File Coverage

blib/lib/RPC/ExtDirect/Event.pm
Criterion Covered Total %
statement 32 33 96.9
branch 9 10 90.0
condition n/a
subroutine 7 8 87.5
pod 3 3 100.0
total 51 54 94.4


line stmt bran cond sub pod time code
1             package RPC::ExtDirect::Event;
2              
3 13     13   2994 use strict;
  13         15  
  13         283  
4 13     13   36 use warnings;
  13         14  
  13         264  
5 13     13   48 no warnings 'uninitialized'; ## no critic
  13         14  
  13         296  
6              
7 13     13   43 use Carp;
  13         13  
  13         1253  
8              
9 13     13   773 use RPC::ExtDirect::Util::Accessor;
  13         16  
  13         2801  
10              
11             ### PUBLIC CLASS METHOD (CONSTRUCTOR) ###
12             #
13             # Initialize a new Event instance
14             #
15              
16             sub new {
17 18     18 1 1878 my $class = shift;
18            
19             # Allow passing either ordered parameters, or hashref,
20             # or even a hash. This is to allow Mooseish and other
21             # popular invocation patterns without having to pile on
22             # argument converters or doing some other nonsense.
23 18         15 my ($name, $data);
24            
25 18 100       49 if ( @_ == 1 ) {
    100          
    50          
26 2 100       6 if ( 'HASH' eq ref $_[0] ) {
27 1         2 $name = $_[0]->{name};
28 1         1 $data = $_[0]->{data};
29             }
30             else {
31 1         2 $name = $_[0];
32             }
33             }
34             elsif ( @_ == 2 ) {
35 14         12 $name = $_[0];
36 14         15 $data = $_[1];
37             }
38             elsif ( @_ % 2 == 0 ) {
39 2         4 my %arg = @_;
40            
41 2         3 $name = $arg{name};
42 2         3 $data = $arg{data};
43             }
44              
45 18 100       510 croak "Ext.Direct Event name is required"
46             unless defined $name;
47              
48 17         41 my $self = bless { name => $name, data => $data }, $class;
49              
50 17         48 return $self;
51             }
52              
53             ### PUBLIC INSTANCE METHOD ###
54             #
55             # A stub for duck typing. Does nothing, returns failure.
56             #
57              
58 0     0 1 0 sub run { !1 }
59              
60             ### PUBLIC INSTANCE METHOD ###
61             #
62             # Returns hashref with Event data. Named so for compatibility with
63             # Exceptions and Requests.
64             #
65              
66             sub result {
67 17     17 1 4971 my ($self) = @_;
68              
69             return {
70 17         409 type => 'event',
71             name => $self->name,
72             data => $self->data,
73             };
74             }
75              
76             ### PUBLIC INSTANCE METHODS ###
77             #
78             # Simple read-write accessors
79             #
80              
81             RPC::ExtDirect::Util::Accessor::mk_accessors(
82             simple => [qw/ name data /],
83             );
84              
85             1;