FlashRemoting.pm

filter: Statementstmt 80.9% 17 / 21 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 69.7% 23 / 33 CC 2 SCAR 8.9
CC
2
Cov
71%
_parse_AMFMethod_attr
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.4
« FlashRemoting/Action/Gateway.pm ↑ Summary
1 package Catalyst::Controller::FlashRemoting;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use base 'Catalyst::Controller';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 __PACKAGE__->mk_accessors(qw/_amf_method/);
7  
8 3 our $VERSION = '0.02';
9  
10 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
11 1 my $self = shift->NEXT::new(@_);
12 1 $self->{_amf_method} = {};
13  
14 1 $self;
15 }
16  
17 1 ▶sub _parse_AMFGateway_attr {
Subroutine _parse_AMFGateway_attr: called CC=1 SCAR=0.0
18 1 my ($self, $c, $name, $value) = @_;
19  
20 1 return ActionClass => 'Catalyst::Controller::FlashRemoting::Action::Gateway',
21 }
22  
23 0 ▶sub _parse_AMFMethod_attr {
Subroutine _parse_AMFMethod_attr: not called CC=2 SCAR=17.9
24 0 my ($self, $c, $name, $value) = @_;
25  
26 0 ▶ my $method = $value || $name;
Condition0%0/3
$value || $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$value || $name
$value $name
Truth table0%0/3
A || B
A= $valueB= $name
ABresult
1X1
011
000
27 0 $self->_amf_method->{ $method } = $self->can($name);
28  
29 0 return 'Private';
30 }
31  
32 =head1 NAME
33  
34 Catalyst::Controller::FlashRemoting - Catalyst controller for Flash Remoting
35  
36 =head1 SYNOPSIS
37  
38 package MyApp::Controller::Gateway;
39 use strict;
40 use warnings;
41 use base qw/Catalyst::Controller::FlashRemoting/;
42
43 sub gateway :Path :AMFGateway { }
44
45 sub echo :AMFMethod {
46 my ($self, $c, $args) = @_;
47
48 return $args;
49 }
50
51 sub sum :AMFMethod('sum') {
52 my ($self, $c, $args) = @_;
53
54 return $args->[0] + $args->[1];
55 }
56  
57 =head1 DESCRIPTION
58  
59 Catalyst::Controller::FlashRemoting is a Catalyst controller that provide easy interface for Flash Remoting.
60  
61 Flash Remoting is RPC subsystem and that use AMF (Action Message Format) as message body format.
62  
63 =head1 USAGE
64  
65 At first, you need api gateway (endpoint) controller. Add AMFGateway attribute to catalyst action for that.
66  
67 sub gateway :Local :AMFGateway { }
68  
69 If you write above code in Root controller, then 'http://localhost:3000/gateway' is AMF Gateway url.
70  
71 To use this gateway, write actionscript3 like this:
72  
73 var nc:NecConnection = new NetConnection();
74 nc.connect("http://localhost:3000/gateway");
75  
76 Second, you need create some methods.
77  
78 sub echo :AMFMethod {
79 my ($self, $c, $args) = @_;
80 return $args;
81 }
82
83 sub sum :AMFMethod('sum') {
84 my ($self, $c, $args) = @_;
85
86 return $args->[0] + $args->[1];
87 }
88  
89 'echo' is echoback method that just return same object to request, and 'sum' method sum up two arguments and return the result.
90  
91 To call these methods, write actionscript3 like this:
92  
93 nc.call("echo", responder, "foo bar"); // result "foo bar"
94 nc.call("sum", responder, 1, 2); // result 3
95  
96 responder is actionscript3's Responder object. see flex/flash docs for detail.
97  
98 =head1 ACTION ATTRIBUTES
99  
100 =head2 AMFGateway
101  
102 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.
103  
104 =head2 AMFMethod($method_name)
105  
106 This attribute makes the controller to act as AMF Method. This is called from AMFGateway, and don't have to be catalyst controller.
107  
108 $method_name argument is optional. When no $method_name passed, the actual method name is used as amf method name.
109  
110 =head1 METHODS
111  
112 =head2 new
113  
114 =head2 _parse_AMFGateway_attr
115  
116 =head2 _parse_AMFMethod_attr
117  
118 =head1 SEE ALSO
119  
120 L<Data::AMF>, L<Data::AMF::Packet>.
121  
122 =head1 AUTHOR
123  
124 Daisuke Murase <typester@cpan.org>
125  
126 =head1 COPYRIGHT
127  
128 This program is free software; you can redistribute
129 it and/or modify it under the same terms as Perl itself.
130  
131 The full text of the license can be found in the
132 LICENSE file included with this module.
133  
134 =cut
135  
136 3 1;
« FlashRemoting/Action/Gateway.pm ↑ Summary