Packaging Perl
   Modules
   Kirrily Robert
Look familiar?


~skud/.cpan/build/Archive-Any-0.093 $ ls
Build.PL        META.yml        README     pm_to_blib
Changes   ...
Today...


• How CPAN modules are packaged
• Why it rocks
• Why you should use it everywhere
• How to integrate it with re...
Creating CPAN modules


• Always use h2xs
• Always use h2xs
• ALWAYS use h2xs
Wrong.
Two main options



• h2xs
• module-starter
h2xs


• Old-school
• Comes with Perl
• Few modern features
• Good XS stubs, though
module-starter


• Module::Starter on CPAN
• Modern features
• Better stubs
• Higher Kwalitee
module-starter

$ module-starter --module Gift::Basket
Created starter directories and files

$ ls Gift-Basket/
Build.PL  ...
Configuration

$ cat ~/.module-starter/config
builder: Module::Build
author: Kirrily Robert
email: skud@cpan.org
Module layout


Build.PL   MANIFEST    lib
Changes    README      t
Build.PL
use strict;
use warnings;
use Module::Build;

my $builder = Module::Build->new(
    module_name         => 'Gift:...
Changes
Revision history for Gift-Basket

0.03    2007-11-20
        Added support for shipping gift baskets to
        ad...
MANIFEST
Build.PL
Changes
MANIFEST
META.yml # Will be created by quot;make distquot;
README
lib/Gift/Basket.pm
t/00-load.t...
README


• Description
• Installation
• Support
• License
lib/

$ find lib
lib
lib/Gift
lib/Gift/Basket.pm
t/

$ find t
t
t/00-load.t
t/boilerplate.t
t/pod-coverage.t
t/pod.t
Building modules

• ./Build dist
• ./Build disttest
• Upload to PAUSE
  • http://pause.perl.org
  • cpaninject
Why this rocks


• Standard build/install tools
• Metadata and tests included by
  default

• Encourages modularity
Non-CPAN
CPAN Modules
Standard build tools


• Save time and effort
• Already familiar to many developers
• Easy release path to CPAN
Metadata and tests



• Encourage testing
• Specify dependencies
Modularity


• Reduce spaghetti
• Share code between projects
• Easy release path to CPAN
Example

$ ls code/
GiftCo-Core        GiftCo-Payments
GiftCo-DB          GiftCo-Reporting
GiftCo-MailTools   GiftCo-Website
Web Server
GiftCo::Website

                   GiftCo::Core


                   GiftCo::DB


                   GiftCo::P...
Backend
GiftCo::Reporting

                    GiftCo::Payments


                    GiftCo::DB


                    Gif...
Installation



• Local CPAN
• Distro packages
Local CPAN


• MiniCPAN
• Add local packages
• Configure CPAN.pm
MiniCPAN



• perl -MCPAN -e ‘install CPAN::Mini’
• minicpan -l $LOCAL -r $REMOTE
Inject

• perl -MCPAN -e
  ‘install CPAN::Mini::Inject’
• mcpani --add --module GiftCo::DB
  --authorid SKUD
  --modversio...
Configure

cpan[1]> o conf urllist
    urllist
        0 [file:///Users/skud/mirrors/cpan/]
        1 [ftp://cpan.pair.com/...
Distro packages


• Integrates with non-Perl packages
• Standardised install procedure
• Sysadmins like them
Dependencies
GiftCo::DB


                DBI


             DBD::mysql


                          mysql-lib
Packaging



• cpan2rpm
• dh-make-perl
cpan2rpm


• Creates RPMs from CPAN modules
• Redhat-derived distros
• cpan2rpm -U GiftCo::DB
• Creates full RPM package
dh-make-perl


• Comes with Debian/Ubuntu
• Creates .deb packages
• dh-make-perl GiftCo-DB-0.01/
• Creates debian/ directory
Issues


• Neither follows CPAN dependencies
• You must walk the dep tree (once)
• Can specify deps thereafter
Example
   GiftCo::Website                     GiftCo::DB
                         requires



                           ...
apt-get install
$ sudo apt-get install giftco-website
Reading package lists... Done
Building dependency tree... Done
The f...
Kirrily Robert
http://infotrope.net
skud@infotrope.net
Upcoming SlideShare
Loading in...5
×

Packaging Perl Modules

11,157

Published on

A talk from the Open Source Developers' Conference 2007. How to package Perl modules for CPAN, why it's a great format, and why you should use it even outside of CPAN itself.

Published in: Business, Technology
0 Comments
12 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
11,157
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
237
Comments
0
Likes
12
Embeds 0
No embeds

No notes for slide

Packaging Perl Modules

  1. 1. Packaging Perl Modules Kirrily Robert
  2. 2. Look familiar? ~skud/.cpan/build/Archive-Any-0.093 $ ls Build.PL META.yml README pm_to_blib Changes Makefile blib t MANIFEST Makefile.PL lib
  3. 3. Today... • How CPAN modules are packaged • Why it rocks • Why you should use it everywhere • How to integrate it with release mgt
  4. 4. Creating CPAN modules • Always use h2xs • Always use h2xs • ALWAYS use h2xs
  5. 5. Wrong.
  6. 6. Two main options • h2xs • module-starter
  7. 7. h2xs • Old-school • Comes with Perl • Few modern features • Good XS stubs, though
  8. 8. module-starter • Module::Starter on CPAN • Modern features • Better stubs • Higher Kwalitee
  9. 9. module-starter $ module-starter --module Gift::Basket Created starter directories and files $ ls Gift-Basket/ Build.PL MANIFEST lib Changes README t
  10. 10. Configuration $ cat ~/.module-starter/config builder: Module::Build author: Kirrily Robert email: skud@cpan.org
  11. 11. Module layout Build.PL MANIFEST lib Changes README t
  12. 12. Build.PL use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'Gift::Basket', license => 'perl', dist_author => 'Kirrily Robert <skud@cpan.org>', dist_version_from => 'lib/Gift/Basket.pm', build_requires => { 'Test::More' => 0, }, add_to_cleanup => [ 'Gift-Basket-*' ], ); $builder->create_build_script();
  13. 13. Changes Revision history for Gift-Basket 0.03 2007-11-20 Added support for shipping gift baskets to addresses within Australia and NZ. 0.02 2007-11-05 Fixed a bug with adding chocolates to the basket. 0.01 2007-11-01 Initial release. Includes methods for building a gift basket and calculating prices. Not ready for production.
  14. 14. MANIFEST Build.PL Changes MANIFEST META.yml # Will be created by quot;make distquot; README lib/Gift/Basket.pm t/00-load.t t/boilerplate.t t/pod-coverage.t t/pod.t
  15. 15. README • Description • Installation • Support • License
  16. 16. lib/ $ find lib lib lib/Gift lib/Gift/Basket.pm
  17. 17. t/ $ find t t t/00-load.t t/boilerplate.t t/pod-coverage.t t/pod.t
  18. 18. Building modules • ./Build dist • ./Build disttest • Upload to PAUSE • http://pause.perl.org • cpaninject
  19. 19. Why this rocks • Standard build/install tools • Metadata and tests included by default • Encourages modularity
  20. 20. Non-CPAN CPAN Modules
  21. 21. Standard build tools • Save time and effort • Already familiar to many developers • Easy release path to CPAN
  22. 22. Metadata and tests • Encourage testing • Specify dependencies
  23. 23. Modularity • Reduce spaghetti • Share code between projects • Easy release path to CPAN
  24. 24. Example $ ls code/ GiftCo-Core GiftCo-Payments GiftCo-DB GiftCo-Reporting GiftCo-MailTools GiftCo-Website
  25. 25. Web Server GiftCo::Website GiftCo::Core GiftCo::DB GiftCo::Payments
  26. 26. Backend GiftCo::Reporting GiftCo::Payments GiftCo::DB GiftCo::Core GiftCo::MailTools
  27. 27. Installation • Local CPAN • Distro packages
  28. 28. Local CPAN • MiniCPAN • Add local packages • Configure CPAN.pm
  29. 29. MiniCPAN • perl -MCPAN -e ‘install CPAN::Mini’ • minicpan -l $LOCAL -r $REMOTE
  30. 30. Inject • perl -MCPAN -e ‘install CPAN::Mini::Inject’ • mcpani --add --module GiftCo::DB --authorid SKUD --modversion 0.01 --file GiftCo::DB-0.01.tar.gz
  31. 31. Configure cpan[1]> o conf urllist urllist 0 [file:///Users/skud/mirrors/cpan/] 1 [ftp://cpan.pair.com/pub/CPAN/] 2 [ftp://cpan.hexten.net/]
  32. 32. Distro packages • Integrates with non-Perl packages • Standardised install procedure • Sysadmins like them
  33. 33. Dependencies GiftCo::DB DBI DBD::mysql mysql-lib
  34. 34. Packaging • cpan2rpm • dh-make-perl
  35. 35. cpan2rpm • Creates RPMs from CPAN modules • Redhat-derived distros • cpan2rpm -U GiftCo::DB • Creates full RPM package
  36. 36. dh-make-perl • Comes with Debian/Ubuntu • Creates .deb packages • dh-make-perl GiftCo-DB-0.01/ • Creates debian/ directory
  37. 37. Issues • Neither follows CPAN dependencies • You must walk the dep tree (once) • Can specify deps thereafter
  38. 38. Example GiftCo::Website GiftCo::DB requires becomes becomes libgiftco-website-perl libgiftco-db-perl requires
  39. 39. apt-get install $ sudo apt-get install giftco-website Reading package lists... Done Building dependency tree... Done The following extra packages will be installed: libgiftco-website-perl libgiftco-db-perl libgiftco-core-perl libgiftco-payments-perl libdbi-perl libdbd-mysql-perl libmysql The following NEW packages will be installed: giftco-website libgiftco-website-perl libgiftco-db-perl libgiftco-core-perl libgiftco-payments-perl libdbi-perl libdbd-mysql-perl libmysql 0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded. Need to get 8.3MB of archives. After unpacking 25MB of additional disk space will be used. Do you want to continue [Y/n]?
  40. 40. Kirrily Robert http://infotrope.net skud@infotrope.net
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×