ExtDirect/Event.pm

filter: Statementstmt 97.1% 34 / 35 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 3 / 3 totaltotal 94.6% 53 / 56 CC 6 SCAR 12.2
CC
6
Cov
96%
new
6.0
run
2.0
BEGIN
1.0
CRAP 3.4
« ExtDirect/API/Hook.pm ↑ Summary ExtDirect/API/Action.pm »
1 package RPC::ExtDirect::Event;
2  
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶no warnings 'uninitialized'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 13 ▶use RPC::ExtDirect::Util::Accessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 ### PUBLIC CLASS METHOD (CONSTRUCTOR) ###
12 #
13 # Initialize a new Event instance
14 #
15  
16 sub new {
17 18 ▶ my $class = shift;
Subroutine new: called CC=6 SCAR=17.9
Pod documented
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 my ($name, $data);
24
25 18 ▶ if ( @_ == 1 ) {
Branch: 3 branches
BranchTrueFalseTotal
if (@_ == 1) { } 2 16 18
elsif (@_ == 2) { } 14 2 16
elsif (@_ % 2 == 0) { } 2 0 2
26 2 ▶ if ( 'HASH' eq ref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('HASH' eq ref $_[0]) { } 1 1 2
27 1 $name = $_[0]->{name};
28 1 $data = $_[0]->{data};
29 }
30 else {
31 1 $name = $_[0];
32 }
33 }
34 elsif ( @_ == 2 ) {
35 14 $name = $_[0];
36 14 $data = $_[1];
37 }
38 elsif ( @_ % 2 == 0 ) {
39 2 my %arg = @_;
40
41 2 $name = $arg{name};
42 2 $data = $arg{data};
43 }
44  
45 18 ▶ croak "Ext.Direct Event name is required"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 17 18
46 unless defined $name;
47  
48 17 my $self = bless { name => $name, data => $data }, $class;
49  
50 17 return $self;
51 }
52  
53 ### PUBLIC INSTANCE METHOD ###
54 #
55 # A stub for duck typing. Does nothing, returns failure.
56 #
57  
58 0 ▶sub run { !1 }
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
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 ▶ my ($self) = @_;
Subroutine result: called CC=1 SCAR=0.0
Pod documented
68  
69 return {
70 17 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 13 RPC::ExtDirect::Util::Accessor::mk_accessors(
82 simple => [qw/ name data /],
83 );
84  
85 13 1;
« ExtDirect/API/Hook.pm ↑ Summary ExtDirect/API/Action.pm »