114
Matt's PSGI Archive

Matt's PSGI Archive

Embed Size (px)

DESCRIPTION

A talk I gave at YAPC in Kiev

Citation preview

Page 1: Matt's PSGI Archive

Matt'sPSGIArchive

Page 2: Matt's PSGI Archive

I blame Leo Lapworth

Page 3: Matt's PSGI Archive

London.pm Tech Meet

Page 4: Matt's PSGI Archive

14th August

Page 5: Matt's PSGI Archive

Talkingabout PSGI

Page 6: Matt's PSGI Archive

LeoMentioned

Matt Wright

Page 7: Matt's PSGI Archive

I Tweeted

Page 8: Matt's PSGI Archive
Page 9: Matt's PSGI Archive
Page 10: Matt's PSGI Archive

Somehistory

Page 11: Matt's PSGI Archive

1995

Page 12: Matt's PSGI Archive

Matt's Script Archive

Page 13: Matt's PSGI Archive

Most popular Perl web site on

the web

Page 14: Matt's PSGI Archive

Most well-known Perl code on the

internet

Page 15: Matt's PSGI Archive

FormMail

Page 16: Matt's PSGI Archive

Most widely installed

Perl program on the

internet

Page 17: Matt's PSGI Archive

Most popular

spamming tool on the

internet

Page 18: Matt's PSGI Archive

Terrible example of

Perl programming

Page 19: Matt's PSGI Archive

Popular!=

Good

Page 20: Matt's PSGI Archive

People “learn”Perl from

copying Matt's code

Page 21: Matt's PSGI Archive

People learn “Perl” from

copying Matt's code

Page 22: Matt's PSGI Archive

2001

Page 23: Matt's PSGI Archive

Not Matt's Scripts

Page 24: Matt's PSGI Archive
Page 25: Matt's PSGI Archive

New versions of

Matt's scripts

Page 26: Matt's PSGI Archive

Fewer Bugs

Page 27: Matt's PSGI Archive

Fewer Security

Holes

Page 28: Matt's PSGI Archive

Higherquality code

Page 29: Matt's PSGI Archive

Coding constraints

Page 30: Matt's PSGI Archive

Targeting cheap

hosting plans

Page 31: Matt's PSGI Archive

1. No CPAN Modules

Page 32: Matt's PSGI Archive

2. Perl 5.004_04

Page 33: Matt's PSGI Archive

(First version to

include CGI.pm)

Page 34: Matt's PSGI Archive

Interesting challenge

Page 35: Matt's PSGI Archive

“Interesting” challenge

Page 36: Matt's PSGI Archive

Results not completely satisfactory

Page 37: Matt's PSGI Archive

No Template Toolkit

Page 38: Matt's PSGI Archive

No Email::*

Page 39: Matt's PSGI Archive

Not best practice

Page 40: Matt's PSGI Archive

(Even for 2001)

Page 41: Matt's PSGI Archive

2012

Page 42: Matt's PSGI Archive

NMS looks embarrassing

Page 43: Matt's PSGI Archive

Perl web programming has changed

a lot

Page 44: Matt's PSGI Archive

People still find Matt's

code

Page 45: Matt's PSGI Archive

People still “learn”

“Perl” from Matt's code

Page 46: Matt's PSGI Archive

Some people are directed

to nms project

Page 47: Matt's PSGI Archive

Not best practice

Page 48: Matt's PSGI Archive

Mojolicious blog posts

Page 49: Matt's PSGI Archive
Page 50: Matt's PSGI Archive
Page 51: Matt's PSGI Archive

Matt targeted

cheap hosting plans

Page 52: Matt's PSGI Archive

nms targeted

cheap hosting plans

Page 53: Matt's PSGI Archive

Cheap hosting

plans are not CPAN

friendly

Page 54: Matt's PSGI Archive

Unintendedconsequences

Page 55: Matt's PSGI Archive

nms discourages CPAN use

Page 56: Matt's PSGI Archive

Dilemma

Page 57: Matt's PSGI Archive

Best Practice

vsEasy to install

Page 58: Matt's PSGI Archive

Cheaphosting plans

still exist

Page 59: Matt's PSGI Archive

But do their users still

use Perl/CGI?

Page 60: Matt's PSGI Archive

PHP

Page 61: Matt's PSGI Archive

nms still exists

Page 62: Matt's PSGI Archive

So I started thinking...

Page 63: Matt's PSGI Archive

Why not...

Page 64: Matt's PSGI Archive

...rewrite Matt's scripts again?

Page 65: Matt's PSGI Archive

Using Modern Perl

Best Practices

Page 66: Matt's PSGI Archive

CPAN

Page 67: Matt's PSGI Archive

PSGI

Page 68: Matt's PSGI Archive

DancerCatalyst

MojoliciousWeb::Simple

Page 69: Matt's PSGI Archive

TemplateEmail::*

DBIx::Class

Page 70: Matt's PSGI Archive

Don't expect many users

Page 71: Matt's PSGI Archive

Simple examples

Page 72: Matt's PSGI Archive

Solutions to common problems

Page 73: Matt's PSGI Archive

Entry-level web

programming in Perl

Page 74: Matt's PSGI Archive

Some of this stuff is

ridiculously easy

Page 75: Matt's PSGI Archive

text_clock

Page 76: Matt's PSGI Archive

rand_text

Page 77: Matt's PSGI Archive

About five lines of code

Page 78: Matt's PSGI Archive

Others were overcomplicated

by Matt's implementation

Page 79: Matt's PSGI Archive

guestbookwwwboard

Page 80: Matt's PSGI Archive

Both far easier if you

use a database

Page 81: Matt's PSGI Archive

2013

Page 82: Matt's PSGI Archive

“Let's remove

CGI.pm from Perl core”

Page 83: Matt's PSGI Archive

nms stops working on

cheap hosting

Page 84: Matt's PSGI Archive

Matt's scripts carry on working

just fine

Page 85: Matt's PSGI Archive

(Which is a little bit

annoying)

Page 86: Matt's PSGI Archive

When will those cheap

hosting plans upgrade to Perl 5.20?

Page 87: Matt's PSGI Archive

Probably in about 15

years

Page 88: Matt's PSGI Archive

Plenty of time to get people used

to PSGI

Page 89: Matt's PSGI Archive

Simple examples look like a good idea

Page 90: Matt's PSGI Archive

Progress report

Page 91: Matt's PSGI Archive

Github

Page 92: Matt's PSGI Archive

github.com/davorg/matts-psgi-archive

Page 93: Matt's PSGI Archive

Four (simple)

programs written

Page 94: Matt's PSGI Archive

countdownrand_imagerand_texttext_clock

Page 95: Matt's PSGI Archive

Others to follow soon

Page 96: Matt's PSGI Archive

(Probably by Christmas)

Page 97: Matt's PSGI Archive

Show ussome code

Page 98: Matt's PSGI Archive

Remember I said it was really easy

Page 99: Matt's PSGI Archive

rand_text

Page 100: Matt's PSGI Archive

my $random_file = 'random.txt';my $delimiter = "%%\n";

get '/' => sub { open my $file, '<', get_file($random_file) or error $!; my @phrases; { local $/ = $delimiter; chomp(@phrases = <$file>); } my $phrase = @phrases[rand @phrases];

return $phrase;};

dance;

Page 101: Matt's PSGI Archive

rand_image

Page 102: Matt's PSGI Archive

my $img_dir = 'public/img';

get '/' => sub { opendir my $dir, $img_dir or die $!; my @imgs = grep { -f "$img_dir/$_" } readdir $dir; my $img = @imgs[rand @imgs];

return redirect "/img/$img";};

get '/img/:img' => sub { return send_file 'img/' . params->{img};};

dance;

Page 103: Matt's PSGI Archive

text_clock

Page 104: Matt's PSGI Archive

use Time::Piece;

get '/' => sub { return date();};

sub date { if (! $Display_Format) { $Display_Format = build_format(); }

return localtime->strftime($Display_Format);}

Page 105: Matt's PSGI Archive

sub build_format { my @date_fmt;

push @date_fmt, '%A' if $Display_Week_Day; push @date_fmt, '%B' if $Display_Month; push @date_fmt, '%d' if $Display_Month_Day; push @date_fmt, '%Y' if $Display_Year; push @date_fmt, '%H:%M:%S' if $Display_Time; push @date_fmt, '%Z' if $Display_Time_Zone;

return join ' ', @date_fmt;}

Page 106: Matt's PSGI Archive

github.com/davorg/matts-psgi-archive

Page 107: Matt's PSGI Archive

Feel free to submit code

Page 108: Matt's PSGI Archive

Full replacements

are good

Page 109: Matt's PSGI Archive

Patches to existing

programs are good

Page 110: Matt's PSGI Archive

Documentation is good

Page 111: Matt's PSGI Archive

Any helpis good

Page 112: Matt's PSGI Archive

github.com/davorg/matts-psgi-archive

Page 113: Matt's PSGI Archive

Dave [email protected]

@davorg

Page 114: Matt's PSGI Archive