NAME
Apache2::ASP::RequestFilter - Chained request filtering for Apache2::ASP
SYNOPSIS
In your apache2_asp_config.xml:
<config>
<web_application>
...
<settings>
...
</settings>
<request_filters>
<filter>
<uri_match>/members_only/.*</uri_match>
<class>MyWebApp::MemberFilter</class>
</filter>
<filter>
<uri_equals>/disabled_page.asp</uri_equals>
<class>MyWebApp::DisabledPage</class>
</filter>
</request_filters>
...
</web_application>
</config>
Here we define two possible filters and specify which RequestFilter subclasses should handle requests to their respective URIs.
Definition for MyWebApp::MemberFilter
:
package MyWebApp::MemberFilter;
use strict;
use warnings 'all';
use base qw( Apache2::ASP::RequestFilter );
use vars qw(
$Request $Application
$Response $Server
$Session $Form
$Config
);
#==============================================================================
sub run
{
my ($s) = @_;
if( ! $Session->{logged_in} )
{
# Get outta here!
$Response->Redirect("/login.asp");
# Same as Apache2::Const::OK:
return 0;
}
else
{
# Same as Apache2::Const::DECLINED:
return -1;
}# end if()
}# end run()
1;# return true:
The definition for MyWebApp::DisabledPage
would look fairly similar:
package MyWebApp::DisabledPage;
use strict;
use warnings 'all';
use base qw( Apache2::ASP::RequestFilter );
use vars qw(
$Request $Application
$Response $Server
$Session $Form
$Config
);
#==============================================================================
sub run
{
my ($s) = @_;
$Response->Redirect("/login.asp");
# Return '0' to tell Apache to stop processing the request:
return 0;
}# end run()
1;# return true:
DESCRIPTION
The motivation for this class came after using Apache2::ASP on a fairly large project which resulted in a great deal of complex logic to control users' navigation through a long series of forms.
We needed a maintainable way to control users' progress through the forms.
Enter Apache2::ASP::RequestFilter
. With a few lines of configuration we can wipe out dozens of lines of if()
this and if()
that. We get something that, six months from now, we can look at and still understand (and confidently update).
METHODS
run( )
You must override this one method.
RETURN VALUES
VERY IMPORTANT!!!
This gets its own section because it is very important.
The run()
method should return the following kinds of values:
-1
-
Return
-1
when your Filter can safely be ignored.If your
run()
method returnsundef
, Apache2::ASP pretends you returned-1
. 0
-
Return
0
when your Filter has completely finished the response, and a successful response can be sent to the browser. 404
,403
,<401>. etc.
BUGS
It's possible that some bugs have found their way into this release.
Use RT http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP to submit bug reports.
HOMEPAGE
Please visit the Apache2::ASP homepage at http://www.devstack.com/ to see examples of Apache2::ASP in action.
AUTHOR
John Drago mailto:jdrago_999@yahoo.com
COPYRIGHT AND LICENSE
Copyright 2007 John Drago, All rights reserved.
This software is free software. It may be used and distributed under the same terms as Perl itself.