NAME

Froody::Dispatch - Easily call Froody Methods

SYNOPSIS

use Froody::Dispatch;
my $dispatcher = Froody::Dispatch->new();
my $response = $dispatcher->dispatch(
   method => "foo.bar.baz",
   params => { fred => "wilma" },
);

or, as a client:

$client = Froody::Dispatch->new;

# uses reflection to load methods from the server
$client->endpoint( "uri" ); 

# look mah, no arguments!
$rsp = $client->call('service.wibble');

# ok, take some arguments then.
$rsp = $client->call('service.devide', divisor => 1, dividend => 2);

# alternatively, args can be passed as a hashref:
$args = { devisor => 1, devidend => 2 }; 
$rsp = $client->call('service.devide', $args);

DESCRIPTION

This class handles dispatching Froody Methods. It's used both from within the servers where you don't want to have to worry about the little details and as a client.

METHODS

Class Methods

new

Create a new instance of the dispatcher

default_repository

The first time this method is called it creates a default repository by trawling through all loaded modues and checking which are subclasses of Froody::Implementation.

If you're running this in a mod_perl handler you might want to consider calling this method at compile time to preload all the classes.

add_endpoint( "url" )

Registers all methods from a remote repository within this one.

TODO: add regex filtering of methods.

Instance Methods

dispatch( %args )

Causes a dispatch to a froody method to happen. At a minimum you need to pass in a method name:

my $response = Froody::Dispatch->new->dispatch( method => "foo.bar.bob" );

You can also pass in parameters:

my $response = Froody::Dispatch->new->dispatch( 
  method => "foo.bar.bob",
  param  => { wibble => "wobble" },
);

Which repository this class uses and how errors are reported depends on the methods defined below.

cleanup

Subclasses should override this method if there are any cleanup tasks that should be run after

call( 'method', [ args ] )

Call a method (optionally with arguments) and return a Froody::Response::Terse response, as described in Froody::DataFormats. This is a thin wrapper for the ->dispatch() method.

repository

Get/set the repository that we're calling methods on. If this is set to undef (as it is by default) then we will use the default repository (see above.)

error_style

Get/set chained accessor that sets the style of errors that this should use. By default this is response, which causes all errors to be converted into valid responses. Other options are throw which turns all errors into Froody::Error objects which are then immediatly thrown and passthrough which doesn't actually do anything (errors that are thrown continue to be thrown, error responses are returned.)

BUGS

None known.

Please report any bugs you find via the CPAN RT system. http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Froody

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.

SEE ALSO

Froody, Froody::Method