Life without CPAN

35
LIFE WITHOUT CPAN Reinventing the Wheel Bob Ernst [email protected] ST. LOUIS PERL MONGERS July 17, 2013 Bob Ernst Life Without CPAN

description

Presentation from the St. Louis Perl Mongers, July 17, 2013 The original presentation was a Reveal.js HTML slideshow hosted at http://bobernststl.1.ai/LwoC This version is a PDF from LaTex Beamer for easier sharing.

Transcript of Life without CPAN

Page 1: Life without CPAN

LIFE WITHOUT CPANReinventing the Wheel

Bob [email protected]

ST. LOUIS PERL MONGERS

July 17, 2013

Bob Ernst Life Without CPAN

Page 2: Life without CPAN

Comprehensive Perl Archive Network

http://www.cpan.org/

22,938 Perl modules (and growing!)

10,781 authors (and growing!)

Possibly the best feature of Perl

... and sometimes you can’t use it

Bob Ernst Life Without CPAN

Page 3: Life without CPAN

$677 Million

In 2004, CPAN had 15.4 million lines of code, which would cost$677,000,000 to develophttp://developers.slashdot.org/story/04/07/30/1229239/cpan-677-million-of-perl

Bob Ernst Life Without CPAN

Page 4: Life without CPAN

Handy tools

cpan

cpanm

cpanp

perlbrew

Bob Ernst Life Without CPAN

Page 5: Life without CPAN

Why don’t people use CPAN?

And how did I become one of them??

Bob Ernst Life Without CPAN

Page 6: Life without CPAN

“But I don’t have root...”

No root access? That is an easy one:

use l o c a l : : l i b ;

Bob Ernst Life Without CPAN

Page 7: Life without CPAN

“Why is this so complicated?”

CPAN often has objected-oriented Perl

Embarrassment of riches

More & Better module documentation couldn’t hurt

Bob Ernst Life Without CPAN

Page 8: Life without CPAN

“I don’t have enough disk space...”

Who doesn’t have lots of disk space in 2013?

SSD drives - fast, but small

Raspberry Pi

Embedded systems

Shared hosting

Virtual Machines

Disk quotas

Bob Ernst Life Without CPAN

Page 9: Life without CPAN

NIH - Not Invented Here

Pretty silly, but unfortunately common

Bob Ernst Life Without CPAN

Page 10: Life without CPAN

Security Concerns

Some organizations are serious about security

What company wrote this software?

You want to connect to the internet??

Bob Ernst Life Without CPAN

Page 11: Life without CPAN

Local Mirror & Packing

CPAN::Mini

CPAN::Mini::Inject

Pinto

Carton

Bob Ernst Life Without CPAN

Page 12: Life without CPAN

Licensing

What is this FOSS / open source / shareware / freeware stuff?

We need to review that license...

Sometimes it is easier to buy software

Bob Ernst Life Without CPAN

Page 13: Life without CPAN

Mix of licenses

“Most, though not all, modules on CPAN are licensedunder the GNU Public License (GPL) or the Artisticlicense”

– CPAN FAQ

Bob Ernst Life Without CPAN

Page 14: Life without CPAN

GPL

The GNU Public License is anegative

in some organizations

Bob Ernst Life Without CPAN

Page 15: Life without CPAN

CPAN::Meta::Spec

agpl_3 GNU Affero General Public License, Version 3

apache_1_1 Apache Software License, Version 1.1

apache_2_0 Apache License, Version 2.0

artistic_1 Artistic License, (Version 1)

artistic_2 Artistic License, Version 2.0

bsd BSD License (three-clause)

freebsd FreeBSD License (two-clause)

gfdl_1_2 GNU Free Documentation License, Version 1.2

gfdl_1_3 GNU Free Documentation License, Version 1.3

gpl_1 GNU General Public License, Version 1

gpl_2 GNU General Public License, Version 2

gpl_3 GNU General Public License, Version 3

lgpl_2_1 GNU Lesser General Public License, Version 2.1

lgpl_3_0 GNU Lesser General Public License, Version 3.0

mit MIT (aka X11) License

mozilla_1_0 Mozilla Public License, Version 1.0

mozilla_1_1 Mozilla Public License, Version 1.1

openssl OpenSSL License

perl_5 The Perl 5 License (Artistic 1 & GPL 1 or later)

qpl_1_0 Q Public License, Version 1.0

ssleay Original SSLeay License

sun Sun Internet Standards Source License (SISSL)

zlib zlib License

Bob Ernst Life Without CPAN

Page 16: Life without CPAN

And...

open_source Other Open Source Initiative (OSI) approved license

restricted Requires special permission from copyright holder

unrestricted Not an OSI approved license, but not restricted

unknown License not provided in metadata

May be hard to get approval!

Bob Ernst Life Without CPAN

Page 17: Life without CPAN

Missing licenses

16.6% of CPAN uploads this year don’t have a license inMETA.yml(Older modules are worse!)http://cpants.cpanauthors.org/kwalitee/metayml has license

Bob Ernst Life Without CPAN

Page 18: Life without CPAN

Get the modules without CPAN

Perhaps you have access to another source of modules that isalready approved

ActiveState Perl’s PPO

Linux package installer (yum, apt, etc.)

Bob Ernst Life Without CPAN

Page 19: Life without CPAN

“This stuff is broken!”

Perl & CPAN have a strong culture of quality and testing... Butthere are buggy modules

Look for recommended modules

http://cpanratings.perl.org/

Check outstanding bug list for modules

Report the bug!

Fix the bug yourself (and share the patch)

Fork the module

Bob Ernst Life Without CPAN

Page 20: Life without CPAN

“Who am I going to call for support?”

Submit a bug report

IRC

Perl Monks

Stack Overflow

Mailing lists

ActiveState

Bob Ernst Life Without CPAN

Page 21: Life without CPAN

Deploying to Production

No internet access (in secure environments)

Slow installs

Missing dependencies

Broken installs

Bob Ernst Life Without CPAN

Page 22: Life without CPAN

Building on Quicksand

CPAN modules typically have dependencies, modules are updatedall the timeA fix in one module might break the module you are counting on!

Bob Ernst Life Without CPAN

Page 23: Life without CPAN

Make it solid

perlbrew to get the right version of Perl

CPAN::Mini to get the right version of everything else

Bob Ernst Life Without CPAN

Page 24: Life without CPAN

You’ve fought the political battle and lost...

What do you do?

Bob Ernst Life Without CPAN

Page 25: Life without CPAN

Reinvent the Wheel

Bob Ernst Life Without CPAN

Page 26: Life without CPAN

You aren’t alone

If you google “XYZ Perl”, you’ll find a lot of questions like:

“How do I XYZ in Perl without using CPAN?”

Bob Ernst Life Without CPAN

Page 27: Life without CPAN

XML Parsing

Writing an XML parser is hard work

XML isn’t a regular language so it can’t be parsed withregular expressions

But in a pinch...

i f ( $ i n p u t =˜ qr { (< t i t l e >) ( . ∗ ) (</ t i t l e >) }x) {

$ t i t l e = $2 ;}

Bob Ernst Life Without CPAN

Page 28: Life without CPAN

Date and Time

Date::Manip and Date::Calc are so powerful...what to do when they aren’t available?

Bob Ernst Life Without CPAN

Page 29: Life without CPAN

The Next Eight Sundays (Date::Calc)

use Date : : C a l c qw( Add Delta Days D a t e t o T e x tDay of Week Today ) ;

my @date = Today ( ) ;my $ d a y s u n t i l s u n d a y = 7 − Day of Week ( @date

) ;i f ( $ d a y s u n t i l s u n d a y == 0 ) {

$ d a y s u n t i l s u n d a y = 7 ;}f o r ( my $ i =0; $ i <8; $ i++ ) {

@date = Add Delta Days ( @date ,$ d a y s u n t i l s u n d a y ) ;

say D a t e t o T e x t ( @date ) ;$ d a y s u n t i l s u n d a y = 7 ;

}

Bob Ernst Life Without CPAN

Page 30: Life without CPAN

The Next Eight Sundays (POSIX)

use POSIX qw( mktime s t r f t i m e ) ;use c o n s t a n t {

MDAY => 3 ,WDAY => 6 ,

} ;my @date = l o c a l t i m e ( t ime ( ) ) ;f o r (my $ i =0; $ i <8; $ i++) {

$date [MDAY] += 7 − $date [WDAY] ;@date = l o c a l t i m e ( mktime ( @date ) ) ;say s t r f t i m e ( ”%a %d−%b−%Y” , @date ) ;

}

Bob Ernst Life Without CPAN

Page 31: Life without CPAN

Parallel Processing

Modules like Parallel::Queue are great...if you have CPAN.

Bob Ernst Life Without CPAN

Page 32: Life without CPAN

Old Fashion Fork

our @ c h i l d r e n = ( ) ;sub spawn command {

my $command = s h i f t ;my $ p i d = f o r k ( ) ;i f ( $ p i d ) {

push @ c h i l d r e n , $ p i d ;}e l s i f ( $ p i d == 0 ) {

system ( @{$command} ) ;e x i t 0 ;

}}

Bob Ernst Life Without CPAN

Page 33: Life without CPAN

Fork continued

f o r ( my $ i =1; $ i <= 5 2 ; $ i++ ) {spawn command ( [ ” whateve r ” , $ i ] ) ;

}

f o r e a c h my $ p i d ( @ c h i l d r e n ) {w a i t p i d ( $pid , 0 ) ;

}

Bob Ernst Life Without CPAN

Page 34: Life without CPAN

Core Modules

Don’t forget the core modules!

Benchmark

Carp

Cwd

Data::Dumper

File::stat

Getopt::Long

IO::Handle

IO::Socket

Log::Message

Math::BigInt

Memoize

Pod::Usage

POSIX

Test::More

Time::Local

682 altogether!

Bob Ernst Life Without CPAN

Page 35: Life without CPAN

REMEMBER

“There are three great virtues of a programmer:laziness, impatience and hubris”

– Larry Wall

Be lazy and impatient – use CPAN!

Bob Ernst Life Without CPAN