16. CGI.PM
CGI SCRIPT - HELLO WORLD
#!/usr/bin/perl
use CGI qw(header);
print header;
print “Hello world”;
17. CGI.PM
CGI SCRIPT - INTERACTION
#!/usr/bin/perl
use CGI qw(header param);
print header;
my $name = param(‘name’);
print “Hello $name”;
18. CGI.PM
TRANSPARENT POST & GET
FILE UPLOADS
QUICK COOKIES
HTML GENERATION (NOT MY FAVORITE)
FUNCTION SETS: :CGI = PARAM , HEADER, ...
DROP-IN DEVELOPMENT
19. MOD_PERL
PERL AS AN APACHE MODULE
INTERACT WITH EVERY STEP OF APACHE REQUEST CYCLE
PERSISTENT COPY OF PERL IN MEMORY
NO DROP-IN DEVELOPMENT
EXCEPT FOR APACHE::RELOAD
22. MOD_PERL 1
CONTENT HANDLER - HELLO WORLD
package Apache::HelloWorld;
use Apache::Constants qw(:common); # Export OK
sub handler
# mod_perl uses handler method unless specified otherwise
{ print quot;Content-type: text/plainnnquot;; # MY EYES!!
print quot;Hello Worldnquot;;
return OK; # read as HTTP status 200
}
1;
PerlModule Apache::HelloWorld
<Location /HelloWorld>
SetHandler perl-script
PerlHandler Apache::HelloWorld
</Location>
http://localhost/HelloWorld/
23. MOD_PERL 1
CONTENT HANDLER - HELLO WORLD REVISED
package Apache::HelloWorld;
use Apache::Constants qw(:common); # Export OK
sub handler
# mod_perl uses handler method unless specified otherwise
{ my $r = shift;
# 1st argument is instance of Apache's Request object
$r->send_http_header('text/plain');
# Send HTTP header (similar to CGI's header)
$r->print(quot;Hello Worldnquot;);
return OK; # read as HTTP status 200
}
1;
PerlModule Apache::HelloWorld
<Location /HelloWorld>
SetHandler perl-script
PerlHandler Apache::HelloWorld
</Location>
http://localhost/HelloWorld/
24. MOD_PERL 1
CONTENT HANDLER - HELLO BOB!
package Apache::HelloBob
use Apache::Constants qw(:common); # Export OK
sub handler
# mod_perl uses handler method unless specified otherwise
{ my $r = shift;
# 1st argument is instance of Apache's Request object
my %query_string = $r->args; # GET data
my %post_data = $r->content; # POST data
my $name = $query_string{'name'};
$r->send_http_header('text/plain');
# Send HTTP header (similar to CGI's header)
$r->print(quot;Hello $namenquot;);
return OK; # read as HTTP status 200
}
1;
http://localhost/HelloBob?name=Bob
25. APACHE::REQUEST (A::R)
INHERITS FROM APACHE CLASS
MIMICS CGI.PM METHODS
SUPPORTS FILE UPLOADS
SUPPORTS COOKIES - APACHE::COOKIE / APACHE2::COOKIE
AVAILABLE FOR MOD_PERL V1 & V2
26. MOD_PERL 1
CONTENT HANDLER - HELLO BOB WITH A::R
package Apache::HelloWorld;
use Apache::Constants qw(:common); # Export OK
use Apache::Request (); # isa Apache
sub handler
# mod_perl uses handler method unless specified otherwise
{ my $r = shift;
my $apr = Apache::Request->new($r);
# Pass Apaches Request object to A::R
$apr->send_http_header('text/plain');
my $name = $apr->param(‘name’);
# Send HTTP header (similar to CGI's header)
$apr->print(quot;Hello $namenquot;);
return OK; # read as HTTP status 200
}
1;
http://localhost/HelloWorld?name=Bob
27. MOD_PERL 2
CONTENT HANDLER - HELLO WORLD
package Apache2::HelloWorld;
use Apache2::Const qw(:common); # Export OK
sub handler
# mod_perl2 uses handler method unless specified otherwise
{ print quot;Content-type: text/plainnnquot;; # MY EYES!!
print quot;Hello Worldnquot;;
return OK; # read as HTTP status 200
}
1;
PerlModule Apache2::HelloWorld
<Location /HelloWorld>
SetHandler perl-script
PerlResponseHandler Apache2::HelloWorld
</Location>
http://localhost/HelloWorld/
28. MOD_PERL 2
CONTENT HANDLER - HELLO WORLD REVISED
package Apache2::HelloWorld;
use Apache2::Const qw(:common); # Export OK
sub handler
# mod_perl2 uses handler method unless specified otherwise
{ my $r = shift;
# 1st argument is instance of Apache's Request object
$r->content_type('text/plain');
# Send HTTP header (similar to CGI's header)
$r->print(quot;Hello Worldnquot;);
return OK; # read as HTTP status 200
}
1;
PerlModule Apache2::HelloWorld
<Location /HelloWorld>
SetHandler perl-script
PerlResponseHandler Apache2::HelloWorld
</Location>
http://localhost/HelloWorld/
29. MOD_PERL 2
CONTENT HANDLER - HELLO BOB WITH A2::R
package Apache2::HelloBob;
use Apache2::Const qw(:common); # Export OK
use Apache2::Request (); # isa Apache
sub handler
# mod_perl uses handler method unless specified otherwise
{ my $r = shift;
my $apr = Apache2::Request->new($r);
# Pass Apaches Request object to A2::R
$apr->send_http_header('text/plain');
my $name = $apr->param(‘name’);
# Send HTTP header (similar to CGI's header)
$apr->print(quot;Hello $namenquot;);
return OK; # read as HTTP status 200
}
1;
http://localhost/HelloWorld?name=Bob