MPMinus::RAMST - RAMST Ain't an MVC SKEL Transaction
Version 1.02
use base qw/MPMinus::RAMST/; __PACKAGE__->register_handler( # GET / handler => "index", method => "GET", path => "/", query => undef, deep => 0, requires=> [qw/ ADMIN USER TEST /], attrs => { foo => 'test', bar => 1, baz => undef, }, description => "Index", code => sub { my $self = shift; my $name = shift; my $r = shift; my $q = $self->get("q"); my $usr = $self->get("usr"); #my $req_data = $self->get("req_data"); #my $res_data = $self->get("res_data"); $self->set( res_data => "Output scalar value" ); $self->code( 200 ); return 1; # Or 0 only!! }); my $server = __PACKAGE__->new( request => $r, # Apache2::RequestRec object location => "/rest", blank => { param1 => "init value" }, dvars => { # Valid dir variables key1 => "default value", key2 => 0, }, ); $server->run_handler( $m ); $server->cleanup;
Base class for not "MVC SKEL Transaction" model implementation
__PACKAGE__->register_handler( # GET / handler => "index", method => "GET", path => "/", query => undef, deep => 0, requires=> [qw/ ADMIN USER TEST /], attrs => { foo => 'test', bar => 1, baz => undef, }, description => "Index", code => sub { my $self = shift; my $name = shift; my $m = shift; my $r = $m->r; my $q = $self->get("q"); my $usr = $self->get("usr"); #my $req_data = $self->get("req_data"); #my $res_data = $self->get("res_data"); $self->set( res_data => "Output scalar value" ); $self->code( 200 ); return 1; # Or 0 only!! });
This is non class method! Sets new handler for trapping the request
Sets attributes of the handler as hashref
Default: {}
In the future, you can get the attribute values using the get_attr("attr_name") method
Sets callback function
This callback function returns bool status of the operation
Enables deeply scanning of path for handler lookup. If this param is set to true then the mechanism of the deeply lookuping will be enabled. For example:
For registered path /foo with enabled deep lookuping will be matched any another incoming path that begins from /foo prefix: /foo, /foo/bar, /foo/bar/baz and etc.
Sets the description of handler
Default: none
Sets the name of handler
Default: noname
Sets the method for trapping. Supported: GET, POST, PUT, DELETE.
Default: GET
Sets the path for trapping
Default: /
Note: This is second (tailed) part of the full path - it's suffix. Path not contents the base location string, e.g. without "/rest" prefix. If you specify "/test/null", then the real path will be trapped "/rest/test/null" as path
Sets the query string for trapping
Default: undef
Example #1: action=foo
Catch if the "action" parameter in query string equals "foo"
Example #2: action=foo&object=bar
Catch if the "action" parameter in query string equals "foo" and "object" parameter equals "bar"
Example #3: action=
Catch if the "action" parameter in query string equals any value
Array-ref structure that contains list of roles or any data for authorization
Default: []
my $server = __PACKAGE__->new( prefix => "MyTestApp", request => $r, # Apache2::RequestRec object location => "/rest", blank => { param1 => "init value" }, dvars => { # Valid dir variables key1 => "default value", key2 => 0, }, );
Constructor. Creates server instance by base location prefix (base attribute)
The "blank" defines initial working structure for input and output variable data
The key-value structure, that defines list of dir_config variables and default values for each
Location is a named part of the "Location" section in Apache's configuration file
Prefix string. Default: current invocant class name
Optional value of the Apache2::RequestRec object
You can set and get data from the working structure using the "set" and "get" methods
$server->cleanup;
Cleans the all working data and sets it to blank structure
my $code = $server->code; my $code = $server->code( 500 );
Gets/Sets response HTTP code
Default: 200 (OK)
my $data = $server->data; $server->data({ param1 => "new value", });
Gets/Sets working structure
Default: $self->{blank}
my $error = $server->error;
Returns current error string
my $status = $server->error( "new error string" );
Sets error string and returns status of the server
my $status = $server->error( 500, "new error string" );
Sets response code and error string and returns status of the server
my $value = $server->get("param1");
Returns parameter "param1" from working structure
my $value = $server->get_attr("foo");
Returns attribute "foo" from attributes of the current handler
my $value = $server->get_dvar("key");
Returns dir config variable "key"
my $value = $server->get_svar("key");
Returns system variable "key"
$server->init_svars;
Takes current method, path and query string from request heads and sets system "key" value for definition the current handler
my $location = $server->location;
Returns base location of current server instance. Default: "" in root (default) context "/"
my $handler = $server->lookup_handler; my $handler = $server->lookup_handler("handler_name");
Returns $handler structure from hash of registered handlers; or undef if handler is not registered
$server->lookup_method("GET"); # returns 1 $server->lookup_method("OPTIONS"); # returns 0
Checks the availability of the method by its name and returns the status
my $prefix = $server->prefix;
Returns prefix of current server instance. Default: invocant class name
my $requires = $server->requires; # [1, 2, 7]
Returns list as "array-ref" of requires for authorization from attributes of the current handler
$server->run_handler( $m ); # $m - this is MPMinus main object
Runs the callback function from current handler with $m parameter
Note: any number of parameters can be specified, all of them will be receive in the callback function
Returns: server status
$server->get("param1", "new value");
Sets new value to parameter "param1" in working structure and returns status of the operation
$server->set_dvar("key", "new value");
Sets new value to dir config variable "key"
$server->set_svar("key", "new value");
Sets new value to system variable "key"
my $status = $server->status; my $status = $server->status( $new_status );
Gets/Sets status of the server
See CHANGES file
CHANGES
mod_perl2, MPMinus
mod_perl2
See TODO file
TODO
* none noted
MPMinus, Apache2::REST
Serż Minus (Sergey Lepenkov) http://www.serzik.com <abalama@cpan.org>
Copyright (C) 1998-2019 D&D Corporation. All Rights Reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See LICENSE file and https://dev.perl.org/licenses/
LICENSE
To install MPMinus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MPMinus
CPAN shell
perl -MCPAN -e shell install MPMinus
For more information on module installation, please visit the detailed CPAN module installation guide.