Modern Web Development in Perl

31
Modern Web Development in Perl Jason A. Crome https://crome-plated.com March 14, 2017 Copyright (C) 2017, Jason A. Crome

Transcript of Modern Web Development in Perl

Page 1: Modern Web Development in Perl

Modern Web Development in Perl

Jason A. Crome https://crome-plated.com

March 14, 2017 Copyright (C) 2017, Jason A. Crome

Page 2: Modern Web Development in Perl

What is Perl?

Page 3: Modern Web Development in Perl

Common Misconceptions• It’s dead

• It’s dying

• It’s just for sysadmins

• It’s not for real development

• It’s not modern - hasn’t been updated in years

Page 4: Modern Web Development in Perl

Why the Misconceptions?• Bad Marketing

• Perl 6

• Matt’s Script Archive

Page 5: Modern Web Development in Perl

Perl 6• Sister language to Perl 5, not a successor!

• Poorly marketed as such

• Fantastic language!

• Both functional and procedural

• Thread-safe

Page 6: Modern Web Development in Perl

Strengths• Data Munging

• Bioinformatics

• Devops

• Web application development

• MMOs

• Whipuptitude

Page 7: Modern Web Development in Perl

Weaknesses• Threading

• Device Drivers

• 3D game development

• Learning curve

Page 8: Modern Web Development in Perl

Who’s Using Perl?• ZipRecruiter

• Booking.com

• Craigslist

• Ticketmaster

• Amazon

• BBC

• NASA

• Rent.com

• DuckDuckGo

• IMDB

• CrowdTilt

• ShutterStock

• ServerCentral

• Bank of America

Page 9: Modern Web Development in Perl
Page 10: Modern Web Development in Perl

Actively Developed• 24th version of Perl 5

• 26th version to be released ~June

• One major release every year

• 5.26 will be 8th production release in last 7 years

• Does that seem like a dead language to you?!

Page 11: Modern Web Development in Perl

What is Modern Perl?• First-class OO programming

• Great Testing Infrastructure

• Deployment and Configuration Toolchain

• Active user community

• Modern language features

• Modern frameworks

Page 12: Modern Web Development in Perl

Object Oriented • Moose

• Moo

• (before that) Overloaded hashes

Page 13: Modern Web Development in Perl

package Point; use Moose;

has 'x' => (isa => 'Int', is => 'rw', required => 1); has 'y' => (isa => 'Int', is => 'rw', required => 1);

sub clear { my $self = shift; $self->x(0); $self->y(0); }

package Point3D; use Moose;

extends 'Point';

has 'z' => (isa => 'Int', is => 'rw', required => 1);

after 'clear' => sub { my $self = shift; $self->z(0); };

Page 14: Modern Web Development in Perl

# hash or hashrefs are ok for the constructor my $point1 = Point->new(x => 5, y => 7); my $point2 = Point->new({x => 5, y => 7});

my $point3d = Point3D->new(x => 5, y => 42, z => -5);

Using the Point Class

Page 15: Modern Web Development in Perl

Roles with Moosepackage MyApp::CLI::SetPassword;

use strictures 2; use MooseX::App::Command; extends qw( MyApp::CLI ); with qw( MyApp::Role::CLI::WithPassword MyApp::Role::CLI::WithUsername MyApp::Role::CLI::WithUser ); use MyApp::Module;

sub run ( $self ) { $self->_say( "Changing password for " . $self->username . '...' ); $self->user->password( $self->password ); $self->user->update; say "Done!"; }

1;

Page 16: Modern Web Development in Perl

Testing Infrastructure• Test2

• Test::Class::Moose

• prove

• Test::Harness

• TAP

Page 17: Modern Web Development in Perl

Deployment/Configuration• Plack

• cpanfile

• Carton

• perlbrew

• plenv

Page 18: Modern Web Development in Perl

Community• Perl’s greatest strength

• Perl Mongers

• YAPC / TPC

• (Meta)CPAN

Page 19: Modern Web Development in Perl

MetaCPAN

Page 20: Modern Web Development in Perl

Modern Language Features/Tools

• Named Parameters

• XS

• POD

• Perlcritic

• Perltidy

Page 21: Modern Web Development in Perl

Named Parameters sub clear( $self ) { $self->x(0); $self->y(0); }

after 'clear' => sub( $self ) { $self->z(0); };

sub set( $self, $x, $y, $z) { $self->x( $x ); $self->y( $y ); $self->z( $z ); }

Page 22: Modern Web Development in Perl

Modern Frameworks• ORMs

• Templating Frameworks

• Web App Frameworks

Page 23: Modern Web Development in Perl

ORMs• DBI

• Class::DBI

• DBIx::Class

• Rose::DB

Page 24: Modern Web Development in Perl

DBIx::Class$user = $schema->resultset('User')->find( { email => $self->email } );

$user = $schema->resultset('User')->create( { username => $self->username, password => $self->password, email => $self->email, } ); my $user_rs = $schema->resultset('User')->search({ email => { like => '%example.com' }, },{ order_by => { username => 'ASC' }, } );

Page 25: Modern Web Development in Perl

Templating Frameworks• HTML::Template

• Mason

• Template Toolkit

• And many, many others…

Page 26: Modern Web Development in Perl

Web App Frameworks

Page 27: Modern Web Development in Perl

And now, Dancer2!

Page 28: Modern Web Development in Perl

Questions?

Page 29: Modern Web Development in Perl

Thanks!https://crome-plated.com

[email protected]

Sample Code: https://github.com/cromedome/RWD

Slides: https://www.slideshare.net/cromedome/modern-web-development-in-perl

Page 30: Modern Web Development in Perl

Bonus 1: Point Class, Old World Perl

Page 31: Modern Web Development in Perl

package Point;

sub new { my ($class, $x, $y) = @_; my $self = { x => $x, y => $y, }; return bless $self, $class; }

sub get_x { return $_[0]->{x}; }

sub set_x { return $_[0]->{x} = $_[1]; }

sub get_y { return $_[0]->{y}; }

sub set_y { return $_[0]->{y} = $_[1]; }

1;