blib/lib/Test/MockObject/Chain.pm

filter: Statementstmt 100% 55 / 55 Branchbran 87.5% 7 / 8 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 92.3% 12 / 13 Podpod n/a totaltotal 88.6% 78 / 88 CC 9 SCAR 9.8
CC
9
Cov
93%
AUTOLOAD
5.0
_new
4.2
_add_method
2.0
CRAP 2.7
↑ Summary
1 package Test::MockObject::Chain;
2  
3 1 ▶use 5.010000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Want;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use vars '$AUTOLOAD';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '1.00';
12  
13 5 ▶sub _new {
Subroutine _new: called CC=4 SCAR=14.3
14 5 shift;
15 5 my %args = @_;
16 5 ▶ $args{type} ||= {};
Condition50%1/2
$args{"type"} ||= {}
l!l
05
MC/DC0%0/1
$args{"type"} ||= {}
$args{"type"}
Truth table50%1/2
A
A= $args{"type"}
Aresult
11
00
17 5 ▶ $args{class} ||= "Test::MockObject::Chain";
Condition50%1/2
$args{"class"} ||= "Test::MockObject::Chain"
l!l
05
MC/DC0%0/1
$args{"class"} ||= "Test::MockObject::Chain"
$args{"class"}
Truth table50%1/2
A
A= $args{"class"}
Aresult
11
00
18  
19 5 ▶ my $object = $args{object} || bless $args{type}, $args{class};
Condition50%1/2
$args{'object'} || bless($args{'type'}, $args{'class'})
l!l
05
MC/DC0%0/1
$args{'object'} || bless($args{'type'}, $args{'class'})
$args{'object'}
Truth table50%1/2
A
A= $args{'object'}
Aresult
11
00
20 5 $object->{_methods_} = {};
21  
22 5 return $object;
23 }
24  
25  
26 17 ▶sub AUTOLOAD: lvalue {
Subroutine AUTOLOAD: called CC=5 SCAR=16.1
27 17 my $self = shift;
28  
29 17 ▶ unless( blessed($self)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($self)) 2 15 17
30 2 $self = $self->_new() ;
31 2 return $self;
32 }
33  
34 15 ( my $method = $AUTOLOAD ) =~ s{.*::}{};
35 15 my @params = @_;
36  
37 15 my $key = $self->_key(\@params);
38  
39 15 ▶ if(not $self->_method_exists( $method, $key ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_method_exists($method, $key)) 7 8 15
40 7 ▶ if(want('OBJECT')) {
Branch: 1 branch
BranchTrueFalseTotal
if (want('OBJECT')) { } 3 4 7
41 3 $self->_add_method($method, \@_, Test::MockObject::Chain->_new() );
42 }
43 else {
44 4 ▶ carp "Attempt to read uninitialised method $method with key $key" unless want('LVALUE');
Branch: 1 branch
BranchTrueFalseTotal
unless want("LVALUE") 0 4 4
45 }
46 }
47  
48 15 $self->{_methods_}->{$method}->{$key};
49  
50 }
51  
52 15 ▶sub _method_exists {
Subroutine _method_exists: called CC=1 SCAR=0.0
53 15 my $self = shift;
54 15 my $method = shift;
55 15 my $key = shift;
56  
57 15 return exists($self->{_methods_}->{$method}->{$key}) ;
58 }
59  
60 15 ▶sub _key {
Subroutine _key: called CC=1 SCAR=0.0
61 15 my $self = shift;
62 15 my $params = shift;
63  
64 15 return join chr(28), @$params;
65 }
66  
67  
68 3 ▶sub _add_method {
Subroutine _add_method: called CC=2 SCAR=7.0
69 3 my $self = shift;
70 3 my $method = shift;
71 3 my $params = shift;
72 3 my $response = shift;
73  
74 3 ▶ $self->{_methods_}->{$method} ||= {};
Condition50%1/2
$self->{"_methods_"}{$method} ||= {}
l!l
30
MC/DC0%0/1
$self->{"_methods_"}{$method} ||= {}
$self->{"_methods_"}{$method}
Truth table50%1/2
A
A= $self->{"_methods_"}{$method}
Aresult
11
00
75 3 $self->{_methods_}->{$method}->{join chr(28),@$params} = $response;
76  
77 3 return $response;
78 }
79  
80  
81 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
82  
83 1 1;
84 __END__
↑ Summary