| 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"} ||= {}
MC/DC0%0/1
$args{"type"} ||= {}
$args{"type"}
Truth table50%1/2
A
A= $args{"type"}
| |||||||||||||
| 17 | 5 | ▶ | $args{class} ||= "Test::MockObject::Chain"; | ||||||||||
|
Condition50%1/2
$args{"class"} ||= "Test::MockObject::Chain"
MC/DC0%0/1
$args{"class"} ||= "Test::MockObject::Chain"
$args{"class"}
Truth table50%1/2
A
A= $args{"class"}
| |||||||||||||
| 18 | |||||||||||||
| 19 | 5 | ▶ | my $object = $args{object} || bless $args{type}, $args{class}; | ||||||||||
|
Condition50%1/2
$args{'object'} || bless($args{'type'}, $args{'class'})
MC/DC0%0/1
$args{'object'} || bless($args{'type'}, $args{'class'})
$args{'object'}
Truth table50%1/2
A
A= $args{'object'}
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 40 | 7 | ▶ | if(want('OBJECT')) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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} ||= {}
MC/DC0%0/1
$self->{"_methods_"}{$method} ||= {}
$self->{"_methods_"}{$method}
Truth table50%1/2
A
A= $self->{"_methods_"}{$method}
| |||||||||||||
| 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__ | ||||||||||||