Le meilleur du CPAN

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

CPAN

  • Comprehensive Perl Archive Network

  • collection centralisée et distribuée de modules

  • http://www.cpan.org/

  • 5.6 Go, environ 17 000 distributions, environ 4 000 auteurs

  • 201 miroirs

CPAN

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

  • véritable richesse de Perl

Problème

  • connaître les bons modules

Listes

  • List::Util

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

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

Expressions régulières

  • Regexp::Common

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

        my $ra = Regexp::Assemble->new;
        $ra->add( "cra+ck", "cru+nch", "clu+n+ck" );
        print $ra->re;   # "(?-xism:c(?:r(?:u+nch|a+ck)|lu+n+ck))"
  • Text::Match::FastAlternatives

    • join "|", @words en bien plus efficace

Date et heure

  • Time::HiRes

  • Date::Parse

        $date = "Wed, 9 Nov 1994 09:50:32 -0500";
        $time = str2time($date);
        ($sec, $min, $hour, $day, $month, $year, $zone) = strptime($date);
  • DateTime

  • DateTime::Set, DateTime::Span

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

Nombres

Fichiers

  • Archivage

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

  • Chemins

    • File::Spec, Path::Class

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

    • File::HomeDir, File::ShareDir

Fichiers

  • Contenu

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

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};

Programmes

  • Proc::Daemon, Proc::Background

  • IPC::Run

  •     my @cmd = qw< ps auwx >;
        run \@cmd, \$input, \$output, \$errors or die "$cmd[0]: $?";
  •     my @cmd1 = qw< ps auwx >;
        my @cmd2 = qw< grep perl >;
        run \@cmd1, "|", \@cmd2, \$output;

Objets

  • Class::Accessor

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

  • Møøse, Coat, Mouse

        package Person;
            use Moose;
    
            has first_name => (isa => "Str", is => "rw");
    
        has last_name  => (isa => "Str", is => "rw");
        sub full_name {
            my ($self) = @_;
            return $self->first_name . " " . $self->last_name
        }

Objects

  • MooseX::Declare

  •     use MooseX::Declare;
    
        class Person {
            has first_name => (isa => "Str", is => "rw");
            has last_name  => (isa => "Str", is => "rw");
    
            method full_name {
               return $self->first_name . " " . $self->last_name
           }
        }

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

Sérialisation

  • Data::Dumper, Storable

  • YAML, YAML::XS

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

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

Courriel

  • MIME::Lite, MIME::Parser

  • Net::SMTP, Net::POP3

  • Email::Simple, Email::MIME, Email::Folder et tous les modules du Perl Email Project

  • Mail::IMAPClient, Mail::Box

Documents

  • Bureautique

    • Text::CSV_XS

    • Spreadsheet::WriteExcel, Spreadsheet::ParseExcel

    • OpenOffice::OODoc, Spreadsheet::ReadSXC

    • Spreadsheet::Read, Spreadsheet::Write

    • PDF::API2

Documents

  • Images

    • GD, Image::Magick, Gimp, Imager

    • PDL (Perl Data Language)

Réseau

  • Protocoles réseau

    • Net::FTP, Net::SSH, Net::SCP

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

    • Net::LDAP, Net::NNTP, Net::RADIUS

    • Net::TacacsPlus, Net::SIP, Net::STOMP...

  • Réseau bas niveau

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

Programmation événementielle

Web

  • Côté client

    • LWP::UserAgent, LWP::Simple

    •     my $page = get($url);
    • HTML::Parser

    • HTML::TreeBuilder

    • WWW::Mechanize

    • WWW::Scripter

    • Web::Scraper

Web

  • Côté serveur

    • CGI, CGI::Simple, CGI::PathInfo

    • CGI::Application

Web

  • Côté serveur

    • 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;
    • POE::Component::Server::HTTP

    • HTTP::Engine

          HTTP::Engine->new(interface => {
              module => "ServerSimple",
              request_handler => sub {
                  HTTP::Engine::Response->new( body => "Hello world" );
              }
          });

HTML

  • Génération

    • HTML::Template

      • HTML::Template::Expr, HTML::Template::Compiled, HTML::Template::JIT, HTML::Template::Pro

    • Petal

    • Mason

    • Template Toolkit

Bases de données

  • Accès

    • DBI

    • MySQL, PostgreSQL, SQLite, Oracle, JDBC, ODBC, Sybase, ADO DB, Unify et plus encore...

    • DBI::Proxy, DBD::Gofer

    • DBIx::Simple

    • DBIx::Connect::FromConfig

  • Abstraction du SQL

    • SQL::Abstract

    • Data::Phrasebook::SQL

ORM

  • Tangram, Alzabo, SPOPS

  • Class::DBI, DBIx::Class

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

Frameworks web modernes

  • Maypole

  • Jifty

  • Catalyst

Tests

  • Test::More, Test::Builder

  • Devel::Cover

  • Test::Deep, Test::LongString

  • Test::Exception, Test::NoWarnings

  • Test::MockModule, Test::MockObject

  • Test::Class (xUnit)

  • Test::LectroTest

Outils

  • Module::Starter, Dist::Zilla

  • ack

  • Perl::Tidy

  • Perl::Critic

  • Perl::Metrics::Simple

Debugging

  • Smart::Comments

  • XXX

  • Devel::SimpleTrace

  • Devel::Graph

  • Devel::TraceLoad, Devel::TraceUse

  • Devel::LeakTrace

  • Devel::ptkdb : perl -d:ptkdb ...

  • Devel::ebug : perl -d:ebug ...

Le monde extérieur

  • Langages

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

  • Bibliothèques externes

    • XS

    • Devel::PPPort

    • SWIG

    • P5NCI

Interfaces

  • Interfaces graphiques

    • Tk, Gtk, WxWidgets, Qt, Prima

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

  • Pilotage natif des OS

    • Mac::Carbon, Mac::Glue

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

Conclusion

  • CPAN, c'est bon, mangez-en

Questions ?

Merci