Modern Perl

Adam M Dutko
April 17, 2015

Overview


"Modern Perl"

Modern::Perl

Moose || Mouse || Moo

cpanm

Task::Kensho

stratopan.com

examples

"Modern Perl"

What is "Modern Perl?"


chromatic

PerlMonks.org

Best Practices

Module

Tracks Perl Releases

Partial solution to delayed Perl 6

Modern::Perl

Modern::Perl


Enabled per Version Features

http://perldoc.perl.org/5.10.0/perldelta.html

Exceptions Thrown

Less Boilerplate Code

Best Practice Enforcement

IO::File and IO::Handle

Modern::Perl cont.

Modern::Perl cont.


            use Modern::Perl '2009'; 
            ...
            use strict;
            use warnings;
            use feature (say);
            ...
            ## switch statements
            given($foo) {
                when(1) { say "Wee!! }
                ...
                default { say "Someone set us up the bomb!" }
            }
            ...
            #needle/haystack
             ~~ 
            ...
          

Modern::Perl cont.


          use Modern::Perl '2009';
          my @a = (2, 3);
          say 3 ~~ @a ? "T" : "F";

          ...

          [freebsd@freeb ~]$ perl test.pl
          T
          [freebsd@freeb ~]$ 



         # http://perlmaven.com/smart-matching-in-perl-5.10
         

Moose || Mouse || Moo

Moose || Mouse || Moo

Moose - heavy, "post modern", OO, Slowish, Good Docs, XS

http://moose.iinteractive.com/en/about.html

Mouse - lighter, "post modern", OO, Faster, OK Docs, XS-light

http://search.cpan.org/~gfuji/Mouse-2.4.2/lib/Mouse.pm

Moo - much lighter, "post modern", OO, Fastest, Good Docs, Pure Perl

http://perlmaven.com/moo

cpanm

cpanm

http://cpanmin.us

Get, Unpack, Install from CPAN

Zero Dependencies

Zero Configuration

10MB RAM

% curl -L https://cpanmin.us | perl - App::cpanminus

Task::Kensho

Task::Kensho


Seeing One's Nature || True Self

Englightened Perl Development

Top 100 Most Used

cpanm --interactive Task::Kensho

Single Modules (if desired)

stratopan.com

stratopan.com


Private CPAN

Cloud Based

Minimize CPAN Instability

https://stratopan.com/help

local::lib

pinto

Example


          % create a new machine ... 
          %
          % curl -L https://cpanmin.us | perl - App::cpanminus
          % cpanm -i DigitalOcean 
          % cpanm -i Modern::Perl 
          % cpanm -i Class::XSAccessor 
          % cpanm -i Devel::Declare::MethodInstaller::Simple 
          % cpanm -i Sub::Name
          % cpanm --reinstall B::Hooks::OP::Check
        

new_vm.pl

            #!/usr/bin/env perl 
            use Modern::Perl '2011';
            use DigitalOcean;

            ## TODO: You should really add more error handling.
          
            my $client_id = 'CHANGE_ME';
            my $api_key   = 'CHANGE_ME';
             
            my $do = DigitalOcean->new(
                client_id      => $client_id,
                api_key        => $api_key,
                wait_on_events => 1
            );  

            my $new_droplet = $do->create_droplet(
                name      => $ARGV[0],
                size_id   => ,
                image_id  => , 
                region_id => ,
            );

          

Questions?

Sources