Apache::Scriptor

Support for Apache handlers conveyor
Download

Apache::Scriptor Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Dmitry Koterov
  • Publisher web site:
  • http://en.dklab.ru/lib/JsHttpRequest/

Apache::Scriptor Tags


Apache::Scriptor Description

Support for Apache handlers conveyor Apache::Scriptor is a Perl module used to handle all the requests through the Perl script. This script is just calling the handlers conveyor for the specified file types.When you place directives like these in your .htaccess file: Action s_copyright "/_Kernel/Scriptor.pl" AddHandler s_copyright .htmApache sees that, to process .htm document, /_Kernel/Scriptor.pl handler should be used. Then, Apache::Scriptor starts, reads this .htaccess and remembers the handler name for .htm document: it is s_copyright. Apache::Scriptor searches for /_Kernel/handlers/s_copyright.pl, trying to find the subroutine with the same name: s_copyright(). Then it runs that and passes the document body, returned from the previous handler, as the first parameter.How to start the new conveyor for extension .html, for example? It's easy: you place some Action-AddHandler pairs into the .htaccess file. You must choose the name for these handlers corresponding to the Scriptor handler file names (placed in /_Kernel/handlers). Apache does NOT care about these names, but Apache::Scriptor does. See example above (it uses two handlers: built-in perl and user-defined s_copyright).EXAMPLE ### Consider the server structure: ### / ### _Kernel/ ### handlers/ ### s_copyright.pl ### ... ### .htaccess ### Scriptor.pl ### .htaccess ### test.htm ### File /.htaccess: # Setting up the conveyor for .htm: # "input" => eperl => s_copyright => "output" Action perl "/_Kernel/Scriptor.pl" AddHandler perl .htm Action s_copyright "/_Kernel/Scriptor.pl" AddHandler s_copyright .htm ### File /_Kernel/.htaccess: # Enables Scriptor.pl as perl executable Options ExecCGI AddHandler cgi-script .pl ### File /_Kernel/Scriptor.pl: #!/usr/local/bin/perl -w use FindBin qw($Bin); # òåêóùàÿ äèðåêòîðèÿ my $HandDir="$Bin/handlers"; # äèðåêòîðèÿ ñ îáðàáîò÷èêàìè # This is run not as CGI-script? if(!$ENV{DOCUMENT_ROOT} || !$ENV{SCRIPT_NAME} || !$ENV{SERVER_NAME}) { print "This script has to be used only as Apache handler! "; exit; } # Non-Apache-handler run? if(!$ENV{REDIRECT_URL}) { print "Location: http"."://$ENV{SERVER_NAME}/ "; exit; } require Apache::Scriptor; my $Scr=Apache::Scriptor->new(); # Setting up the handlers' directory. $Scr->set_handlers_dir($HandDir); # Go on! $Scr->run_uri($ENV{REQUEST_URI},$ENV{PATH_TRANSLATED}); ### File /_Kernel/handlers/s_copyright.pl: sub s_copyright { my ($input)=@_; -f $ENV{SCRIPT_FILENAME} or return -1; # Error indicator # Adds the comment string BEFORE all the output. print '< !-- Copyright (C) by Dmitry Koterov (koterov at cpan dot org) -- > '.$input; return 0; # OK } ### File /test.htm: print "< html >< body >Hello, world!< /body >< /html >"; ### Then, user enters the URL: http://ourhost.com/test.htm. ### The result will be: Content-type: text/html < !-- Copyright (C) by Dmitry Koterov (koterov at cpan dot org) -- > Hello, world! Here are some key features of "Apache::Scriptor": · Uses ONLY perl binary. · Helps to organize the Apache handler conveyor. That means you can redirect the output from one handler to another handler. · Supports non-existance URL handling and 404 Error processing. · Uses .htaccess files to configure. Requirements: · Perl


Apache::Scriptor Related Software