The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Froody::Plugin

SYNOPSIS

  package My::Plugin;
  use base qw( Froody::Plugin );
  
  sub new {
    my ($class, $impl, @args) = @_;
    my $self = $class->SUPER::new($impl, @args);
    $impl->mk_accessors( 'leg_count' );
    return $self;
  }
  
  sub pre_process {
    my ($impl, $method, $params) = @_;
    $impl->leg_count( delete $params->{legs} || 2 );
  }

  ...
  
  package My::Implementation;
  use base qw( Froody::Implementation );
  
  __PACKAGE__->register_plugin('My::Plugin');
  
  sub my_method {
    my ($self, $params) = @_;
    return $self->leg_count()." legs found.\n";
  }

DESCRIPTION

Froody plugins let you extend an implementation and add functionality without scary messing around with superclasses. They have a chance to get involved in the pre_process step of the request, and can add accessors to the importing class and instance.

METHODS

new( plugin class, implementation class, arguments... )
  sub new {
    my ($class, $impl, @args) = @_;
    my $self = $class->SUPER::new($impl, @args);
    $impl->mk_accessors( 'leg_count' );
    return $self;
  }

Constructor, called as a class method. 'implementation class' here is the class doing the requiring of the plugin, and 'arguments' are all the remaining args passed to the require_plugin call.

init( implementation, args )

the place to initialize your object. The return value is ignored.

get_plugin_methods( implementation class )

plugins should override this method to return froody methods provided by the plugin. The methods will then be registered.

pre_process( implementation class, method, params )

This is where your plugin gets to do interesting things to the request. See the docs for pre_process in Froody::Invoker::Implementation for details on what you can do here. Importantly, this is before parameter validation. For instance, a session management plugin could remove a 'session_id' param from the request here, and load a session:

  sub pre_process {
    my ($self, $method, $param) = @_;
    my $session_id = delete $param->{session_id};
    $self->session( $session_id );
  }

and the method signature of the implementation wouldn't need to include it.

Note that the method is called with the first parameter being the implementation class, not the plugin class. If you need access to the plugin object, override plugin_pre_process (see below).

plugin_pre_process(self, implementation class, method, params)

If you need access to your plugin instance, override this method. Its default behaviour (in Froody::Plugin) is to call pre_process, and not pass the plugin instance. Override this method or pre_process.

post_process( implementation, method, args )

By overriding this method, you can preform actions after the implementation has done its work. See the docs for post_process in Froody::Invoker::Implementation for details on what you can do here. The 'args' param here is the hash returned from the implementation, before it is interpolated into the XML by the path walker, so you can change the returned XML, but only within the spec of the API.

plugin_post_process

If you need access to your plugin instance, override this method. Its default behaviour (in Froody::Plugin) is to call post_process, and not pass the plugin instance. Override this method or post_process.

error_handler( implementation, method, args )

By overriding this method, you can preform actions after the implementation has done it's work. See the docs for error_handler in Froody::Invoker::Implementation for details on what you can do here. The 'args' param here is the hash returned from the implementation, before it is interpolated into the XML by the path walker, so you can change the returned XML, but only within the spec of the API.

plugin_error_handler

If you need access to your plugin instance, override this method. Its default behaviour (in Froody::Plugin) is to call error_handler, and not pass the plugin instance. Override this method or error_handler.

AUTHOR

Copyright Fotango 2005. All rights reserved.

Please see the main Froody documentation for details of who has worked on this project.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.