| 1 | package Mock::Quick::Util; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Mock::Quick::Method; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | our $CLEAR = 'clear'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 9 | our @EXPORT = qw/ | |||||||||||||||||||||||||||||||||||||||||
| 12 | class_meth | ||||||||||||||||||||||||||||||||||||||||||
| 13 | obj_meth | ||||||||||||||||||||||||||||||||||||||||||
| 14 | alt_meth | ||||||||||||||||||||||||||||||||||||||||||
| 15 | call | ||||||||||||||||||||||||||||||||||||||||||
| 16 | param | ||||||||||||||||||||||||||||||||||||||||||
| 17 | inject | ||||||||||||||||||||||||||||||||||||||||||
| 18 | purge_util | ||||||||||||||||||||||||||||||||||||||||||
| 19 | super | ||||||||||||||||||||||||||||||||||||||||||
| 20 | /; | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 108 | ▶ | sub inject { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inject: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 108 | my ( $package, $name, $code ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 9 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 108 | *{"$package\::$name"} = $code; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 67 | ▶ | sub call { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call: called CC=12 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 67 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 67 | require Mock::Quick::Object::Control; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 67 | my $control = Mock::Quick::Object::Control->new( $self ); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 67 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 67 | my $class = blessed( $self ); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 67 | ▶ | croak "Can't call method on an unblessed reference" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | unless $class; | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 67 | ▶ | if ( $control->strict ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | croak "Can't locate object method \"$name\" in this instance" | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | ▶ | unless exists $self->{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 66 | ▶ | if ( @_ && ref $_[0] && "$_[0]" eq "" . \$CLEAR ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@_ and ref $_[0] and "$_[0]" eq '' . \$Mock::Quick::Util::CLEAR
@_ and ref $_[0]
MC/DC100%3/3
@_ and ref $_[0] and "$_[0]" eq '' . \$Mock::Quick::Util::CLEAR
@_
ref $_[0]
"$_[0]" eq '' . \$Mock::Quick::Util::CLEAR
Truth table100%4/4
A and B and C
A= @_B= ref $_[0]C= "$_[0]" eq '' . \$Mock::Quick::Util::CLEAR
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | delete $self->{ $name }; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 7 | delete $control->metrics->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 59 | $control->metrics->{$name}++; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | return $self->{ $name }->( $self, @_ ) | ||||||||||||||||||||||||||||||||||||||||||
| 53 | if exists( $self->{ $name }) | ||||||||||||||||||||||||||||||||||||||||||
| 54 | && blessed( $self->{ $name }) | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 59 | ▶ | && blessed( $self->{ $name })->isa( 'Mock::Quick::Method' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
exists $self->{$name} and builtin::blessed($self->{$name}) and builtin::blessed($self->{$name})->isa("Mock::Quick::Method")
exists $self->{$name} and builtin::blessed($self->{$name})
MC/DC66%2/3
exists $self->{$name} and builtin::blessed($self->{$name}) and builtin::blessed($self->{$name})->isa("Mock::Quick::Method")
exists $self->{$name}
builtin::blessed($self->{$name})
builtin::blessed($self->{$name})->isa("Mock::Quick::Method")
Truth table75%3/4
A and B and C
A= exists $self->{$name}B= builtin::blessed($self->{$name})C= builtin::blessed($self->{$name})->isa("Mock::Quick::Method")
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 40 | ▶ | return $self->{$name} = shift(@_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($_[0]) and builtin::blessed($_[0])->isa("Mock::Quick::Method")
MC/DC50%1/2
builtin::blessed($_[0]) and builtin::blessed($_[0])->isa("Mock::Quick::Method")
builtin::blessed($_[0])
builtin::blessed($_[0])->isa("Mock::Quick::Method")
Truth table66%2/3
A and B
A= builtin::blessed($_[0])B= builtin::blessed($_[0])->isa("Mock::Quick::Method")
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | if blessed( $_[0] ) && blessed( $_[0] )->isa( 'Mock::Quick::Method' ); | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 39 | param( $self, $name, @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 39 | ▶ | sub param { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
param: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 39 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 39 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 39 | ▶ | $self->{$name} = shift(@_) if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | # Prevent autovivication | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 39 | ▶ | return unless exists( $self->{ $name }); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 18 | return $self->{ $name }; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 9 | ▶ | sub class_meth { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class_meth: called CC=1 SCAR=0.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 9 | my ( $name, $block ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 9 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 14 | ▶ | my $sub = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=10.5
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 14 | ▶ | goto &$block unless blessed( $_[0] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | unshift @_ => ( shift(@_), $name ); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | goto &call; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 9 | }; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 9 | inject( $caller, $name, $sub ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 9 | ▶ | sub obj_meth { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
obj_meth: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 9 | my ( $name, $block ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 9 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 16 | ▶ | my $sub = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 16 | ▶ | goto &$block if blessed( $_[0] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | Carp::croak( "Can't locate object method \"$name\" via package \"$caller\"" ); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 9 | }; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 9 | inject( $caller, $name, $sub ); | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 14 | ▶ | sub alt_meth { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alt_meth: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 14 | my ( $name, %alts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 14 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | croak "You must provide an action for both 'class' and 'obj'" | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 14 | ▶ | unless $alts{class} && $alts{obj}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$alts{"class"} and $alts{"obj"}
MC/DC0%0/2
$alts{"class"} and $alts{"obj"}
$alts{"class"}
$alts{"obj"}
Truth table33%1/3
A and B
A= $alts{"class"}B= $alts{"obj"}
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 33 | ▶ | my $sub = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 33 | ▶ | goto &{ $alts{obj }} if blessed( $_[0] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 12 | goto &{ $alts{ class }}; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 14 | }; | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 14 | inject( $caller, $name, $sub ); | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 26 | ▶ | sub purge_util { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
purge_util: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 26 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 26 | for my $sub ( @EXPORT ) { | |||||||||||||||||||||||||||||||||||||||||
| 117 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 208 | my $ref = \%{"$caller\::"}; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 208 | delete $ref->{ $sub }; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||||||||||||||||