SlideShare a Scribd company logo
30 minutes to CPAN

(Minimizing the magic, and demystifying the process.)
30 minutes is pure Marketing Department hype.

       But with practice, it's realistic.
There are many ways to do it.

 This is a good way to start.
Get a PAUSE/CPAN account
●   https://pause.perl.org/pause/query?ACTION=request_id
●   The form takes 2 minutes.
●   The response time can be 1-3 days, so be patient.
●   Make sure to search CPAN ensuring you're not requesting a
    PAUSE ID that is already in use.
Create a directory framework
$ mkdir Foo
$ cd Foo
$ mkdir lib
$ mkdir t
$ mkdir examples
$ touch lib/Foo.pm
$ touch t/00-load.t
$ touch examples/example.pl
$ touch Makefile.PL
$ touch MANIFEST
$ touch Changes
$ touch README
MANIFEST
●   List the files included in your distribution. Comments
    may be added to the right.
    MANIFEST              This file. (And this is a legal comment)
    README                The brief introduction. (Another comment)
    Changes               The change log
    Makefile.PL
    META.json
    META.yml
    lib/Foo.pm
    t/00-load.t
    examples/example.pl
README
●   Brief intro to your module.

●   Just copy one from CPAN as an example and
    modify it to suit your needs.
    –   Too long to post here, mostly boilerplate.

●   No version numbers. No version-specific details.
    –   It will make your life as an author easier.
Changes
●   The change log for CPAN releases. Newer releases are
    listed above older ones. One blank line separates
    releases.

    Change log for Perl module Foo.


    0.02 2013-01-09
      - Fixed all the bugs in version 0.01.


    0.01 2012-11-15
      - First version.
Makefile.PL
use strict;
use warnings;
use 5.006000;
use ExtUtils::MakeMaker;


WriteMakefile( … );
Makefile.PL – WriteMakefile()
WriteMakefile(
     NAME               => 'Foo',
     AUTHOR             => q{Your Name < cpan_acct [at] cpan [dot] org >},
     VERSION_FROM       => 'lib/Foo.pm',
     ABSTRACT_FROM      => 'lib/Foo.pm',
     LICENSE            => 'perl',
     MIN_PERL_VERSION   => '5.006000',
    BUILD_REQUIRES      => { Test::More => '0', },    # Core; needn't be
listed.
     PREREQ_PM          => { List::MoreUtils => '0.33', },
     META_MERGE         => { … },
     dist               => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
     clean              => { FILES => 'Foo-*' },
);
Other Makefile.PL meta info
●   It's helpful to include a META_MERGE section
    in Makefile.PL
    –   List the public version control repositiory.
    –   Other useful meta fields documented in
        CPAN::Meta::Spec
    –   These fields are helpful, but not mandatory.
Testing: t/00-load.t
●   Anything named t/*.t will be run in ASCII-betical
    order as a test.
    use strict;
    use warnings;
    use Test::More;


    use_ok( 'Foo' );
    can_ok( 'Foo', 'bar' ); # Function exists.
    can_ok('main', 'bar');   # Function was imported.
    done_testing();
lib/Foo.pm
●   Your module's code and documentation:
    package Foo;


    use strict;              use warnings;
    use Exporter;


    our @ISA = qw( Exporter );
    our @EXPORT = qw( bar );
    our $VERSION = '0.01';


    sub bar {     print “Hello world!n”;    }


    1;


    =pod
lib/Foo.pm ( =pod )
    =pod
    =head1 NAME
    Foo – The great Foo says hello!
    =head1 SYNOPSIS
        Use Foo;
        Bar();
    =head1 DESCRIPTION
    This module implements a single function, C<bar()> which greets you by
    printing “Hello world!”.
    =head1 EXPORTS
    L<Foo> exports a single function; C<bar()>.


●   Follow your favorite (simple) module's example.
●   Read perldoc perlpod.
examples/example.pl
●   A small working script demonstrating your module.
    use strict;
    use warnings;
    use Foo;


    bar();   # This prints “Hello world.n”



●   Should not be chmod +x (Nor should
    anything else in the distribution).
Prepare the distribution
perl Makefile.PL
make
make test
make distcheck
make disttest
cp Foo-0.01/META.* ./
rm -rf Foo-0.01
make dist
Upload to PAUSE
●   Log in at: http://pause.perl.org


●   Upload at:
    https://pause.perl.org/pause/authenquery?ACTION=add_uri


●   Wait a few hours for the CPAN mirrors to update.


●   Visit http://cpantesters.org to check smoke test results.
Request the namespace.
●   This is a formality, and can take a week to be
    approved.

●   This is done via the PAUSE website.

●   Top-level namespaces are more difficult.

●   Upload first, then request.
Version Numbers
●   Regular Releases
        our $VERSION = '0.01';


●   Always bump the version number before uploading to
    CPAN.

●   Minimize error-prone work: Keep version numbers in as
    few places as practical.
    –   Consider adding a version number consistency test.
Module tests
●   Module tests are important to you and users.
    –   You get feedback from the smoke testers.
    –   Your users gain confidence that the module will work on their
        platform.
    –   Bugs are easier to track down.
●   List additional test dependencies in BUILD_REQUIRES.
●   Some tests such as Test::NoWarnings may be written
    generically, and copied into your next project.
    –   Your next module won't take as long to assemble.
Author / Release Tests
●   Should run optionally
●   Should not fail if a test module dependency isn't
    available.
●   Use environment variables such as RELEASE_TESTING
    to trigger these sorts of tests.
●   Skip and exit gracefully if an optional test's module is
    unavailable on the target system.
●   Generic: They may be useful in your next module.
A few author tests to consider
●   Test::Pod
●   Test::Pod::Coverage
●   Test::CPAN::Changes
●   Test::Manifest
●   Test::Perl::Critic
●   Test::Kwalitee
●   Test::Version
●   Many other favorites are on CPAN – Ask around.
License
●   Make sure the license enumerated in the POD
    matches the one called for in Makefile.PL
●   See:
      $ perldoc perlmodstyle
      $ perldoc perlartistic
      $ perldoc perlgpl
●   License should be referred to in Makefile.PL
    so the META files list it.
License
●   Make sure the license enumerated in the POD
    matches the one called for in Makefile.PL
●   See:
      $ perldoc perlmodstyle
      $ perldoc perlartistic
      $ perldoc perlgpl
●   License should be referred to in Makefile.PL
    so the META files list it.
Next time...
●   Use Module::Starter
    –   Creates a simple template for you, and adds a few
        tests.
●   Copy the generic (especially author-only) tests
    from your previous distribution.
●   Whenver you come up with a test that might
    be useful in other distributions, copy it to them.
Eventually...
●   Some people love Dist::Zilla; a distribution
    automator / manager.
●   Module::Build is a more Perlish alternative to
    ExtUtils::MakeMaker
●   Module::Install is yet another solution that lets
    you bundle prereqs more easily. It simplifies
    creating ExtUtils::MakeMaker-based
    distributions.
References (Really, look them over)
●   POD
    –   perlmodstyle
    –   perlpod
●   On CPAN
    –   Module::Starter
    –   ExtUtils::MakeMaker
    –   CPAN::Meta::Spec
●   In print
    –   Intermediate Perl Programming (O'Reilly)
●   On testing
    –   Test::More
    –   http://cpantesters.org
●   CPAN itself! (Thousands of good – and bad – examples.)
David Oswald

daoswald@gmail.com / davido@cpan.org

More Related Content

ODP
Deploying Perl apps on dotCloud
PDF
CPAN Training
ODP
Getting started with Perl XS and Inline::C
KEY
The problem with Perl
PDF
parenscript-tutorial
PDF
The Parenscript Common Lisp to JavaScript compiler
PDF
Perl Dist::Surveyor 2011
PDF
How DSL works on Ruby
Deploying Perl apps on dotCloud
CPAN Training
Getting started with Perl XS and Inline::C
The problem with Perl
parenscript-tutorial
The Parenscript Common Lisp to JavaScript compiler
Perl Dist::Surveyor 2011
How DSL works on Ruby

What's hot (20)

PPTX
PHP 5.6 New and Deprecated Features
PPTX
PSGI and Plack from first principles
PDF
Os Harkins
PDF
What you need to remember when you upload to CPAN
PDF
PECL Picks - Extensions to make your life better
PDF
PHP traits, treat or threat?
PDF
Fluentd v0.14 Plugin API Details
PDF
Statyczna analiza kodu PHP
PPTX
Php’s guts
PPTX
Php internal architecture
PPTX
10 Most Important Features of New PHP 5.6
PDF
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
PDF
J Ruby Whirlwind Tour
PDF
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
PDF
Apache Thrift
PDF
Zend expressive workshop
PDF
Laravel 4 package development
PDF
How to develop Jenkins plugin using to ruby and Jenkins.rb
PPTX
PSR-7 - Middleware - Zend Expressive
PPTX
HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)
PHP 5.6 New and Deprecated Features
PSGI and Plack from first principles
Os Harkins
What you need to remember when you upload to CPAN
PECL Picks - Extensions to make your life better
PHP traits, treat or threat?
Fluentd v0.14 Plugin API Details
Statyczna analiza kodu PHP
Php’s guts
Php internal architecture
10 Most Important Features of New PHP 5.6
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
J Ruby Whirlwind Tour
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Apache Thrift
Zend expressive workshop
Laravel 4 package development
How to develop Jenkins plugin using to ruby and Jenkins.rb
PSR-7 - Middleware - Zend Expressive
HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)
Ad

Similar to 30 Minutes To CPAN (20)

PDF
CPAN 模組二三事
PDF
CPANci: Continuous Integration for CPAN
PDF
Authoring CPAN modules
PPTX
CPAN Curation
PDF
Packaging perl (LPW2010)
ODP
Perl - laziness, impatience, hubris, and one liners
PDF
System Programming and Administration
PDF
走向开源:向CPAN提交模块Step By Step
PPT
perlall
PDF
Managing Perl Installations: A SysAdmin's View
PDF
Create and upload your first Perl module to CPAN
PDF
Making My Own CPAN
PDF
Utility Modules That You Should Know About
PDF
CPAN Workshop, Chicago 2014
ODP
Things I Learned From Having Users
DOCX
Perl 20tips
PDF
CPAN Dependency Heaven
PPTX
Modern Perl toolchain (help building microservices)
PDF
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
PDF
Introduction to writing readable and maintainable Perl
CPAN 模組二三事
CPANci: Continuous Integration for CPAN
Authoring CPAN modules
CPAN Curation
Packaging perl (LPW2010)
Perl - laziness, impatience, hubris, and one liners
System Programming and Administration
走向开源:向CPAN提交模块Step By Step
perlall
Managing Perl Installations: A SysAdmin's View
Create and upload your first Perl module to CPAN
Making My Own CPAN
Utility Modules That You Should Know About
CPAN Workshop, Chicago 2014
Things I Learned From Having Users
Perl 20tips
CPAN Dependency Heaven
Modern Perl toolchain (help building microservices)
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
Introduction to writing readable and maintainable Perl
Ad

More from daoswald (8)

PDF
Perl: Setting Up An Internal Darkpan
ODP
Speaking at Tech Events
ODP
Perl one-liners
ODP
Whatsnew in-perl
ODP
Add Perl to Your Toolbelt
ODP
Think Like a Programmer
ODP
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
ODP
Perls Functional functions
Perl: Setting Up An Internal Darkpan
Speaking at Tech Events
Perl one-liners
Whatsnew in-perl
Add Perl to Your Toolbelt
Think Like a Programmer
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Perls Functional functions

Recently uploaded (20)

PPTX
Tartificialntelligence_presentation.pptx
PDF
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPT
What is a Computer? Input Devices /output devices
PDF
Getting Started with Data Integration: FME Form 101
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
TLE Review Electricity (Electricity).pptx
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
Hindi spoken digit analysis for native and non-native speakers
Tartificialntelligence_presentation.pptx
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
Group 1 Presentation -Planning and Decision Making .pptx
Web App vs Mobile App What Should You Build First.pdf
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
What is a Computer? Input Devices /output devices
Getting Started with Data Integration: FME Form 101
DP Operators-handbook-extract for the Mautical Institute
A contest of sentiment analysis: k-nearest neighbor versus neural network
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
1 - Historical Antecedents, Social Consideration.pdf
cloud_computing_Infrastucture_as_cloud_p
WOOl fibre morphology and structure.pdf for textiles
observCloud-Native Containerability and monitoring.pptx
Assigned Numbers - 2025 - Bluetooth® Document
TLE Review Electricity (Electricity).pptx
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Hindi spoken digit analysis for native and non-native speakers

30 Minutes To CPAN

  • 1. 30 minutes to CPAN (Minimizing the magic, and demystifying the process.)
  • 2. 30 minutes is pure Marketing Department hype. But with practice, it's realistic.
  • 3. There are many ways to do it. This is a good way to start.
  • 4. Get a PAUSE/CPAN account ● https://pause.perl.org/pause/query?ACTION=request_id ● The form takes 2 minutes. ● The response time can be 1-3 days, so be patient. ● Make sure to search CPAN ensuring you're not requesting a PAUSE ID that is already in use.
  • 5. Create a directory framework $ mkdir Foo $ cd Foo $ mkdir lib $ mkdir t $ mkdir examples $ touch lib/Foo.pm $ touch t/00-load.t $ touch examples/example.pl $ touch Makefile.PL $ touch MANIFEST $ touch Changes $ touch README
  • 6. MANIFEST ● List the files included in your distribution. Comments may be added to the right. MANIFEST This file. (And this is a legal comment) README The brief introduction. (Another comment) Changes The change log Makefile.PL META.json META.yml lib/Foo.pm t/00-load.t examples/example.pl
  • 7. README ● Brief intro to your module. ● Just copy one from CPAN as an example and modify it to suit your needs. – Too long to post here, mostly boilerplate. ● No version numbers. No version-specific details. – It will make your life as an author easier.
  • 8. Changes ● The change log for CPAN releases. Newer releases are listed above older ones. One blank line separates releases. Change log for Perl module Foo. 0.02 2013-01-09 - Fixed all the bugs in version 0.01. 0.01 2012-11-15 - First version.
  • 9. Makefile.PL use strict; use warnings; use 5.006000; use ExtUtils::MakeMaker; WriteMakefile( … );
  • 10. Makefile.PL – WriteMakefile() WriteMakefile( NAME => 'Foo', AUTHOR => q{Your Name < cpan_acct [at] cpan [dot] org >}, VERSION_FROM => 'lib/Foo.pm', ABSTRACT_FROM => 'lib/Foo.pm', LICENSE => 'perl', MIN_PERL_VERSION => '5.006000', BUILD_REQUIRES => { Test::More => '0', }, # Core; needn't be listed. PREREQ_PM => { List::MoreUtils => '0.33', }, META_MERGE => { … }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Foo-*' }, );
  • 11. Other Makefile.PL meta info ● It's helpful to include a META_MERGE section in Makefile.PL – List the public version control repositiory. – Other useful meta fields documented in CPAN::Meta::Spec – These fields are helpful, but not mandatory.
  • 12. Testing: t/00-load.t ● Anything named t/*.t will be run in ASCII-betical order as a test. use strict; use warnings; use Test::More; use_ok( 'Foo' ); can_ok( 'Foo', 'bar' ); # Function exists. can_ok('main', 'bar'); # Function was imported. done_testing();
  • 13. lib/Foo.pm ● Your module's code and documentation: package Foo; use strict; use warnings; use Exporter; our @ISA = qw( Exporter ); our @EXPORT = qw( bar ); our $VERSION = '0.01'; sub bar { print “Hello world!n”; } 1; =pod
  • 14. lib/Foo.pm ( =pod ) =pod =head1 NAME Foo – The great Foo says hello! =head1 SYNOPSIS Use Foo; Bar(); =head1 DESCRIPTION This module implements a single function, C<bar()> which greets you by printing “Hello world!”. =head1 EXPORTS L<Foo> exports a single function; C<bar()>. ● Follow your favorite (simple) module's example. ● Read perldoc perlpod.
  • 15. examples/example.pl ● A small working script demonstrating your module. use strict; use warnings; use Foo; bar(); # This prints “Hello world.n” ● Should not be chmod +x (Nor should anything else in the distribution).
  • 16. Prepare the distribution perl Makefile.PL make make test make distcheck make disttest cp Foo-0.01/META.* ./ rm -rf Foo-0.01 make dist
  • 17. Upload to PAUSE ● Log in at: http://pause.perl.org ● Upload at: https://pause.perl.org/pause/authenquery?ACTION=add_uri ● Wait a few hours for the CPAN mirrors to update. ● Visit http://cpantesters.org to check smoke test results.
  • 18. Request the namespace. ● This is a formality, and can take a week to be approved. ● This is done via the PAUSE website. ● Top-level namespaces are more difficult. ● Upload first, then request.
  • 19. Version Numbers ● Regular Releases our $VERSION = '0.01'; ● Always bump the version number before uploading to CPAN. ● Minimize error-prone work: Keep version numbers in as few places as practical. – Consider adding a version number consistency test.
  • 20. Module tests ● Module tests are important to you and users. – You get feedback from the smoke testers. – Your users gain confidence that the module will work on their platform. – Bugs are easier to track down. ● List additional test dependencies in BUILD_REQUIRES. ● Some tests such as Test::NoWarnings may be written generically, and copied into your next project. – Your next module won't take as long to assemble.
  • 21. Author / Release Tests ● Should run optionally ● Should not fail if a test module dependency isn't available. ● Use environment variables such as RELEASE_TESTING to trigger these sorts of tests. ● Skip and exit gracefully if an optional test's module is unavailable on the target system. ● Generic: They may be useful in your next module.
  • 22. A few author tests to consider ● Test::Pod ● Test::Pod::Coverage ● Test::CPAN::Changes ● Test::Manifest ● Test::Perl::Critic ● Test::Kwalitee ● Test::Version ● Many other favorites are on CPAN – Ask around.
  • 23. License ● Make sure the license enumerated in the POD matches the one called for in Makefile.PL ● See: $ perldoc perlmodstyle $ perldoc perlartistic $ perldoc perlgpl ● License should be referred to in Makefile.PL so the META files list it.
  • 24. License ● Make sure the license enumerated in the POD matches the one called for in Makefile.PL ● See: $ perldoc perlmodstyle $ perldoc perlartistic $ perldoc perlgpl ● License should be referred to in Makefile.PL so the META files list it.
  • 25. Next time... ● Use Module::Starter – Creates a simple template for you, and adds a few tests. ● Copy the generic (especially author-only) tests from your previous distribution. ● Whenver you come up with a test that might be useful in other distributions, copy it to them.
  • 26. Eventually... ● Some people love Dist::Zilla; a distribution automator / manager. ● Module::Build is a more Perlish alternative to ExtUtils::MakeMaker ● Module::Install is yet another solution that lets you bundle prereqs more easily. It simplifies creating ExtUtils::MakeMaker-based distributions.
  • 27. References (Really, look them over) ● POD – perlmodstyle – perlpod ● On CPAN – Module::Starter – ExtUtils::MakeMaker – CPAN::Meta::Spec ● In print – Intermediate Perl Programming (O'Reilly) ● On testing – Test::More – http://cpantesters.org ● CPAN itself! (Thousands of good – and bad – examples.)