CGI-Builder-CgiAppAPI
view release on metacpan or search on metacpan
lib/CGI/Builder/CgiAppAPI.pm view on Meta::CPAN
%params = $s->param() # dereferenced
As you see, in scalar context the C<param()> method returns the reference to the underlying hash containing the parameters. This allows you to interact directly with the whole hash, or checking and deleting single parameters very easily:
$P = $s->param ;
while ( my ($p, $v) = each %$P )
{ do_something_useful }
# check if exists a parameter
exists $s->param->{myPar} ;
# delete a parameter
delete $s->param->{myPar} ;
In list context the param() returns a copy of the parameter hash.
=head1 API CONVERSION TABLE (quick reference)
CGI::Application[::Plus] CGI::Builder
======================== ============
mode_param [default:'rm'] cgi_page_param [default:'p']
start_mode [default:'start'] page_name [default:'index']
get_current_runmode page_name
QUERY cgi
query cgi
cgiapp_get_query cgi_new
PARAMS param
TMPL_PATH page_path
tmpl_path page_path
prerun_mode switch_to
header_prop header
header_add header
header_type redirect | dont_send_header | -
run_modes page_handler_map
run process
cgiapp_init OH_init
startup OH_init
cgiapp_prerun OH_pre_process
cgiapp_postrun OH_fixup
teardown OH_cleanup
dump CGI::Builder::Test::dump
dump_html CGI::Builder::Test::dump_html
load_tmpl - | CGI::Builder::HTMLtmpl
$ENV{CGI_APP_RETURN_ONLY} capture('process')
CGI::Application::Plus CGI::Builder
====================== ============
runmode [default:'start'] page_name [default:'index']
RM_prefix [default:'RM_'] 'PH_' (constant value)
page page_content
start_capture capture
stop_capture capture
qparam --
=head1 CHANGES
The CBF implements a different metaphor based on 'processing pages' instead of 'running applications'. This should be simpler to understand (specially for beginners) because it is more consistent with the specific task that a CGI::Builder application...
Even if the internal implementation of similar methods is greatly improved and has a completely different internal code, from the user point of view most changes here don't require more than a simple translation of identifier from one concept to the ...
The CGI::Application philosophy is very simple: the application defines several run methods, and each run method is organized to produce and return its own output page. You have to set a map in the application to define what run method has to be call...
The CBF let you organize your application in a far more flexible way, it just need to find some C<page_content> to send to the client: it does not matter what method or handler has set it during the process, (and the C<page_content> itself might even...
This flexible structure open several handy and powerful possibilities to your application and to the extension system. If you want to know some more details about that, you could read L<CGI::Application::Plus/"Exclusive Features and Improvements"> wh...
B<Note>: The changes reported below are needed just if you want to completely convert your old cgiapp to the CBF. Until you include this API in your build, they are transparently added to your application.
=head2 mode_param
Change it with C<cgi_page_param>.
C<mode_param> is used to define the query parameter that holds the run mode, and its default is 'rm'. The CGI::Builder property to use is the C<cgi_page_param> and its default is 'p', so if your old cgiapp rely on the default, you should either set e...
# (simpler) solution 1: put this line in the OH_init()
$s->cgi_page_param = 'rm';
# solution 2: change the links like: '/webapp.cgi?rm=myRunmode'
# to '/webapp.cgi?p=myRunmode'
Besides, the old C<mode_param> accepted as well a CODE reference returning the page name, while C<cgi_page_param> doesn't. In this case - if you want to generate the page name by some sub - you should just override the C<get_page_name()> method, and ...
sub get_page_name {
my $s= shift;
... your code to get the page name ...
$s->page_name = $resulting_page_name
}
=head2 start_mode, get_current_runmode, runmode
Change them with C<page_name> (i.e. the cgiapp runmode).
C<start_mode>, C<get_current_runmode> (and C<runmode> in CGI::Application::Plus) are used to set and get the (start) run mode (i.e. the CGI::Builder page name). You should use the C<page_name> property instead.
$s->page_name = 'mystart'
$s->page_name # always returns the current page name
B<Important Note>: Remember that the default C<page_name> is 'index' while the default run mode was 'start' so if you get rid of this API after a migration you should consider this new default.
=head2 QUERY and query
Change them with C<cgi>.
C<QUERY> (and C<query> in CGI::Application::Plus) are used to pass a cgi object with the C<new()> method. You should use C<cgi> property instead.
$webapp = WebApp->new(cgi=>CGI->new) ;
# or
$s->cgi = CGI->new ;
=head2 cgiapp_get_query
Just change it with C<cgi_new>.
=head2 PARAMS
Change them with C<param>.
C<PARAMS> is used to pass a reference to an hash containing some param with the C<new()> method or to set some application param. The CBF accessor to set and retrieve your application param is the C<param()> property group accessor, you should use it...
=head2 TMPL_PATH and tmpl_path
( run in 0.629 second using v1.01-cache-2.11-cpan-5735350b133 )