| 1 | package Test::Mock::Simple; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.008008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | our $VERSION = '0.10'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | my $allow_new_methods = 0; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 6 | my $package = shift; | |||||||||||||||||||||||||||
| 13 | 6 | ▶ | my $class = ref($package) || $package; | ||||||||||||||||||||||||||
|
Condition66%2/3
ref $package || $package
MC/DC0%0/2
ref $package || $package
ref $package
$package
Truth table66%2/3
A || B
A= ref $packageB= $package
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 6 | my $self = {@_}; | |||||||||||||||||||||||||||
| 16 | 6 | bless($self, $class); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 6 | ▶ | if (!$self->{module}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 1 | require Carp; | |||||||||||||||||||||||||||
| 20 | 1 | Carp::croak("No module name provided to mock"); | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 5 | my $module_location; | |||||||||||||||||||||||||||
| 24 | 5 | ▶ | if ($self->{module_location}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 1 | $module_location = $self->{module_location}; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | else { | ||||||||||||||||||||||||||||
| 28 | 4 | $module_location = $self->{module} . '.pm'; | |||||||||||||||||||||||||||
| 29 | 4 | $module_location =~ s/::/\//g; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 5 | ▶ | if ($self->{no_load}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | $INC{$module_location} = 1; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | else { | ||||||||||||||||||||||||||||
| 36 | 5 | require $module_location; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 5 | ▶ | $allow_new_methods = 1 if $self->{allow_new_methods} || $self->{no_load}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"allow_new_methods"} or $self->{"no_load"}
MC/DC50%1/2
$self->{"allow_new_methods"} or $self->{"no_load"}
$self->{"allow_new_methods"}
$self->{"no_load"}
Truth table66%2/3
A or B
A= $self->{"allow_new_methods"}B= $self->{"no_load"}
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 5 | return $self; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 8 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 46 | 8 | my $name = shift; | |||||||||||||||||||||||||||
| 47 | 8 | my $sub = shift; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 8 | ▶ | return if $ENV{TEST_MOCK_SIMPLE_DISABLE}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 8 | ▶ | if (!$name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 1 | require Carp; | |||||||||||||||||||||||||||
| 53 | 1 | Carp::croak("No method name provided to mock"); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 7 | ▶ | if (!$sub) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 1 | require Carp; | |||||||||||||||||||||||||||
| 57 | 1 | Carp::croak("No sub ref provided to mock"); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 6 | ▶ | if (!$allow_new_methods) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | die("Module (" . $self->{module} . ") does not have a method named '$name'\n") | ||||||||||||||||||||||||||||
| 62 | 2 | ▶ | unless $self->{module}->can($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||
| 66 | 3 | ▶ | no strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | 3 | ▶ | no warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 5 | *{$self->{module} . '::' . $name} = $sub; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 3 | 1; | |||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||