LIFE WITHOUT CPAN 
Reinventing the Wheel 
Bob Ernst 
BobErnstStl@gmail.com 
ST. LOUIS PERL MONGERS 
July 17, 2013 
Bob Ernst 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
$677 Million 
In 2004, CPAN had 15.4 million lines of code, which would cost 
$677,000,000 to develop 
http://developers.slashdot.org/story/04/07/30/1229239/cpan-677-million-of-perl 
Bob Ernst Life Without CPAN
Handy tools 
cpan 
cpanm 
cpanp 
perlbrew 
Bob Ernst Life Without CPAN
Why don't people use CPAN? 
And how did I become one of them?? 
Bob Ernst Life Without CPAN
But I don't have root..." 
No root access? That is an easy one: 
us e l o c a l : : l i b ; 
Bob Ernst 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
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
NIH - Not Invented Here 
Pretty silly, but unfortunately common 
Bob Ernst 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
Local Mirror & Packing 
CPAN::Mini 
CPAN::Mini::Inject 
Pinto 
Carton 
Bob Ernst Life Without CPAN
Licensing 
What is this FOSS / open source / shareware / freeware stu? 
We need to review that license... 
Sometimes it is easier to buy software 
Bob Ernst Life Without CPAN
Mix of licenses 
Most, though not all, modules on CPAN are licensed 
under the GNU Public License (GPL) or the Artistic 
license 
{ CPAN FAQ 
Bob Ernst Life Without CPAN
GPL 
The GNU Public License is a 
negative 
in some organizations 
Bob Ernst 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
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
Missing licenses 
16.6% of CPAN uploads this year don't have a license in 
META.yml 
(Older modules are worse!) 
http://cpants.cpanauthors.org/kwalitee/metayml has license 
Bob Ernst Life Without CPAN
Get the modules without CPAN 
Perhaps you have access to another source of modules that is 
already approved 
ActiveState Perl's PPO 
Linux package installer (yum, apt, etc.) 
Bob Ernst Life Without CPAN
This stu is broken! 
Perl  CPAN have a strong culture of quality and testing... But 
there 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
Who am I going to call for support? 
Submit a bug report 
IRC 
Perl Monks 
Stack Over
ow 
Mailing lists 
ActiveState 
Bob Ernst Life Without CPAN
Deploying to Production 
No internet access (in secure environments) 
Slow installs 
Missing dependencies 
Broken installs 
Bob Ernst Life Without CPAN
Building on Quicksand 
CPAN modules typically have dependencies, modules are updated 
all the time 
A
x in one module might break the module you are counting on! 
Bob Ernst 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
You've fought the political battle and lost... 
What do you do? 
Bob Ernst Life Without CPAN
Reinvent the Wheel 
Bob Ernst Life Without CPAN
You aren't alone 
If you google XYZ Perl, you'll
nd a lot of questions like: 
How do I XYZ in Perl without using CPAN? 
Bob Ernst Life Without CPAN
XML Parsing 
Writing an XML parser is hard work 
XML isn't a regular language so it can't be parsed with 
regular expressions 
But in a pinch... 
i f ( $ i n p u t =~ qr f ( t i t l e ) ( .  ) (/ t i t l e ) gx 
) f 
$ t i t l e = $2 ; 
g 
Bob Ernst 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
The Next Eight Sundays (Date::Calc) 
us e Date : : Cal c qw( Add De l ta Days Da t e t o Te x t 
Day 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 ) f 
$ d a y s u n t i l s u n d a y = 7 ; 
g 
f o r ( my $ i =0; $i 8; $ i++ ) f 
@date = Add De l ta Days ( @date , 
$ d a y s u n t i l s u n d a y ) ; 
say Da t e t o Te x t ( @date ) ; 
$ d a y s u n t i l s u n d a y = 7 ; 
g 
Bob Ernst Life Without CPAN
The Next Eight Sundays (POSIX) 
us e POSIX qw( mktime s t r f t ime ) ; 
us e c o n s t a n t f 
MDAY = 3 , 
WDAY = 6 , 
g ; 
my @date = l o c a l t ime ( t ime ( ) ) ; 
f o r (my $ i =0; $i 8; $ i++) f 
$dat e [MDAY] += 7  $dat e [WDAY] ; 
@date = l o c a l t ime ( mktime ( @date ) ) ; 
say s t r f t ime ( %a %d%b%Y , @date ) ; 
g 
Bob Ernst Life Without CPAN
Parallel Processing 
Modules like Parallel::Queue are great... 
if you have CPAN. 
Bob Ernst Life Without CPAN
Old Fashion Fork 
our @c h i l d r e n = ( ) ; 
sub spawn command f 
my $command = s h i f t ; 
my $pid = f o r k ( ) ; 
i f ( $pid ) f 
push @c h i l d r e n , $pid ; 
g 
e l s i f ( $pid == 0 ) f 
sys tem ( @f$commandg ) ; 
e x i t 0 ; 
g 
g 
Bob Ernst Life Without CPAN
Fork continued 
f o r ( my $ i =1; $ i = 5 2 ; $ i++ ) f 
spawn command ( [ what e v e r  , $ i ] ) ; 
g 
f o r e a c h my $pid ( @c h i l d r e n ) f 
wa i t p i d ( $pid , 0 ) ; 
g 
Bob Ernst Life Without CPAN

Life without CPAN

  • 1.
    LIFE WITHOUT CPAN Reinventing the Wheel Bob Ernst BobErnstStl@gmail.com ST. LOUIS PERL MONGERS July 17, 2013 Bob Ernst Life Without CPAN
  • 2.
    Comprehensive Perl ArchiveNetwork 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
  • 3.
    $677 Million In2004, CPAN had 15.4 million lines of code, which would cost $677,000,000 to develop http://developers.slashdot.org/story/04/07/30/1229239/cpan-677-million-of-perl Bob Ernst Life Without CPAN
  • 4.
    Handy tools cpan cpanm cpanp perlbrew Bob Ernst Life Without CPAN
  • 5.
    Why don't peopleuse CPAN? And how did I become one of them?? Bob Ernst Life Without CPAN
  • 6.
    But I don'thave root..." No root access? That is an easy one: us e l o c a l : : l i b ; Bob Ernst Life Without CPAN
  • 7.
    Why is thisso complicated?" CPAN often has objected-oriented Perl Embarrassment of riches More & Better module documentation couldn't hurt Bob Ernst Life Without CPAN
  • 8.
    I don't haveenough 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
  • 9.
    NIH - NotInvented Here Pretty silly, but unfortunately common Bob Ernst Life Without CPAN
  • 10.
    Security Concerns Someorganizations are serious about security What company wrote this software? You want to connect to the internet?? Bob Ernst Life Without CPAN
  • 11.
    Local Mirror &Packing CPAN::Mini CPAN::Mini::Inject Pinto Carton Bob Ernst Life Without CPAN
  • 12.
    Licensing What isthis FOSS / open source / shareware / freeware stu? We need to review that license... Sometimes it is easier to buy software Bob Ernst Life Without CPAN
  • 13.
    Mix of licenses Most, though not all, modules on CPAN are licensed under the GNU Public License (GPL) or the Artistic license { CPAN FAQ Bob Ernst Life Without CPAN
  • 14.
    GPL The GNUPublic License is a negative in some organizations Bob Ernst Life Without CPAN
  • 15.
    CPAN::Meta::Spec agpl_3 GNUAffero 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
  • 16.
    And... open_source OtherOpen 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
  • 17.
    Missing licenses 16.6%of CPAN uploads this year don't have a license in META.yml (Older modules are worse!) http://cpants.cpanauthors.org/kwalitee/metayml has license Bob Ernst Life Without CPAN
  • 18.
    Get the moduleswithout CPAN Perhaps you have access to another source of modules that is already approved ActiveState Perl's PPO Linux package installer (yum, apt, etc.) Bob Ernst Life Without CPAN
  • 19.
    This stu isbroken! Perl CPAN have a strong culture of quality and testing... But there 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
  • 20.
    Who am Igoing to call for support? Submit a bug report IRC Perl Monks Stack Over ow Mailing lists ActiveState Bob Ernst Life Without CPAN
  • 21.
    Deploying to Production No internet access (in secure environments) Slow installs Missing dependencies Broken installs Bob Ernst Life Without CPAN
  • 22.
    Building on Quicksand CPAN modules typically have dependencies, modules are updated all the time A
  • 23.
    x in onemodule might break the module you are counting on! Bob Ernst Life Without CPAN
  • 24.
    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
  • 25.
    You've fought thepolitical battle and lost... What do you do? Bob Ernst Life Without CPAN
  • 26.
    Reinvent the Wheel Bob Ernst Life Without CPAN
  • 27.
    You aren't alone If you google XYZ Perl, you'll
  • 28.
    nd a lotof questions like: How do I XYZ in Perl without using CPAN? Bob Ernst Life Without CPAN
  • 29.
    XML Parsing Writingan XML parser is hard work XML isn't a regular language so it can't be parsed with regular expressions But in a pinch... i f ( $ i n p u t =~ qr f ( t i t l e ) ( . ) (/ t i t l e ) gx ) f $ t i t l e = $2 ; g Bob Ernst Life Without CPAN
  • 30.
    Date and Time Date::Manip and Date::Calc are so powerful... what to do when they aren't available? Bob Ernst Life Without CPAN
  • 31.
    The Next EightSundays (Date::Calc) us e Date : : Cal c qw( Add De l ta Days Da t e t o Te x t Day 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 ) f $ d a y s u n t i l s u n d a y = 7 ; g f o r ( my $ i =0; $i 8; $ i++ ) f @date = Add De l ta Days ( @date , $ d a y s u n t i l s u n d a y ) ; say Da t e t o Te x t ( @date ) ; $ d a y s u n t i l s u n d a y = 7 ; g Bob Ernst Life Without CPAN
  • 32.
    The Next EightSundays (POSIX) us e POSIX qw( mktime s t r f t ime ) ; us e c o n s t a n t f MDAY = 3 , WDAY = 6 , g ; my @date = l o c a l t ime ( t ime ( ) ) ; f o r (my $ i =0; $i 8; $ i++) f $dat e [MDAY] += 7 $dat e [WDAY] ; @date = l o c a l t ime ( mktime ( @date ) ) ; say s t r f t ime ( %a %d%b%Y , @date ) ; g Bob Ernst Life Without CPAN
  • 33.
    Parallel Processing Moduleslike Parallel::Queue are great... if you have CPAN. Bob Ernst Life Without CPAN
  • 34.
    Old Fashion Fork our @c h i l d r e n = ( ) ; sub spawn command f my $command = s h i f t ; my $pid = f o r k ( ) ; i f ( $pid ) f push @c h i l d r e n , $pid ; g e l s i f ( $pid == 0 ) f sys tem ( @f$commandg ) ; e x i t 0 ; g g Bob Ernst Life Without CPAN
  • 35.
    Fork continued fo r ( my $ i =1; $ i = 5 2 ; $ i++ ) f spawn command ( [ what e v e r , $ i ] ) ; g f o r e a c h my $pid ( @c h i l d r e n ) f wa i t p i d ( $pid , 0 ) ; g Bob Ernst Life Without CPAN
  • 36.
    Core Modules Don'tforget 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
  • 37.
    REMEMBER There arethree great virtues of a programmer: laziness, impatience and hubris { Larry Wall Be lazy and impatient { use CPAN! Bob Ernst Life Without CPAN