Matt's PSGI Archive

28,404 views
28,259 views

Published on

A talk I gave at YAPC in Kiev

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

  • Be the first to like this

No Downloads
Views
Total views
28,404
On SlideShare
0
From Embeds
0
Number of Embeds
149
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Matt's PSGI Archive

  1. 1. Matt's PSGI Archive
  2. 2. I blame Leo Lapworth
  3. 3. London.pm Tech Meet
  4. 4. 14th August
  5. 5. Talking about PSGI
  6. 6. Leo Mentioned Matt Wright
  7. 7. I Tweeted
  8. 8. Some history
  9. 9. 1995
  10. 10. Matt's Script Archive
  11. 11. Most popular Perl web site on the web
  12. 12. Most well- known Perl code on the internet
  13. 13. FormMail
  14. 14. Most widely installed Perl program on the internet
  15. 15. Most popular spamming tool on the internet
  16. 16. Terrible example of Perl programming
  17. 17. Popular != Good
  18. 18. People “learn” Perl from copying Matt's code
  19. 19. People learn “Perl” from copying Matt's code
  20. 20. 2001
  21. 21. Not Matt's Scripts
  22. 22. New versions of Matt's scripts
  23. 23. Fewer Bugs
  24. 24. Fewer Security Holes
  25. 25. Higher quality code
  26. 26. Coding constraints
  27. 27. Targeting cheap hosting plans
  28. 28. 1. No CPAN Modules
  29. 29. 2. Perl 5.004_04
  30. 30. (First version to include CGI.pm)
  31. 31. Interesting challenge
  32. 32. “Interesting” challenge
  33. 33. Results not completely satisfactory
  34. 34. No Template Toolkit
  35. 35. No Email::*
  36. 36. Not best practice
  37. 37. (Even for 2001)
  38. 38. 2012
  39. 39. NMS looks embarrassing
  40. 40. Perl web programming has changed a lot
  41. 41. People still find Matt's code
  42. 42. People still “learn” “Perl” from Matt's code
  43. 43. Some people are directed to nms project
  44. 44. Not best practice
  45. 45. Mojolicious blog posts
  46. 46. Matt targeted cheap hosting plans
  47. 47. nms targeted cheap hosting plans
  48. 48. Cheap hosting plans are not CPAN friendly
  49. 49. Unintended consequences
  50. 50. nms discourages CPAN use
  51. 51. Dilemma
  52. 52. Best Practice vs Easy to install
  53. 53. Cheap hosting plans still exist
  54. 54. But do their users still use Perl/CGI?
  55. 55. PHP
  56. 56. nms still exists
  57. 57. So I started thinking...
  58. 58. Why not...
  59. 59. ...rewrite Matt's scripts again?
  60. 60. Using Modern Perl Best Practices
  61. 61. CPAN
  62. 62. PSGI
  63. 63. Dancer Catalyst Mojolicious Web::Simple
  64. 64. Template Email::* DBIx::Class
  65. 65. Don't expect many users
  66. 66. Simple examples
  67. 67. Solutions to common problems
  68. 68. Entry-level web programming in Perl
  69. 69. Some of this stuff is ridiculously easy
  70. 70. text_clock
  71. 71. rand_text
  72. 72. About five lines of code
  73. 73. Others were overcomplicated by Matt's implementation
  74. 74. guestbook wwwboard
  75. 75. Both far easier if you use a database
  76. 76. 2013
  77. 77. “Let's remove CGI.pm from Perl core”
  78. 78. nms stops working on cheap hosting
  79. 79. Matt's scripts carry on working just fine
  80. 80. (Which is a little bit annoying)
  81. 81. When will those cheap hosting plans upgrade to Perl 5.20?
  82. 82. Probably in about 15 years
  83. 83. Plenty of time to get people used to PSGI
  84. 84. Simple examples look like a good idea
  85. 85. Progress report
  86. 86. Github
  87. 87. github.com/davorg/matts-psgi-archive
  88. 88. Four (simple) programs written
  89. 89. countdown rand_image rand_text text_clock
  90. 90. Others to follow soon
  91. 91. (Probably by Christmas)
  92. 92. Show us some code
  93. 93. Remember I said it was really easy
  94. 94. rand_text
  95. 95. 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;
  96. 96. rand_image
  97. 97. 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;
  98. 98. text_clock
  99. 99. use Time::Piece; get '/' => sub { return date(); }; sub date { if (! $Display_Format) { $Display_Format = build_format(); } return localtime->strftime($Display_Format); }
  100. 100. 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; }
  101. 101. github.com/davorg/matts-psgi-archive
  102. 102. Feel free to submit code
  103. 103. Full replacements are good
  104. 104. Patches to existing programs are good
  105. 105. Documentation is good
  106. 106. Any help is good
  107. 107. github.com/davorg/matts-psgi-archive
  108. 108. Dave Cross dave@perlhacks.com @davorg

×