Params::CallbackRequest

Functional and object-oriented callback architecture
Download

Params::CallbackRequest Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • David Wheeler
  • Publisher web site:
  • http://search.cpan.org/~dwheeler/

Params::CallbackRequest Tags


Params::CallbackRequest Description

Functional and object-oriented callback architecture Params::CallbackRequest is a Perl module that provides functional and object-oriented callbacks to method and function parameters. Callbacks may be either code references provided to the new() constructor, or methods defined in subclasses of Params::Callback. Callbacks are triggered either for every call to the Params::CallbackRequest request() method, or by specially named keys in the parameters to request().The idea behind this module is to provide a sort of plugin architecture for Perl templating systems. Callbacks are triggered by the contents of a request to the Perl templating server, before the templating system itself executes. This approach allows you to carry out logical processing of data submitted from a form, to affect the contents of the request parameters before they're passed to the templating system for processing, and even to redirect or abort the request before the templating system handles it.SYNOPSISFunctional parameter-triggered callbacks: use strict; use Params::CallbackRequest; # Create a callback function. sub calc_time { my $cb = shift; my $params = $cb->params; my $val = $cb->value; $params->{my_time} = localtime($val || time); } # Set up a callback request object. my $cb_request = Params::CallbackRequest->new( callbacks => ); # Request callback execution. my %params = ('myCallbacker|calc_time_cb' => 1); $cb_request->request(\%params); # Demonstrate the result. print "The time is $params{my_time} ";Or, in a subclass of Params::Callback: package MyApp::Callback; use base qw(Params::Callback); __PACKAGE__->register_subclass( class_key => 'myCallbacker' ); # Set up a callback method. sub calc_time : Callback { my $self = shift; my $params = $self->request_params; my $val = $cb->value; $params->{my_time} = localtime($val || time); }And then, in your application: # Load order is important here! use MyApp::Callback; use Params::CallbackRequest; my $cb_request = Params::Callback->new( cb_classes => ); my %params = ('myCallbacker|calc_time_cb' => 1); $cb_request->request(\%params); print "The time is $params{my_time} "; Requirements: · Perl


Params::CallbackRequest Related Software