Generic/Object.pm

filter: Statementstmt 92.5% 62 / 67 Branchbran 58.3% 14 / 24 Conditioncond 57.1% 4 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 16 / 16 Podpod 80.0% 4 / 5 totaltotal 81.3% 100 / 123 CC 17 SCAR 12.9
CC
17
Cov
82%
AUTOLOAD
8.0
__package_map
4.0
yield
3.5
CRAP 3.6
« Generic.pm ↑ Summary Generic/Net/SSH2.pm »
1 package POE::Component::Generic::Object;
2 # $Id: Object.pm 762 2011-05-18 19:34:32Z fil $
3  
4 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 21 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use POE::Component::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 21 ▶use Scalar::Util qw( blessed reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 21 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 21 ▶use vars qw($AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 21 our $VERSION = '0.1400';
16  
17 ##################################################
18 # Create the object
19 # $obj_def was sent from Generic::Child->request
20 # $session_id and $package_map come from Generic
21 sub new
22 5 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
23 5 my( $package, $obj_def, $session_id, $package_map ) = @_;
24  
25 my $self = bless {
26 OBJid => $obj_def->{OBJid},
27 session_id => $session_id,
28 package => $obj_def->{package}
29 5 }, $package;
30  
31 5 $self->__package_map( $package_map, $obj_def->{methods} );
32  
33 5 return $self;
34 }
35  
36 ##################################################
37 # $package_map comes from Generic->new
38 # $methods came from the child
39 sub __package_map
40 5 ▶{
Subroutine __package_map: called CC=4 SCAR=13.9
41 5 my( $self, $package_map, $methods ) = @_;
42  
43 5 ▶ unless( $package_map ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($package_map) 4 1 5
44 4 my $c = $package_map = {};
45 4 foreach my $method ( @$methods ) {
46 5 my( $package, $m ) =
47 POE::Component::Generic->__method_map( $method );
48 5 ▶ next unless $m;
Branch: 1 branch
BranchTrueFalseTotal
unless $m 0 5 5
49 5 $c->{$m} = $self->{package};
50 }
51 }
52 5 $self->{package_map} = $package_map;
53 }
54  
55 ##################################################
56 sub AUTOLOAD
57 2 ▶{
Subroutine AUTOLOAD: called CC=7 SCAR=20.7
58 2 my $self = shift;
59 2 my $method = $AUTOLOAD;
60 2 $method =~ s/.*:://;
61  
62 2 ▶ croak "$method not an object method" unless blessed $self;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self) 0 2 2
63 2 ▶ unless( $method =~ /[^A-Z]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($method =~ /[^A-Z]/) 1 1 2
64 1 croak qq( Can't locate object method "$method" via package ")
65 .ref( $self ). qq("); #"
66 }
67
68 1 my $hash = shift;
69 1 ▶ unless( reftype($hash) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::reftype($hash) eq "HASH") 0 1 1
70 0 croak "First argument to $method must be a hashref";
71 }
72  
73 1 ▶ unless( $self->{package_map}{ $method } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"package_map"}{$method}) 0 1 1
74 0 croak qq(Can't locate object method "$method" via package ")
75 .ref( $self ). qq("); #"
76 }
77 1 ▶ $hash->{wantarray} = wantarray() unless (defined($hash->{wantarray}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hash->{"wantarray"} 1 0 1
78  
79 1 ▶ warn "autoload method $method" if ($self->{debug});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 1 1
80
81  
82 1 $self->__request( $method, $hash, @_ );
83 }
84  
85 ##################################################
86 # Add our arguements to the hash
87 sub __request
88 8 ▶{
Subroutine __request: called CC=3 SCAR=11.6
89 8 my( $self, $method, $hash ) = @_;
90  
91 8 ▶ unless( $self->{package_map}{ $method } or $method eq 'DESTROY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"package_map"}{$method} or $method eq "DESTROY") 0 8 8
Condition66%2/3
$self->{"package_map"}{$method} or $method eq "DESTROY"
l!l&&r!l&&!r
350
MC/DC0%0/2
$self->{"package_map"}{$method} or $method eq "DESTROY"
$self->{"package_map"}{$method} $method eq "DESTROY"
Truth table66%2/3
A or B
A= $self->{"package_map"}{$method}B= $method eq "DESTROY"
ABresult
1X1
011
000
92 0 croak "Unknown method $method for package $self->{package}";
93 }
94  
95 8 $hash->{obj} = $self->object_id;
96 8 $hash->{package} = $self->{package};
97  
98 # use ->call() so that $generic->method() happens in order
99 8 return $poe_kernel->call( $self->session_id => '__request2',
100 @_[1 .. $#_] );
101 }
102  
103  
104  
105 ############################################################################
106 # Object methods
107  
108 sub session_id
109 8 ▶{
Subroutine session_id: called CC=1 SCAR=0.0
Pod documented
110 8 shift->{session_id};
111 }
112  
113 sub object_id
114 13 ▶{
Subroutine object_id: called CC=1 SCAR=0.0
Pod documented
115 13 shift->{OBJid};
116 }
117  
118 sub yield
119 1 ▶{
Subroutine yield: called CC=3 SCAR=12.5
Pod documented
120 1 my $self = shift;
121 0 ▶ if( 'HASH' eq (reftype( $_[2] )||'') ) { croak "Second argument must be a hashref" }
Branch: 1 branch
BranchTrueFalseTotal
if ("HASH" eq (builtin::reftype($_[2]) || "")) 0 1 1
Condition50%1/2
builtin::reftype($_[2]) || ''
l!l
01
MC/DC0%0/1
builtin::reftype($_[2]) || ''
builtin::reftype($_[2])
Truth table50%1/2
A
A= builtin::reftype($_[2])
Aresult
11
00
122 1 return $self->__request( @_ );
123 }
124  
125 sub call
126 1 ▶{
Subroutine call: called CC=3 SCAR=12.5
Pod documented
127 1 my $self = shift;
128 0 ▶ if( 'HASH' eq (reftype( $_[2] )||'') ) { croak "Second argument must be a hashref" }
Branch: 1 branch
BranchTrueFalseTotal
if ("HASH" eq (builtin::reftype($_[2]) || "")) 0 1 1
Condition50%1/2
builtin::reftype($_[2]) || ''
l!l
01
MC/DC0%0/1
builtin::reftype($_[2]) || ''
builtin::reftype($_[2])
Truth table50%1/2
A
A= builtin::reftype($_[2])
Aresult
11
00
129 1 return $self->__request( @_);
130 }
131  
132 sub DESTROY
133 5 ▶{
Subroutine DESTROY: called CC=2 SCAR=7.2
134 5 ▶ if (UNIVERSAL::isa($_[0],__PACKAGE__)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_[0], __PACKAGE__)) 5 0 5
135 5 $_[0]->__request( 'DESTROY', {} );
136 }
137 }
138  
139 21 1;
140  
141 __END__
« Generic.pm ↑ Summary Generic/Net/SSH2.pm »