Telephone +44(0)1524 64544
Email: info@shadowcat.co.uk

pgwest-2008 - perl5s-alive

Sat Dec 22 00:30:00 2012

Slides for the talk perl5s-alive at pgwest-2008

Perl 5's
Alive!

-

Matt S Trout

-

Catalyst
DBIx::Class
Moose

-

Shadowcat Systems Limited
http://shadowcat.co.uk/

-

Web Development
Consultancy

-

PostgreSQL
WEST 2008

-

But Perl's
Dying!

-

Netcraft
Confirms?

-

X-Powered-By

-

Number of
jobs going
upwards

-

CPAN release
rate going
upwards

-

perl5
powers

-

vox.com
takkle.com

-

vox.com
takkle.com
bbc.co.uk/iplayer

-

vox.com
takkle.com
bbc.co.uk/iplayer
youporn.com

-

Our great
depression

-

Waiting
for godot

-

Waiting
for perl6

-

Waiting
for christmas

-

Fuck
that

-

The new perl5
enlightenment

-

Mature
community

-

Mature
practices

-

Polyglot
programmers

-

New
blood

-

New
ideas

-

CPAN uploads:
(very approx.)
2003 - 100/mo
2004 - 125/mo
2005 - 170/mo
2006 - 200/mo

-

CPAN uploads:
(very approx.)
2005 - 170/mo
2006 - 200/mo
2007 - 350/mo
2008 - 750/mo

-

Ten new CPAN
authors
per -week-

-

Biggest
problem:
finding
developers!

-

-

perl5
v10

-

Performance
improvements

-

Regexp
improvements

-

  given ($name) {
    when ("bob") {
      ...
    }
    when (/jo.*/) {
      ...
    }
    default { ... }
  }

-

Smartmatch
~~

-

Defined-or
//

-

say()

-

C3 MRO

-

C3 MRO
plus MRO::Compat
for perl5 v8

-

CPANPLUS
in core

-

Module::Build
in core

-

Vanilla
Perl

-

Perl on
a stick

-

-

Multi
Paradigm

-

  my @result
    = map { $_+1 }
      sort { $a <=> $b }
      grep { $_ % 2 == 0 }
      @start;

-

  my $adder = sub {
    $_[0] + 1
  };

-

Sub::Curried

-

 curry add_n_to ($n, $val) {
   return $n+$val;
 }

 my $add_10_to = add_n_to( 10 );

 say $add_10_to->(4);  # 14

-

Scalar::Defer

-

  lazy  { expensive_operation() };
  defer { expensive_operation() };

-

IPC::Messaging

-

  my $proc = spawn {
   receive {
     got ping => then {
       print "$$: got ping from $_\n";
       $_->pong;
     };
   };
 };

-

Continuity

-

  sub main {
    my $request = shift;
    $request->print("Your name: <form><input type=text name=name></form>");
    $request->next; # this waits for the form to be submitted!
    my $name = $request->param('name');
    $request->print("Hello $name!");
  }

-

-

Scalable

-

Perl is
-fast-

-

Perl won
Wide Finder

-

Perl scales
to large
applications

-

20,000 lines
is fine

-

Not large?

-

1 large project =
N medium projects
+ M well defined APIs

-

Perl scales
to large teams

-

Perl::Critic

-

svk

-

local::lib

-

use Foo::Bar;

-

distribution
Makefile.PL

-

Perl scales
to large
deployments

-

CPANPLUS::Dist::Deb
cpanspec

-

Devel::NYTProf

-

-

Object
Oriented

-

Moose

-

Perl6
Ruby
CLOS
Smalltalk
Ocaml

-

  has 'name' => (
    is => 'rw',
    isa => 'Str',
    required => 1,
    default => 'darkstar',
    trigger => sub {
      warn "Name changed to: $_[0]";
    }
  );

-

  around new => sub {
    my ($orig, $self, $name) = @_;
    $self->$orig(ucfirst($name));
  };

  before insert => sub {
    $self->assert_permissions;
  };

  override update => sub {
    my ($self) = @_;
    $self->_with_txn_do(sub {
      $self->_log_change;
      super;
    });
  };

-

  package Persistable;

  use Moose::Role;
  use My::DiskUtils qw(write_file);

  sub _save_to_disk {
    my ($self) = @_;
    write_file(
      $self->_calculate_filename,
      $self->_as_string
    );
  }

  after update => sub {
    my ($self) = @_;
    $self->_save_to_disk;
  }

  requires '_calculate_filename';
  requires '_as_string';

-

  $object->meta
         ->compute_all_applicable_attributes
  $attr->get_read_method
  $attr->is_required

-

Roles
compose
safely

-

Roles are
safe. Mixins
rarely are.

-

Method::Signatures

-

  package Foo;

  use Method::Signatures;

  method new (%args) {
      return bless {%args}, $self;
  }

  method get ($key) {
      return $self->{$key};
  }

  method set ($key, $val) {
      return $self->{$key} = $val;
  }

-

Moose::Autobox

-

  my @list = (1, 2, 3);
  @list->each(sub {
    print "List member: $_[0]\n";
  });

  my $add_2 = sub { $_[0] + $_[1] }->curry(2);

  my $allowed = [ qw(moderator admin) ];

  if ($user eq $allowed->any) {
    ...
  }

-

Perl5: Ruby,
but with a
usable object
system ...

-

-

Expressive

-

IO::All

-

  my $data < io('file.txt');

  io('copy.txt') < io('orig.txt');

  $io->[42] = 'Line forty three';

  my @records =
    io('file.data')->separator($sep)
                   ->slurp;

-

Email::Stuff

-

  Email::Stuff->from('cpan@ali.as')
              ->to('santa@northpole.org')
              ->bcc('bunbun@sluggy.com')
              ->text_body($ambush_setup)
              ->attach(io('dead_bunbun_faked.gif')->all,
                       filename => 'dead_bunbun_proof.gif')
              ->send;

-

-

Testable

-

TAP is the
gold standard

-

Working
towards
an RFC

-

Test::More

-

  use Test::More tests => 3;

  ok(1, "First test passes");
  is("bob", "bob", "bob is bob";
  like("bob", qr/BOOM/, "FAIL");

-

Test::Most

-

  use Test::Most qw(defer_plan die);

  lives_ok {
    ...
  } "didn't throw";

  is_deeply(
    $structure,
    { foo => [ 1, 2, { bar => 'baz' } ] },
  );

  all_done;

-

  use Data::Thunk qw(lazy_object);

  sub mock {
    my $class = shift;
    lazy_object { confess "Mock ${class} evaluated" }
      class => $class,
      DESTROY => sub {},
      @_;
  }

-

Malleable

-

Devel::Declare

-

Method::Signatures
is implemented in
perl5

-

Sub::Curried
is implemented in
perl5

-

MooseX::Types::Structured

-

  has 'set_of_name' => (
    isa => ArrayRef[
      Dict[
        first_name => Str,
        last_name => Str,
      ]
    ]
  );

-

Object::Declare

-

 column gender =>
   type is 'text',
   label is 'Gender',
   valid_values are [ qw(male female) ];

-

-

http://enlightenedperl.org/

-

Promoting the new
perl enlightenment

-

Explicitly perl5
+ new wave of CPAN

-

Websites
Tutorials
Screencasts

-

Installation
Accessibility
Niggles

-

Blogging
White papers
Success stories

-

Membership:
Individual
Corporate

-

Working groups:
http://lists.scsys.co.uk/

-

Perl5's
Alive!

-

NO
DISASSEMBLE

-

http://enlightenedperl.org/
http://lists.scsys.co.uk/
these slides will be on
http://shadowcat.co.uk/