Catalyst::Controller::FlashRemoting - Catalyst controller for Flash Remoting


Catalyst-Controller-FlashRemoting documentation Contained in the Catalyst-Controller-FlashRemoting distribution.

Index


Code Index:

NAME

Top

Catalyst::Controller::FlashRemoting - Catalyst controller for Flash Remoting

SYNOPSIS

Top

    package MyApp::Controller::Gateway;
    use strict;
    use warnings;
    use base qw/Catalyst::Controller::FlashRemoting/;

    sub gateway :Path :AMFGateway { }

    sub echo :AMFMethod {
        my ($self, $c, $args) = @_;

        return $args;
    }

    sub sum :AMFMethod('sum') {
        my ($self, $c, $args) = @_;

        return $args->[0] + $args->[1];
    }

DESCRIPTION

Top

Catalyst::Controller::FlashRemoting is a Catalyst controller that provide easy interface for Flash Remoting.

Flash Remoting is RPC subsystem and that use AMF (Action Message Format) as message body format.

USAGE

Top

At first, you need api gateway (endpoint) controller. Add AMFGateway attribute to catalyst action for that.

    sub gateway :Local :AMFGateway { }

If you write above code in Root controller, then 'http://localhost:3000/gateway' is AMF Gateway url.

To use this gateway, write actionscript3 like this:

    var nc:NecConnection = new NetConnection();
    nc.connect("http://localhost:3000/gateway");

Second, you need create some methods.

    sub echo :AMFMethod {
        my ($self, $c, $args) = @_;
        return $args;
    }

    sub sum :AMFMethod('sum') {
        my ($self, $c, $args) = @_;

        return $args->[0] + $args->[1];
    }

'echo' is echoback method that just return same object to request, and 'sum' method sum up two arguments and return the result.

To call these methods, write actionscript3 like this:

    nc.call("echo", responder, "foo bar");  // result "foo bar"
    nc.call("sum", responder, 1, 2);        // result 3

responder is actionscript3's Responder object. see flex/flash docs for detail.

ACTION ATTRIBUTES

Top

AMFGateway

This attribute makes the controller to act as AMF Gateway. the controller automatically parse AMF request, dispatch amf method (see AMFMethod attribute below), and serialize response and return.

AMFMethod($method_name)

This attribute makes the controller to act as AMF Method. This is called from AMFGateway, and don't have to be catalyst controller.

$method_name argument is optional. When no $method_name passed, the actual method name is used as amf method name.

METHODS

Top

new

_parse_AMFGateway_attr

_parse_AMFMethod_attr

SEE ALSO

Top

Data::AMF, Data::AMF::Packet.

AUTHOR

Top

Daisuke Murase <typester@cpan.org>

COPYRIGHT

Top


Catalyst-Controller-FlashRemoting documentation Contained in the Catalyst-Controller-FlashRemoting distribution.

package Catalyst::Controller::FlashRemoting;
use strict;
use warnings;
use base 'Catalyst::Controller';

__PACKAGE__->mk_accessors(qw/_amf_method/);

our $VERSION = '0.02';

sub new {
    my $self = shift->NEXT::new(@_);
    $self->{_amf_method} = {};

    $self;
}

sub _parse_AMFGateway_attr {
    my ($self, $c, $name, $value) = @_;

    return ActionClass => 'Catalyst::Controller::FlashRemoting::Action::Gateway',
}

sub _parse_AMFMethod_attr {
    my ($self, $c, $name, $value) = @_;

    my $method = $value || $name;
    $self->_amf_method->{ $method } = $self->can($name);

    return 'Private';
}

1;