Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Perl Modules

    MasonX::Interp::WithCallbacks 1.18

    Download button

    No screenshots available
    Downloads: 214  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    David E. Wheeler | More programs
    Perl Artistic License / FREE
    April 8th, 2010, 21:19 GMT
    ROOT / Programming / Perl Modules

     Read user reviews (0)  Refer to a friend  Subscribe

    MasonX::Interp::WithCallbacks description

    Mason callback support via Params::CallbackRequest

    MasonX::Interp::WithCallbacks is a Perl module with subclasses HTML::Mason::Interp in order to provide a Mason callback system built on Params::CallbackRequest. 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 request or by specially named keys in the Mason request arguments, and all callbacks are executed at the beginning of a request, just before Mason creates and executes the request component stack.

    This module brings support for a sort of plugin architecture based on Params::CallbackRequest to Mason. Mason then executes code before executing any components. This approach allows you to carry out logical processing of data submitted from a form, to affect the contents of the Mason request arguments (and thus the %ARGS hash in components), and even to redirect or abort the request before Mason handles it.

    Much of the documentation here is based on that in Params::CallbackRequest, although it prefers using HTML form fields for its examples rather than Perl hashes. But see the Params::CallbackRequest documentation for the latest on its interface.

    SYNOPSIS

    In your Mason component:

     % if (exists $ARGS{answer}) {
     < p >< b >Answer: < % $ARGS{answer} % >< /b >< /p >
     % } else {
     < form >
     < p >Enter an epoch time: < input type="text" name="epoch_time" / >< br / >
     < input type="submit" name="myCallbacker|calc_time_cb" value="Calculate" / >
     < /p >
     < /form >
     % }


    In handler.pl:

     use strict;
     use MasonX::Interp::WithCallbacks;

     sub calc_time {
     my $cb = shift;
     my $params = $cb->params;
     my $val = $cb->value;
     $params->{answer} = localtime($val || time);
     }

     my $ah = HTML::Mason::ApacheHandler->new
     ( interp_class => 'MasonX::Interp::WithCallbacks',
     callbacks => [ { cb_key => 'calc_time',
     pkg_key => 'myCallbacker',
     cb => \&calc_time } ]
     );

     sub handler {
     my $r = shift;
     $ah->handle_request($r);
     }


    Or, in a subclass of Params::Callback:

     package MyApp::CallbackHandler;
     use base qw(Params::Callback);
     __PACKAGE__->register_subclass( class_key => 'myCallbacker' );

     sub calc_time : Callback {
     my $self = shift;
     my $params = $self->params;
     my $val = $cb->value;
     $params->{answer} = localtime($val || time);
     }


    And then, in handler.pl:

     # Load order is important here!
     use MyApp::CallbackHandler;
     use MasonX::Interp::WithCallbacks;

     my $ah = HTML::Mason::ApacheHandler->new
     ( interp_class => 'MasonX::Interp::WithCallbacks',
     cb_classes => [qw(myCallbacker)] );

     sub handler {
     my $r = shift;
     $ah->handle_request($r);
     }


    Or, just use MasonX::Interp::WithCallbacks directly:

     use MyApp::CallbackHandler;
     use MasonX::Interp::WithCallbacks;
     my $interp = MasonX::Interp::WithCallbacks->new
     ( cb_classes => [qw(myCallbacker)] );
     $interp->exec($comp, %args);



    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    Mason callback | Perl module | Mason | callback | Params::CallbackRequest

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM