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

NAME

Froody::Dispatch - Easily call Froody Methods

SYNOPSIS

  use Froody::Dispatch;
  my $dispatcher = Froody::Dispatch->new();
  my $response = $dispatcher->call( "foo.bar.baz",
    fred => "wilma" 
  );

or, as a client:

  $client = Froody::Dispatch->new;

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

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

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

  # alternatively, args can be passed as a hashref:
  $args = { devisor => 1, devidend => 2 }; 
  $rsp = $invoker->invoke($client, '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

parse_cli (@args)

Parses a list of files, urls, modules, method filter expressions, and paths.

What you're able to do:

module

-MModule::Name (or just Module::Name) - request that that module is registered.

path

-Ipath will inject that path into %INC

perl module file name

filename will extract all module names from within the path

method filter

foo.bar.baz will be interpreted as a filter expression.

Returns a hashref of include paths, modules, urls, and filters

config ($args)

Configures the dispatcher. Takes { filters => [], modules => [], urls => [], includes => [] } and ensures that the dispatcher only contains methods that are present in either the modules list or the urls list, and only if those modules match one or more of the filters in the filters list. If the filters list is empty, then all methods will be registered.

add_implementation

Adds an implementation's methods to this dispatcher.

cli_config

Parses arguments with parse_cli, and then calls config with the arguments. This is intended to be used for parsing command line options, and directly creating configuration details

Returns a dispatch object, and the parsed options.

default_repository

DEPRECATED: This is harmful -- you end up with random methods in your namespaces

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.

See config

call_via ($invoker, $method, [@ARGS, $args])

Calls $method with $invoker. If $invoker or $method are not instances of Froody::Invoker and Froody::Method respectively then this method will attempt to discover them in the registered list of endpoints and the method repository.

Returns a Froody::Response object.

add_endpoint( "url" )

Registers all methods from a remote repository within this one.

TODO: add regex filtering of methods.

load_specification ($name, @method_filters)

Load method and errortype specifications from a named endpoint

Instance Methods

get_method( 'full_name', args )

Retrieve a method

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.

render_response( $response )
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.

get_methods ( [@filters] )

Provides a list of Froody::Method objects. Optionally, the methods are filtered by a list of filter patterns. If Froody::Method::config was called with a list of filters, the methods will be pre-filtered by that list. If you wish to override the configured filters, call this method with undef, or use the repository methods directly.

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. The other option is throw which turns all errors into Froody::Error objects which are then immediatly thrown.

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