Web Development in Perl


Published on

This was my presentation during WebOSS '07, the first Web and Open Source Technology Conference in Kolkata, on 13th October 2007

Published in: Technology
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Web Development in Perl

  1. 1. WEB DEVELOPMENT IN Perl Naveen Gupta nkrgupta@gmail.com
  2. 2. <ul><li>AGENDA </li></ul><ul><ul><li>Introduction to Web Development & Perl </li></ul></ul><ul><ul><li>Perl Powered Sites/Application </li></ul></ul><ul><ul><li>Basic Web Programming in Perl </li></ul></ul><ul><ul><li>CGI Programming in Perl </li></ul></ul><ul><ul><li>Creating HTML Forms </li></ul></ul><ul><ul><li>mod_perl </li></ul></ul><ul><ul><li>Templating Systems in Perl </li></ul></ul><ul><ul><li>Web 2.0 Applications in Perl </li></ul></ul><ul><ul><li>Perl vs PHP - A Tale of 2 Languages </li></ul></ul>
  3. 3. <ul><li>Introduction to Web Development </li></ul><ul><li>What is Web Dev? </li></ul><ul><li>– Development of websites, internet applications, e-commerce sites, social networks etc. </li></ul><ul><li>– Includes Web Designing, Content Development, client/server side coding, Web Server configuration </li></ul><ul><li>– Flexible Model, easy to adopt to, Barriers to entry very low </li></ul><ul><li>– Contributing Factors - Propagation of Open Source Technologies, WYSIWYG Tools, Internet Awareness </li></ul><ul><li>– Killer Apps – Google Docs, Flickr, WordPress, PhpBB, WikiMedia, YouTube and millions others </li></ul>
  4. 4. <ul><li>Dominant Technologies </li></ul><ul><ul><li>C, C++, Pascal, Shell Script </li></ul></ul><ul><ul><li>ASP </li></ul></ul><ul><ul><li>JAVA, J2EE and related Frameworks </li></ul></ul><ul><ul><li>Perl with or without CGI </li></ul></ul><ul><ul><li>PHP </li></ul></ul><ul><ul><li>.NET – C#, VB.NET </li></ul></ul><ul><ul><li>Python </li></ul></ul><ul><ul><li>Ruby on Rails </li></ul></ul><ul><ul><li>ColdFusion </li></ul></ul>
  5. 5. <ul><li>Introduction to Perl </li></ul><ul><ul><li>Created by Larry Wall in 1987 </li></ul></ul><ul><ul><li>Interpreted, Scripting Language </li></ul></ul><ul><ul><li>C - like syntax </li></ul></ul><ul><ul><li>Best of C, awk and sed </li></ul></ul><ul><ul><li>Best language for Text Manipulation/ Data Processing </li></ul></ul><ul><ul><li>Swiss Army knife for SysAdmins, Programmers </li></ul></ul><ul><ul><li>Supports modules, OO, DB interaction, pointers, regular expressions, multithreading, sockets, MVC frameworks </li></ul></ul><ul><ul><li>Highly Portable, well documented </li></ul></ul>
  6. 6. <ul><li>Perl and the WEB </li></ul><ul><ul><li>De facto language for CGI Programs </li></ul></ul><ul><ul><li>Made popular by Matt’s Script Archive </li></ul></ul><ul><ul><li>Easy to build and maintain </li></ul></ul><ul><ul><li>Wide acceptance of LAMP framework – Linux, Apache, MySQL, PHP/Perl/Python/Ruby </li></ul></ul><ul><ul><li>Great DB support via DBI set of Modules </li></ul></ul><ul><ul><li>Strength of Perl – CPAN, Comprehensive Perl Archive Network </li></ul></ul><ul><ul><li>Hands down winner with the advent of mod_perl, FastCGI, Catalyst, Moose etc. </li></ul></ul>
  7. 7. <ul><li>How to get Perl? </li></ul><ul><li>- For *NIX Platforms – Included with almost every Linux, BSD, Solaris, OS X installation. Source can be can be downloaded from http://www.perl.org and compiled using “ gcc”. RPMs are also available. </li></ul><ul><li>- For Windows Platforms – Installation Binary distributed by http://www.activestate.com as ActivePerl. Yet, complete LAMP installations distributed by http:// www.apachefriends.org , http://www.apache.org , http://www.indigostar.com etc. are most popular. Complete listing can be found at http://www.perl.org/ports </li></ul>
  8. 8. <ul><li>Perl Powered Sites/Applications </li></ul>
  9. 9. <ul><li>My First Web Program in Perl </li></ul>#!/usr/bin/perl print “Content-type:/text/html ”; print “Hello World!<br>”;
  10. 10. <ul><li>Adding a Bit of `Perl` </li></ul>#!/usr/bin/perl print “Content-type:/text/html ”; my $time= localtime ( time ); print “Today is $time <br>”; foreach my $key ( sort keys %ENV){ print qq{$key = $ENV{$key} <br>}; }
  11. 11. <ul><li>Jazz it up with a little HTML </li></ul>#!/usr/bin/perl print “Content-type:/text/html ”; print “<h1>Welcome to my First Perl Web page</h1>”; print “Perl is a great language!<br>”; print “It can create killer websites too!<br>”; print “Wanna see how?”;
  12. 12. <ul><li>Here Document </li></ul>#!/usr/bin/perl print “Content-type:/text/html ”; print <<HTML; <h1>Welcome to my First Perl Web page</h1> Perl is a great language!<br> It can create killer websites too!<br> Wanna see how? HTML
  13. 13. <ul><li>Going Dynamic with CGI </li></ul>#!/usr/bin/perl use CGI; use strict; my $cgi=new CGI; print $cgi->header(); print $cgi->start_html(-title=>’First CGI.pm program’, -meta=>{‘keywords’=>’perl cgi’, ‘ copyright’=>’WebOSS ‘07’}, -style=>{‘src’=>’style.css’}, -BGCOLOR=>’blue’); contd….
  14. 14. … contd Going Dynamic with CGI print $cgi->h1(“Welcome to a CGI APP!”); print “Your IP Address is : ”.$ENV{‘REMOTE_ADDR’}.“<br>”; print “You have been directed here from: $ENV{‘HTTP_REFERER’}” ; print $cgi->a({-href=>’http://search.cpan.org’, -target=>’_blank’}, “Go to CPAN!”); print $cgi->end_html;
  15. 15. <ul><li>The Power of mod_perl </li></ul><ul><li>“… mod_perl  is more than CGI scripting on steroids. It is a whole new way to create dynamic content by utilizing the full power of the Apache web server to create stateful sessions, customized user authentication systems, smart proxies and much more. Yet, magically, your old CGI scripts will continue to work and work very fast indeed. With mod_perl you give up nothing and gain so much! …” – Lincoln Stein, Author – CGI.pm </li></ul><ul><li>- Perl Interpreter embedded in Apache </li></ul><ul><li>- Overcomes one-process-per-request limitation of CGI, 100x faster! </li></ul><ul><li>- Write Apache modules in Perl instead of C </li></ul><ul><li>- Hundreds of Modules available in CPAN </li></ul><ul><li>- Numerous Application Frameworks, Templating Systems </li></ul><ul><li>- Configure Apache’s httpd.conf via Perl </li></ul>
  16. 16. <ul><li>Perl Templating Systems </li></ul><ul><ul><li>HTML::Mason </li></ul></ul><ul><ul><li>Template Toolkit </li></ul></ul><ul><ul><li>HTML::Template </li></ul></ul><ul><ul><li>SSI using mod_include or Apache::SSI module </li></ul></ul><ul><ul><li>Why use Templating System? </li></ul></ul><ul><ul><li>Consistency of Appearance </li></ul></ul><ul><ul><li>Reusability </li></ul></ul><ul><ul><li>Abstraction between logic and design </li></ul></ul><ul><ul><li>Division of Labour </li></ul></ul>
  17. 17. <ul><li>Web 2.0 Apps in Perl </li></ul><ul><ul><li> CGI::Ajax </li></ul></ul><ul><ul><ul><li>Object Oriented module by Brian C. Thomas </li></ul></ul></ul><ul><ul><ul><li>Eliminates the need to write JS for AJAX Calls </li></ul></ul></ul><ul><ul><ul><li>Generates JS Functions from output by Perl subroutines </li></ul></ul></ul><ul><ul><ul><li>Can be implemented in large projects </li></ul></ul></ul><ul><ul><ul><li>HTML::TagCloud </li></ul></ul></ul><ul><ul><ul><li>Generates Tag Clouds, with different font sizes </li></ul></ul></ul><ul><ul><ul><li>CSS Based </li></ul></ul></ul><ul><ul><ul><li>Add method takes 3 arguments – a) Tag Name </li></ul></ul></ul><ul><ul><ul><ul><ul><li>b) URL to link to </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>c) Weight </li></ul></ul></ul></ul></ul>
  18. 18. WEB DEVELOPMENT IN Perl Perl vs PHP
  19. 19. APACHE INTEGRATION DOCUMENTATION API/ LIBRARY SUPPORT LEARNING CURVE PURPOSE/ UTILITY mod_php mod_perl, Fast CGI http:// www.php.net Perldoc, http:// perldoc. perl.org , CPAN PEAR and PECL, both from http://www.php.net 48606 active modules on CPAN and many others elsewhere Easier than Perl Easier than C, JAVA, .NET Made primarily for WEB. Can do CLI and other tasks. Multi-purpose, primarily for text pocessing, equally suited for sysadmin and web apps PHP Perl
  20. 20. WordPress, phpBB, Drupal, Coppermine, phpMyAdmin AWStats, Slash Code, BugZilla CMS / APPLICATIONS Yes, the main reason for its popularity Only with Modules like Mason, HTML::Template, Template::Toolkit etc. HTML EMBED PHP Perl
  21. 21. <ul><li>THANK YOU! </li></ul><ul><li>use Perl; </li></ul>