The Web That Was - The Promise and Decline of mod_perl

The Web That Was - The Promise and Decline of mod_perl

I talk about the strengths of the Apache C API and how mod_perl integrated with it. Unfortunately, I find perl is in decline, and I asked ChicagoRuby for advice on switching to Ruby.

4668af74c6a388c78bb9dc3606ce00f0?s=128

Aijaz Ansari

January 19, 2013
Tweet

Transcript

  1. The Web That Was Aijaz Ansari @_aijaz_ The Promise and

    Decline of mod_perl 1 Monday, January 21, 13
  2. About Me 2 Monday, January 21, 13

  3. About Me 1991 2 Monday, January 21, 13

  4. About Me 1991 1995 2 Monday, January 21, 13

  5. About Me 1991 1995 1999 2 Monday, January 21, 13

  6. About Me 1991 1995 1999 2005 2 Monday, January 21,

    13
  7. About Me 1991 1995 1999 2005 2013 2 Monday, January

    21, 13
  8. A Brief Timeline 3 Monday, January 21, 13

  9. 1987 4 Monday, January 21, 13

  10. 1987 Perl 1.0 4 Monday, January 21, 13

  11. 1991 Perl 4.0 5 Monday, January 21, 13

  12. 6 Monday, January 21, 13

  13. 7 Monday, January 21, 13

  14. 1991 Perl 4.0 8 Monday, January 21, 13

  15. 1995 Apache 9 Monday, January 21, 13

  16. 1995 Apache C API 9 Monday, January 21, 13

  17. Request Phases 10 Monday, January 21, 13

  18. Request Phases • Post-read-request - e.g.: reloading changed modules •

    URI Translation - honor aliases • Map To Storage - where’s the file? • Header Parsing - e.g.: block certain browsers • Access Control - block by IP address, time of day • Authentication - who are you? • Authorization - what are you allowed to see • Mime-type - set response MIME type • Fixups - last-minute tweaks to env, etc. • RESPONSE - most of the work is done here • Logging - always happens • Cleanup - after client goes away - don’t keep it waiting 11 Monday, January 21, 13
  19. Request Phases • Post-read-request - e.g.: reloading changed modules •

    URI Translation - honor aliases • Map To Storage - where’s the file? • Header Parsing - e.g.: block certain browsers • Access Control - block by IP address, time of day • Authentication - who are you? • Authorization - what are you allowed to see • Mime-type - set response MIME type • Fixups - last-minute tweaks to env, etc. • RESPONSE - most of the work is done here • Logging - always happens • Cleanup - after client goes away - don’t keep it waiting 12 Monday, January 21, 13
  20. Request Phases • Post-read-request - e.g.: reloading changed modules •

    URI Translation - honor aliases • Map To Storage - where’s the file? • Header Parsing - e.g.: block certain browsers • Access Control - block by IP address, time of day • Authentication - who are you? • Authorization - what are you allowed to see • Mime-type - set response MIME type • Fixups - last-minute tweaks to env, etc. • RESPONSE - most of the work is done here • Logging - always happens • Cleanup - after client goes away - don’t keep it waiting 13 Monday, January 21, 13
  21. Request Phases • Post-read-request - e.g.: reloading changed modules •

    URI Translation - honor aliases • Map To Storage - where’s the file? • Header Parsing - e.g.: block certain browsers • Access Control - block by IP address, time of day • Authentication - who are you? • Authorization - what are you allowed to see • Mime-type - set response MIME type • Fixups - last-minute tweaks to env, etc. • RESPONSE - most of the work is done here • Logging - always happens • Cleanup - after client goes away - don’t keep it waiting 14 Monday, January 21, 13
  22. Request Phases • Post-read-request - e.g.: reloading changed modules •

    URI Translation - honor aliases • Map To Storage - where’s the file? • Header Parsing - e.g.: block certain browsers • Access Control - block by IP address, time of day • Authentication - who are you? • Authorization - what are you allowed to see • Mime-type - set response MIME type • Fixups - last-minute tweaks to env, etc. • RESPONSE - most of the work is done here • Logging - always happens • Cleanup - after client goes away - don’t keep it waiting 15 Monday, January 21, 13
  23. Request Phases • Post-read-request - e.g.: reloading changed modules •

    URI Translation - honor aliases • Map To Storage - where’s the file? • Header Parsing - e.g.: block certain browsers • Access Control - block by IP address, time of day • Authentication - who are you? • Authorization - what are you allowed to see • Mime-type - set response MIME type • Fixups - last-minute tweaks to env, etc. • RESPONSE - most of the work is done here • Logging - always happens • Cleanup - after client goes away - don’t keep it waiting 16 Monday, January 21, 13
  24. Request Phases • Post-read-request - e.g.: reloading changed modules •

    URI Translation - honor aliases • Map To Storage - where’s the file? • Header Parsing - e.g.: block certain browsers • Access Control - block by IP address, time of day • Authentication - who are you? • Authorization - what are you allowed to see • Mime-type - set response MIME type • Fixups - last-minute tweaks to env, etc. • RESPONSE - most of the work is done here • Logging - always happens • Cleanup - after client goes away - don’t keep it waiting 17 Monday, January 21, 13
  25. Request Phases • Post-read-request - e.g.: reloading changed modules •

    URI Translation - honor aliases • Map To Storage - where’s the file? • Header Parsing - e.g.: block certain browsers • Access Control - block by IP address, time of day • Authentication - who are you? • Authorization - what are you allowed to see • Mime-type - set response MIME type • Fixups - last-minute tweaks to env, etc. • RESPONSE - most of the work is done here • Logging - always happens • Cleanup - after client goes away - don’t keep it waiting 18 Monday, January 21, 13
  26. Request Phases • Post-read-request - e.g.: reloading changed modules •

    URI Translation - honor aliases • Map To Storage - where’s the file? • Header Parsing - e.g.: block certain browsers • Access Control - block by IP address, time of day • Authentication - who are you? • Authorization - what are you allowed to see • Mime-type - set response MIME type • Fixups - last-minute tweaks to env, etc. • RESPONSE - most of the work is done here • Logging - always happens • Cleanup - after client goes away - don’t keep it waiting 19 Monday, January 21, 13
  27. Request Phases • Post-read-request - e.g.: reloading changed modules •

    URI Translation - honor aliases • Map To Storage - where’s the file? • Header Parsing - e.g.: block certain browsers • Access Control - block by IP address, time of day • Authentication - who are you? • Authorization - what are you allowed to see • Mime-type - set response MIME type • Fixups - last-minute tweaks to env, etc. • RESPONSE - most of the work is done here • Logging - always happens • Cleanup - after client goes away - don’t keep it waiting 20 Monday, January 21, 13
  28. Request Phases • Post-read-request - e.g.: reloading changed modules •

    URI Translation - honor aliases • Map To Storage - where’s the file? • Header Parsing - e.g.: block certain browsers • Access Control - block by IP address, time of day • Authentication - who are you? • Authorization - what are you allowed to see • Mime-type - set response MIME type • Fixups - last-minute tweaks to env, etc. • RESPONSE - most of the work is done here • Logging - always happens • Cleanup - after client goes away - don’t keep it waiting 21 Monday, January 21, 13
  29. Request Phases • Post-read-request - e.g.: reloading changed modules •

    URI Translation - honor aliases • Map To Storage - where’s the file? • Header Parsing - e.g.: block certain browsers • Access Control - block by IP address, time of day • Authentication - who are you? • Authorization - what are you allowed to see • Mime-type - set response MIME type • Fixups - last-minute tweaks to env, etc. • RESPONSE - most of the work is done here • Logging - always happens • Cleanup - after client goes away - don’t keep it waiting 22 Monday, January 21, 13
  30. Enter mod_perl Complete access to C API via Perl Long-running

    process 23 Monday, January 21, 13
  31. How I Use It Writing a RESTful Service 24 Monday,

    January 21, 13
  32. httpd.conf <Directory .../htdocs/rest/rest> SetHandler perl-script PerlAuthenHandler SLA PerlResponseHandler SL AuthType

    Basic AuthName "Speak Friend And Enter" Require valid-user Order allow,deny Allow from all </Directory> 25 Monday, January 21, 13
  33. httpd.conf <Directory .../htdocs/rest/rest> SetHandler perl-script PerlAuthenHandler SLA PerlResponseHandler SL AuthType

    Basic AuthName "Speak Friend And Enter" Require valid-user Order allow,deny Allow from all </Directory> 26 Monday, January 21, 13
  34. httpd.conf <Directory .../htdocs/rest/rest> SetHandler perl-script PerlAuthenHandler SLA PerlResponseHandler SL AuthType

    Basic AuthName "Speak Friend And Enter" Require valid-user Order allow,deny Allow from all </Directory> 27 Monday, January 21, 13
  35. httpd.conf <Directory .../htdocs/rest> SetHandler perl-script PerlAuthenHandler SLA PerlResponseHandler SL AuthType

    Basic AuthName "Speak Friend And Enter" Require valid-user Order allow,deny Allow from all </Directory> 28 Monday, January 21, 13
  36. PerlAuthenHandler sub handler { my $r = shift; my ($status,

    $password) = $r->get_basic_auth_pw; return OK if authenticated($r, $dbh, $r->user, $password); return HTTP_UNAUTHORIZED; } 29 Monday, January 21, 13
  37. PerlAuthenHandler sub handler { my $r = shift; my ($status,

    $password) = $r->get_basic_auth_pw; return OK if authenticated($r, $dbh, $r->user, $password); return HTTP_UNAUTHORIZED; } sub authenticated { my ($r, $dbh, $login, $p) = @_; my $result = &Database::getRow($r, $dbh, "select p=crypt(?, pass) as ok from slUser where email=?", $p, $login); if ($result && $result->{ok}) { return 1; } return 0; } 30 Monday, January 21, 13
  38. PerlResponseHandler sub handler { my $r = shift; my $file

    = getFilePath; my $text = &Template::readFile ($r, $file); $r->print($text); } 31 Monday, January 21, 13
  39. HTML Templates file1.html: ----------- <html> <head></head> <body> <h1>Welcome</h1> <include MyFilterModule

    /file2.html > <h1>Goodbye</h1> </body> </html> 32 Monday, January 21, 13
  40. Filter Module MyFilterModule.pm: ------------------ sub handle { my ($r) =

    @_; my $hash = {}; # process input $hash = { var1 => "Hello", var2 => "World", print => 1, list => [ { name => 'Foo' }, { name => 'Bar'} ] }; return $hash; } 1; 33 Monday, January 21, 13
  41. HTML Templates file1.html: ----------- <html> <head></head> <body> <h1>Welcome</h1> <include MyFilterModule

    /file2.html > <h1>Goodbye</h1> </body> </html> 34 Monday, January 21, 13
  42. The Template File file2.html: ----------- $var1, $var2! <ul> <aohL list>

    <li>$name</li> </aohL></ul> <ifV print>TRUE<elseV>FALSE</ifV> { var1 => "Hello", var2 => "World", print => 1, list => [ { name => 'Foo' }, { name => 'Bar'} ] }; 35 Monday, January 21, 13
  43. The Final Output <html> <head></head> <body> <h1>Welcome</h1> Hello, World! <ul>

    <li>Foo</li> <li>Bar</li> </ul> TRUE <h1>Goodbye</h1> </body> </html> 36 Monday, January 21, 13
  44. The Decline 37 Monday, January 21, 13

  45. The Decline Installation is complex 37 Monday, January 21, 13

  46. The Decline Libraries are stagnant Installation is complex 37 Monday,

    January 21, 13
  47. The Decline Libraries are stagnant Perl talent is hard to

    find Installation is complex 37 Monday, January 21, 13
  48. The Decline Libraries are stagnant Perl talent is hard to

    find The community is shrinking Installation is complex 37 Monday, January 21, 13
  49. 38 Monday, January 21, 13

  50. Do I need to change the way I think? Does

    Ruby have these issues? 38 Monday, January 21, 13
  51. http://TheJoyOfHack.com/ @_aijaz_ Thank