Apache2-API
view release on metacpan or search on metacpan
lib/Apache2/API/Request/Params.pm view on Meta::CPAN
$return++;
}
$body = $self->body or ++$return;
};
return if( $return );
if( $@ )
{
return( $self->error( "Unable to get the APR::Request body objet: $@" ) );
}
# So further call on this object will be handled by Apache2::API::Request::Params::Field below
$body->param_class( __PACKAGE__ . '::Field' );
return( $body->uploads( $self->pool ) );
}
1;
# NOTE: POD
__END__
=encoding utf8
=head1 NAME
Apache2::API::Request::Params - Apache2 Request Fields Object
=head1 SYNOPSIS
use Apache2::API::Request::Params;
## $r is the Apache2::RequestRec object
my $req = Apache2::API::Request::Params->new(
request => $r,
# pool of 2Mb
brigade_limit => 2097152,
disable_uploads => 0,
# For example: 3Mb
read_limit => 3145728,
temp_dir => '/home/me/my/tmp'
upload_hook => sub
{
my( $upload, $new_data ) = @_;
# do something
},
);
my $form = $req->args;
# but it is more efficient to call $request->params with $request being a Apache2::API::Request object
my @args = $req->args;
my $val = $req->args( 'first_name' );
my $status = $req->args_status;
my @names = $req->body;
my @vals = $req->body( 'field' );
my $status = $req->body_status;
$req->brigade_limit( 1024 );
my $bucket = $req->bucket_alloc;
# No upload please
$req->disable_uploads( 1 );
# Returns a APR::Request::Cookie::Table object
my $jar = $req->jar;
my $cookie = $req->jar( 'cookie_name' );
my @all = $req->jar( 'cookie_name' );
my $status = $req->jar_status;
# Returns a APR::Request::Param::Table object
my $object = $req->param;
my $val = $req->param( 'first_name' );
my @multi_choice_values = $req->param( 'multi_choice_field' );
# Note that $self->request->param( 'multi_choice_field' ) would return an array reference
# $self being your object inheriting from Apache2::API
my $status = $req->param_status;
$req->parse;
# Returns a APR::Pool object
my $pool = $req->pool;
my $limit = $req->read_limit;
my $temp_dir = $req->temp_dir;
my $upload_accessor = $req->upload;
# Returns a Apache2::API::Request::Upload object
my $object = $req->upload( 'file_upload' );
# Returns a APR::Request::Param::Table object
my $uploads = $req->uploads;
$req->upload_hook( \&some_sub );
=head1 VERSION
v0.1.1
=head1 DESCRIPTION
This is an interface to Apache mod_perl methods to access and manipulate the request data and the way Apache handles those incoming data.
This is taken from L<APR::Request>, L<APR::Request::Params>, L<APR::Request::Apache2> and L<Apache2::Request>
There are some differences with L<Apache2::Request> that provides similar interface. L<Apache2::API::Request::Params> is more cautious when dealing with L<APR::Request::body> and checks its status is 0 (i.e. successful) and traps any exceptions.
The instantiation makes no assumptions as to the data provided, which otherwise could lead to some unpleasant error, and we thrive to provide reliability as the backbone of a REST API.
Finally, it provides access to more L<APR::Request> methods.
=head1 METHODS
=head2 new
This takes an hash or an hash reference of parameters, of which 1 is mandatory: the C<request> parameter that must be an L<Apache2::RequestRec> object.
The L<Apache2::RequestRec> object can be retrieved with L<Apache2::API::Request/request> and this module object can be instantiated more simply by calling L<Apache2::API::Request/apr>, which is basically a shortcut.
Other possible parameters are: L</brigade_limit>, L</disable_uploads>, L</read_limit>, L</temp_dir>, L</upload_hook>.
They can also be accessed as methods as documented below.
=head2 args
With no arguments, this method returns a tied L<APR::Request::Param::Table> object (or undef if the query string is absent) in scalar context, or the names (in order, with repetitions) of all the parsed query-string arguments.
With the $key argument, in scalar context this method fetches the first matching query-string arg. In list context it returns all matching args.
args() will throw an L<APR::Request::Error> object whenever args_status() is non-zero and the return value is potentially invalid (eg C<< scalar $req->args($key) >> will not die if the desired query argument was successfully parsed).
$args = $req->args;
@arg_names = $req->args;
if( $args->isa('APR::Request::Param::Table') )
{
# ok then
}
ok shift( @arg_names ) eq $_ for( keys( %$args ) );
$foo = $req->args( 'foo' );
@bar = $req->args( 'bar' );
=head2 args_status
Returns the final status code of the L<Apache2::RequestRec> handle's query-string parser.
=head2 body
With no arguments, this method returns a tied L<APR::Request::Param::Table> object (or undef if the request body is absent) in scalar context, or the names (in order, with repetitions) of all the parsed cookies.
With the $key argument, in scalar context this method fetches the first matching body param. In list context it returns all matching body params.
L</body> will throw an L<APR::Request::Error> object whenever body_status() is non-zero and the return value is potentially invalid (eg C<< scalar $req->body($key) >> will not die if the desired body param was successfully parsed).
my $body = $req->body;
my @body_names = $req->body;
if( $body->isa('APR::Request::Param::Table') )
{
# ok then
}
ok shift( @body_names ) eq $_ for( keys( %$body ) );
my $alpha = $req->body( 'alpha' );
my @beta = $req->body( 'beta' );
=head2 body_status
Returns the final status code of the L<Apache2::RequestRec> handle's body parser.
=head2 brigade_limit integer
Get or sets the brigade_limit for the current parser. This limit determines how many bytes of a file upload that the parser may spool into main memory. Uploads exceeding this limit are written directly to disk.
=head2 bucket_alloc
Returns the L<APR::BucketAlloc> object associated to this L<Apache2::RequestRec> handle.
=head2 disable_uploads boolean
Engage the disable_uploads hook for this request.
=for Pod::Coverage error
=head2 jar
With no arguments, this method returns a tied L<APR::Request::Cookie::Table> object (or undef if the "Cookie" header is absent) in scalar context, or the names (in order, with repetitions) of all the parsed cookies.
With the C<$key> argument, in scalar context this method fetches the first matching cookie. In list context it returns all matching cookies. The returned cookies are the values as they appeared in the incoming Cookie header.
This will trigger an L<APR::Request::Error> if L</jar_status> returned value is not zero.
my $jar = $req->jar;
my @cookie_names = $req->jar;
if( $jar->isa( 'APR::Request::Cookie::Table' ) )
{
# ok then
}
ok shift( @cookie_names ) eq $_ for( keys( %$jar ) );
my $cookie = $req->jar('apache');
my @cookies = $req->jar('apache');
=head2 jar_status
Returns the final status code of the L<Apache2::RequestRec> handle's cookie header parser.
=head2 param
With no arguments, this method returns a tied L<APR::Request::Param::Table> object (or undef, if the query string and request body are absent) in scalar context, or the names (in order, with repetitions) of all the incoming (args + body) params.
With the $key argument, in scalar context this method fetches the first matching param. In list context it returns all matching params.
L</param> will throw an L<APR::Request::Error> object whenever param_status() is non-zero and the return value is potentially invalid (eg C<scalar $req->param($key)> will not die if the desired param was successfully parsed).
my $param = $req->param;
my @param_names = $req->param;
if( $param->isa(' APR::Request::Param::Table' ) )
{
# ok then
}
ok shift( @param_names ) eq $_ for( keys( %$param ) );
my $foo = $req->param( 'foo' );
my @foo = $req->param( 'foo' );
=head2 param_status
Returns C<($req->args_status, $req->body_status)> in list context; otherwise returns C<< $req->args_status || $req->body_status >>.
=head2 parse
Parses the jar, args, and body tables. Returns C<< $req->jar_status, $req->args_status, $req->body_status >>.
However, it is more efficient to write:
sub handler
{
my $r = shift( @_ );
my $req = Apache2::API::Request::Params->new( request => $r );
# efficiently parses the request body
$r->discard_request_body;
my $parser_status = $req->body_status;
# ...
}
=head2 pool
Returns the L<APR::Pool> object associated to this L<Apache2::RequestRec> handle.
=head2 read_limit integer
Get/set the read limit, which controls the total amount of bytes that can be fed to the current parser.
=head2 temp_dir string
( run in 1.040 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )