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

NAME

Froody::Implementation - define Perl methods to implement Froody::Method

SYNOPSIS

  package MyCompany::PerlMethods::Time;
  use base qw(Froody::Implementation);

  # say what api you're implementing, and what subset of those methods
  # should be handled by perl methods in this class
  sub implements { "MyCompany::API" => "mycompany.timequery.*" }

  use DateTime;
 
  # this is mycompany.timequery.gettime
  sub gettime
  {
     my $self = shift;
     my $args = shift;

     $now = DateTime->now;
     $now->set_time_zone($args->{time_zone}) if $args->{time_zone};
     return $now->datetime;
  }

You may also load plugins to do some of the work for you:

  __PACKAGE__->register_plugin("Froody::Plugin::Sasquatch", shoe_size => 25 );
  
  sub explore {
    my ($self, $params) = @_;
    return $self->find_bigfoot( $params->{shoe_size} );
  }

DESCRIPTION

This class is a simple base class that allows you to quickly and simply provide code for Froody to run when it needs to execute a method.

You can use a plugin if you want some processing for each of the methods (or a large portion of the methods). Typical plugins will perform functions like session management and user authentication (see, for instance, Froody::Plugin::Session and Froody::Plugin::Auth). Plugins have the ability to add accessors to your implementation class and instance, and can perform functions in the 'pre_process' stage of your application. (If you override pre_process yourself, be sure to call $self->SUPER::pre_process for the plugins to work.)

How to write your methods

It's fairly straightforward to write methods for Froody, and is best demonstrated with an example. Imagine we've got a Froody::Method that's been defined like so:

  package PerlService::API;
  use base qw(Froody::API::XML);
  1;
  
  sub xml { <<'XML';
  <spec>
   <methods>
    <method name="perlservice.corelist.released">
      <arguments>
        <argument name="module" type="text" optional="0" />
      </arguments>
      <response>
        <module name="">
          <in version=""></in>
        </module>
      </response>
    </method>
   </methods>
  </spec>
  XML

We are now ready to start writing a class implementing this API:

  package MyCompany::PerlMethods;
  use base qw(Froody::Implementation);
  
  sub implements { "MyCompany::API" => "mycompany.timequery.datetime" }

  sub hello {
    ...
  }

  sub some_get_function :FroodyMethod(get) {
    ...
  }

The methods will be called with two parameters: self and a hashref containing the method arguments. The arguments will have already been pre-processed to verify that they are all there and of the right type, for example (all registerred plugins also have a chance at doing their own pre-processing before the method is called).

Abstract methods

implements()

Should return a hash of

  Namespace => 'method.names.*'

mappings specifying in what modules the given methods are implemented.

METHODS

register_plugin( plugin_class, [ plugin params ] )
  __PACKAGE__->register_plugin("Froody::Plugin::Session", session_class => "My::Session::Class" );
  

Adds a plugin to this class. The first parameter is the classname of the plugin to add, all remaining parameters are passed to the plugin class's constructor, and should be documented in the perldoc for that plugin. See Froody::Plugin about plugins.

BUGS

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