Best of CPAN

Sébastien Aperghis-Tramoni, sebastien@aperghis.net

CPAN

  • Comprehensive Perl Archive Network

  • centralised and distributed collection of modules

  • http://www.cpan.org/

  • 4.5 Go, more than 13,000 modules, more than 6,000 authors

  • 236 mirrors

CPAN

  • « CPAN is the language, Perl is just its syntax » -- Audrey Tang

  • true strength of Perl

Problem

  • knowing the good modules

Shell

  • Getopt::Long

  • Pod::Usage

  •     my %options = (
             debug => 0,
        );
    
        GetOptions(\%options, qw{
            help|h!  version|V!
            debug|d!  config|c=s
        }) or pod2usage(0);
    
        pod2usage({ -verbose => 2, -exitval => 0, -noperldoc => 1 })
            if $options{help};

Programs

  • Proc::Daemon

  • IPC::Run

  •     my @cmd = qw(ps auwx);
        run \@cmd, \$input, \$output, \$errors or die "$cmd[0]: $?"

Lists

  • List::Util

  •     first max maxstr min minstr reduce shuffle sum
  • List::MoreUtils

  •     any all none notall each_array pairwise natatime mesh zip uniq minmax

Regular expressions

  • Regexp::Common

        while (<>) {
            /$RE{num}{real}/ and print "got a number";
            /$RE{net}{IPv4}/ and print "got an IP address";
        }
  • Regexp::Assemble

  • Text::Match::FastAlternatives

Date and time

  • Time::HiRes

  • Date::Parse

  • DateTime

  • DateTime::Set, DateTime::Span

  • DateTime::Calendar:: Chinese, Christian, Coptic, FrenchRevolutionary, Hebrew, Japanese, Mayan, Pataphysical

Numbers

  • bignum, bigint, bigrat

  • PDL (Perl Data Language == MatLab in Perl)

Files

  • Archiving

    • Archive::Tar, Archive::Zip, Compress:Zlib, Compress:Bzip2

  • Paths

    • File::Spec, Path::Class

    • File::Find::Rule, File::Next, File::Wildcard

    • File::HomeDir, File::ShareDir

Files

  • Content

    • File::Slurp, File::Tail, File::Temp

Objects

  • Class::Accessor

  • Class::Std, Class::InsideOut, Object::InsideOut

  • Moose, Coat

        package CheckingAccount;
            use Moose;
            
            extends 'BankAccount';
            
            has 'overdraft_account' => (isa => 'BankAccount', is => 'rw');        
            
            before 'withdraw' => sub {
                ...
            };
    

Co-operating objects

XML

  • XML::LibXML, XML::LibXSLT

        my $parser = XML::LibXML->new;
        my $doc = $parse->parse_file($file);
    
        my ($node) = $doc->findnodes("/root/path/node[1]");
  • XML::SAX

  • XML::Twig

  • XML::Tiny

Serialisation

  • Data::Dumper, Storable

  • YAML, YAML::Syck, YAML::XS

        YAML::DumpFile($file, \%complex_structure);
        my $struct = YAML::LoadFile($file);
  • JSON, JSON::Syck, JSON::XS

        my $struct = from_json( $request->content );
    
        $response->add_content( to_json(\%data) );

Email

  • MIME::Lite, MIME::Parser, Mail::Box

  • Email::Simple, Email::MIME, Email::Folder all the modules from the Perl Email Project

  • Net::SMTP, Net::POP3, Net::IMAP, IMAP::Admin

Web, client-side

  • LWP::UserAgent, LWP::Simple

  •     my $page = get($url);
  • LWP::Parallel, HTTP::Async

  • WWW::Mechanize

  • Web::Scraper

Web, server-side

  • HTTP::Daemon

  • HTTP::Server::Simple

  • HTTP::Server::Brick

        my $server = HTTP::Server::Brick->new( port => 8888 );
        $server->mount("/files" => { path => "/path/to/files" });
        $server->mount("/user"  => { handler => \&process_user });
        $server->start;
  • CGI, CGI::Simple, CGI::PathInfo

HTML

  • HTML::Parser

  • HTML::TreeBuilder

  • WebService::Validator::HTML::W3C

Documents

  • Office

    • Spreadsheet::WriteExcel, Spreadsheet::ParseExcel

    • OpenOffice::OODoc, Spreadsheet::ReadSXC

    • Spreadsheet::Read, Spreadsheet::Write

    • PDF::API2

  • Images

    • GD, Image::Magick, Gimp, Imager

Network

  • Protocols

    • Net::FTP, Net::SSH, Net::SCP, Net:LDAP, Net::NNTP, Net::RADIUS, Net::TacacsPlus, Net::SIP

    • Net::DNS, Net::Ping, Net::DHCP

  • Low level

    • Net::Pcap, Net::Frame, Net::Packet

Databases

  • Text::CSV_XS

  • DBI

  • MySQL, PostgreSQL, SQLite, Oracle, JDBC, ODBC, Sybase, ADO DB, Unify and much more...

  • DBI::Proxy, DBD::Gofer

  • DBIx::Simple

ORM

  • Tangram, Alzabo, SPOPS

  • Class::DBI, DBIx::Class

  • Rose::DB::Object, DBIx::DataModel, Fey::ORM

Templates

  • HTML::Template

  • Petal

  • Mason

  • Template Toolkit

Modern web frameworks

  • Maypole

  • Catalyst

  • Jifty

Tests

  • Test::More, Test::Builder

  • Devel::Cover

  • Test::Deep, Test::LongString

  • Test::Exception, Test::NoWarnings

  • Test::MockModule, Test::MockObject

  • Test::Class, Test::Unit

  • Test::LectroTest

Tools

  • Module::Starter

  • ack

  • Perl::Critic

  • Perl::Tidy

Debugging

  • XXX

  • Devel::SimpleTrace

  • Devel::Graph

  • Devel::TraceLoad, Devel::TraceUse

  • Devel::LeakTrace

  • Devel::ebug

The external world

  • Languages

    • Inline : C, Java, Python, Ruby, Tcl, Befunge, Lua

  • External libraries

    • XS

    • Devel::PPPort

    • SWIG

    • P5NCI

Interfaces

  • Graphical interfaces

    • Tk, Gtk, WxWidgets, Qt, Prima

    • GUI natives : Win32, Aqua (Mac OS X), X11

  • Native OS API

    • Mac::Carbon, Mac::Glue

    • Win32, Win32::OLE, W2RK::WMI

Conclusion

  • CPAN is full of win

Questions?

Thank you