Your SlideShare is downloading. ×
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Modern Perl
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Modern Perl

8,544

Published on

A brief introduction to modern Perl programming tools that I gave at the OpenTech conference in Spetember 2010.

A brief introduction to modern Perl programming tools that I gave at the OpenTech conference in Spetember 2010.

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
8,544
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
133
Comments
0
Likes
7
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Modern Perl
  • 2. Fifteen years of Perl development
  • 3. In twenty minutes
  • 4. 1995
  • 5. Everyone uses Perl to build dynamic web sites
  • 6. Nasty CGI scripts
  • 7. Web technology has moved on since then
  • 8. Perl technology has moved on since then
  • 9. Perceptions of Perl are stuck in the mid 90s
  • 10. Hi! We're the Perl community and we suck at marketing
  • 11. Perl has all the facilities you would expect in a modern dynamic language
  • 12. Fully! Buzzword! Compliant!
  • 13. A note on version numbers
  • 14. Perl 5 is the current version of Perl
  • 15. Specifically 5.12.1
  • 16. Specifically 5.12.
  • 17. Specifically 5.12.2
  • 18. Perl 6 is still in development
  • 19. (If you want to know more about Perl 6 then ask me later)
  • 20. Perl 5 is still thriving
  • 21. Some powerful Perl tools
  • 22. Template Toolkit
  • 23. Templating engine
  • 24. Powerful and flexible
  • 25. Web and non-web
  • 26. Separation of concerns
  • 27. Dear [% name %], You owe me £[% debt %]. Please pay up by [% date %] or I'll send the boys round. Love Dave...
  • 28. #!/usr/bin/perl use Template; my $tt = Template->new; my $data = { name => 'Joe Random', debt => 100, date => '18 September', }; $tt->process('template.tt', $data);
  • 29. Use with objects
  • 30. [% FOREACH debt IN debts %] Dear [% debt.name %], You owe me £[% debt.amount %]. Please pay up by [% debt.date %] or I'll send the boys round. Love Dave... [% END %]
  • 31. #!/usr/bin/perl use Template; use Debt; my $tt = Template->new; my @debts = Debt->find_all; $tt->process('template.tt', { debts => @debts});
  • 32. http://tt2.org/
  • 33. ORM
  • 34. We all hate SQL
  • 35. DBIx::Class
  • 36. Builds on DBI
  • 37. DBIx::Class::Schema::Loader
  • 38. $ dbicdump MyClass 'dbi:mysql:<db>;<hostname>' <user> <password> Dumping manual schema for MyClass to directory . ... Schema dump completed.
  • 39.
    • Class for each table
    • 40. Attribute for each column
      • Type, mandatory/optional, auto-increment
      • 41. Data type inflation
    • Relationships
  • 42. #!/usr/bin/perl use MyClass; my $sch = MyClass->connect('...'); my $objs = $sch->resultset('MyTable'); while ($objs->next) { print $_->name, “ ”; }
  • 43. while (<FILE>) { my ($code, $name, $desc) = split; my $new_obj = $objs->create({ code => $code, name => $name, desc => $desc, }); print 'New object id: ', $new_obj->id, “ ”; }
  • 44.
    • Complex searching
    • 45. Prefetching data
    • 46. Many-to-many relationships
    • 47. Database migrations
    • 48. Replicated databases
  • 49. http://dbix-class.org/
  • 50. Moose
  • 51. The Modern Object System for Perl 5
  • 52. Perl 5's standard OO system looks a bit bolted on
  • 53. (That's because it was bolted on)
  • 54. Moose hides all that nastiness
  • 55. Pretty syntactic sugar
  • 56. Declarative syntax for attributes
  • 57. package Debt; use Moose; has name => (isa => 'Str', is => 'rw', required => 1); has amount => (isa => 'Num', is => 'rw', required => 1); has date => (isa => 'DateTime', is => 'rw');
  • 58. #!/usr/bin/perl use 5.010; use strict; use warnings; use Debt; my $debt = Debt->new({ name => 'Joe Random', amount => 100, }); say $debt->name, ' owes £', $debt->amount; # Add interest $debt->amount($debt->amount * 1.1); say $debt->name, ' owes £', $debt->amount;
  • 59. use DateTime; # Set due date $debt->date(DateTime->now->add(days => 28)); say $debt->date; # Easier to read say $debt->date->strftime('%A %d %B %Y');
  • 60.
    • More attribute features
    • Roles/Traits
      • Like mixins or interfaces
  • 64. MooseX::*
  • 65. MooSex::*
  • 66. MooseX::*
  • 67. http://moose.perl.org/
  • 68. MVC
  • 69. Catalyst
  • 70. Builds on existing tools
  • 71. Model is DBIx::Class
  • 72. View is Template Toolkit
  • 73. (These are just defaults)
  • 74. Easy to get application framework running
  • 75. $ catalyst.pl MyApp created &quot;MyApp&quot; created &quot;MyApp/script&quot; created &quot;MyApp/lib&quot; created &quot;MyApp/root&quot; created &quot;MyApp/root/static&quot; created &quot;MyApp/root/static/images&quot; created &quot;MyApp/t&quot; [ ... ] created &quot;MyApp/Makefile.PL&quot; created &quot;MyApp/script/myapp_cgi.pl&quot; created &quot;MyApp/script/myapp_fastcgi.pl&quot; created &quot;MyApp/script/myapp_server.pl&quot; created &quot;MyApp/script/myapp_test.pl&quot; created &quot;MyApp/script/myapp_create.pl&quot; Change to application directory and Run &quot;perl Makefile.PL&quot; to make sure your install is complete
  • 76. $ cd MyApp $ script/myapp_server.pl [debug] Debug messages enabled [debug] Statistics enabled [debug] Loaded plugins: .----------------------------------------------------------------------------. | Catalyst::Plugin::ConfigLoader 0.27 | '----------------------------------------------------------------------------' [ ... lots of information ... ] [info] MyApp powered by Catalyst 5.80023 You can connect to your server at http://localhost:3000
  • 77.  
  • 78. Plugins to handle common requirements
  • 79. Authentication/Authorisation
  • 80. Session handling
  • 81. CatalystX::*
  • 82. Catalyst::Plugin::AUTOCRUD
  • 83. http://catalystframework.org/
  • 84. PSGI / Plack
  • 85. PSGI is a specification
  • 86. Like a super-charged CGI
  • 87. And a lot like WSGI
  • 88. Plack is a reference implementation
  • 89. And a lot like Rack
  • 90. Make it easy to move web apps
  • 91. Different application technologies
  • 92. Different web hosting technologies
  • 93. Take a PSGI application and run it anywhere
  • 94. PSGI app is a subroutine reference
  • 95. # app.psgi my $app = sub { # clever stuff goes here };
  • 96. Input comes from a hash passed to sub
  • 97. # app.psgi my $app = sub { my $env = shift; # clever stuff goes here };
  • 98. Sub returns a reference to an array
  • 99. # app.psgi my $app = sub { my $env = shift; return [ 200, [ 'Content-type', 'text/plain' ], [ 'Hello world' ], ]; };
  • 100. Plack distribution includes many tools
  • 101. plackup - a simple PSGI web server
  • 102. $ plackup app.psgi HTTP::Server::PSGI Accepting connections at http://localhost:5000/
  • 103. Plack::Request Plack::Response
  • 104. use Plack::Request; use Plack::Response; use Data::Dumper; my $app = sub { my $req = Plack::Request->new(shift); my $res = Plack::Response->new(200); $res->content_type('text/plain'); $res->body(Dumper $req); return $res->finalize; }
  • 105. Plack::Middleware::* Plack::App::*
  • 106. Most Perl web frameworks support Plack
  • 107. http://plackperl.org/
  • 108. Other Modern Perl tools
  • 109. DateTime
  • 110. TryCatch & autodie
  • 111. Test::* & TAP::*
  • 112. A lot has happened in the ten years you've been ignoring Perl
  • 113. Your local Perl Mongers will be happy to tell you more
  • 114. http://london.pm.org/ http://pm.org/
  • 115. Dave Cross [email_address] @davorg @perlfoundation
  • 116.  

×