use
vars __PACKAGE__->VARS;
sub
run;
1;
=pod
=head1 NAME
ASP4::RequestFilter - Filter incoming requests
=head1 SYNOPSIS
use
vars __PACKAGE__->VARS;
sub
run {
my
(
$self
,
$context
) =
@_
;
if
(
$Session
->{is_logged_in} )
{
return
$Response
->Declined;
}
else
{
$Session
->{validation_errors} = {
general
=>
"You must log in first"
};
return
$Response
->Redirect(
"/login/"
);
}
}
1;
Then, in your C<asp4-config.json>:
{
...
"web"
: {
...
"request_filters"
: [
{
"uri_match"
:
"/regexp/to/(path|place).*?"
,
"class"
"My::MemberFilter"
},
{
"uri_match"
:
"/regexp/to/(some|other|area).*?"
,
"class"
"My::OtherFilter"
}
]
...
},
...
}
=head1 DESCRIPTION
Subclass C<ASP4::RequestFilter> to instantly apply rules to incoming
requests.
These RequestFilters also work
for
testing via L<ASP4::API>.
=head1 ABSTRACT METHODS
=head2 run(
$self
,
$context
)
B<IMPORTANT:> Return C<-1> (or
$Response
->Declined) to allow the current RequestFilter to be ignored.
Returning anything
else
...
return
$Response
->Redirect(
"/unauthorized/"
);
...results in the termination of the current request right away.
=head1 BUGS
It's possible that some bugs have found their way into this release.
=head1 HOMEPAGE
of ASP4 in action.
=pod