Mockify/Tools.pm

filter: Statementstmt 100% 64 / 64 Branchbran 100% 22 / 22 Conditioncond 100% 7 / 7 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 5 totaltotal 95.5% 108 / 113 CC 15 SCAR 13.1
CC
15
Cov
100%
ExistsMethod
6.0
Error
5.0
Isa
4.0
CRAP 3.7
« Mockify/Parameter.pm ↑ Summary Mockify/ReturnValue.pm »
1 package Test::Mockify::Tools;
2 26 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 26 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 26 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 26 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 26 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 26 our @EXPORT_OK = qw (
9 Error
10 ExistsMethod
11 IsValid
12 LoadPackage
13 Isa
14 );
15  
16 #------------------------------------------------------------------------
17 116 ▶sub LoadPackage {
Subroutine LoadPackage: called CC=1 SCAR=0.0
Pod undocumented
18 116 my ($Package) = @_;
19  
20 116 my $PackageFileName = join( '/', split /::/sm, $Package ); ## no critic (ProhibitNoisyQuotes)
21 116 load("$PackageFileName.pm");
22 116 return;
23 }
24 #------------------------------------------------------------------------
25 68 ▶sub IsValid {
Subroutine IsValid: called CC=3 SCAR=11.0
Pod undocumented
26 68 my ($Value) = @_;
27  
28 68 my $IsValid = 0;
29 68 ▶ if( defined($Value) && $Value ne '' ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Value and $Value ne "") 62 6 68
Condition100%3/3
defined $Value and $Value ne ""
!ll&&!rl&&r
3362
MC/DC100%2/2
defined $Value and $Value ne ""
defined $Value $Value ne ""
Truth table100%3/3
A and B
A= defined $ValueB= $Value ne ""
ABresult
0X0
100
111
30 62 $IsValid = 1;
31 }
32 68 return $IsValid;
33 }
34 #------------------------------------------------------------------------
35 128 ▶sub ExistsMethod {
Subroutine ExistsMethod: called CC=6 SCAR=17.9
Pod undocumented
36 128 my ( $PathOrObject, $MethodName, $hAdditionalInfo ) = @_;
37  
38 128 ▶ $hAdditionalInfo //= {};
Condition100%2/2
$hAdditionalInfo //= {}
l!l
18110
MC/DC100%1/1
$hAdditionalInfo //= {}
$hAdditionalInfo
Truth table100%2/2
A
A= $hAdditionalInfo
Aresult
11
00
39 128 ▶ Error('Path or Object is needed') unless defined $PathOrObject;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PathOrObject 1 127 128
40 127 ▶ Error('Method name is needed') unless defined $MethodName;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $MethodName 1 126 127
41 126 ▶ if( not $PathOrObject->can( $MethodName ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($PathOrObject->can($MethodName)) 3 123 126
42 3 ▶ if( IsValid( ref( $PathOrObject ) ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (IsValid(ref $PathOrObject)) 1 2 3
43 1 $PathOrObject = ref( $PathOrObject );
44 }
45 3 Error( $PathOrObject." doesn't have a method like: $MethodName", {'Method' => $MethodName, %{$hAdditionalInfo}});
46 }
47  
48 123 return 1;
49 }
50 #------------------------------------------------------------------------
51 5 ▶sub Isa {
Subroutine Isa: called CC=4 SCAR=13.9
Pod undocumented
52 5 my ($Object, $ClassName) = @_;
53 5 ▶ return 0 unless blessed( $Object );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($Object) 2 3 5
54 3 ▶ return 0 unless $ClassName;
Branch: 1 branch
BranchTrueFalseTotal
unless $ClassName 1 2 3
55 2 my $ResultIsaCheck = $Object->isa( $ClassName );
56 2 ▶ if($ResultIsaCheck eq ''){
Branch: 1 branch
BranchTrueFalseTotal
if ($ResultIsaCheck eq "") 1 1 2
57 1 return 0;
58 }
59 1 return $ResultIsaCheck;
60 }
61 #------------------------------------------------------------------------
62 107 ▶sub Error {
Subroutine Error: called CC=5 SCAR=16.1
Pod undocumented
63 107 my ($Message, $hData) = @_;
64  
65 107 ▶ die('Message is needed')unless(defined $Message);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Message 1 106 107
66 # print hData
67 106 local $Data::Dumper::Terse = 1;
68 106 local $Data::Dumper::Indent = 0;
69 106 local $Data::Dumper::Pair = '='; ## no critic (ProhibitNoisyQuotes)
70 106 local $Data::Dumper::Quotekeys = 0;
71 106 ▶ my $MockedMethod = delete $hData->{'Method'} if defined $hData->{'Method'}; ## no critic (ProhibitConditionalDeclarations)
Branch: 1 branch
BranchTrueFalseTotal
if defined $hData->{"Method"} 6 100 106
72 106 ▶ $MockedMethod //= '-no method set-';
Condition100%2/2
$MockedMethod //= "-no method set-"
l!l
8818
MC/DC100%1/1
$MockedMethod //= "-no method set-"
$MockedMethod
Truth table100%2/2
A
A= $MockedMethod
Aresult
11
00
73 106 my $DumpedData = Dumper($hData);
74 # print Callerstack
75 106 my $CallerStack = '';
76 106 my $CallerStackPosition = 1; # 0 would be this function
77 106 ▶ while (my @Caller = caller($CallerStackPosition++) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@Caller) = caller $CallerStackPosition++) 1039 106 1145
78 1039 my $FileName = $Caller[1];
79 1039 my $LineNumber = $Caller[2];
80 1039 my $FunctionName = $Caller[3];
81 1039 $CallerStack .= sprintf(
82 "%s,%s(line %s)\n",
83 $FunctionName,
84 $FileName,
85 $LineNumber,
86 );
87  
88 }
89 # If the last element is a newline, the "at Xxxx.pm line XX" will not be printed
90 106 my $ErrorOutput = sprintf(
91 "%s:\nMockedMethod: %s\nData:%s\n%s\n",
92 $Message,
93 $MockedMethod,
94 $DumpedData,
95 $CallerStack,
96 );
97  
98 106 die($ErrorOutput);
99 }
100  
101 26 1;
« Mockify/Parameter.pm ↑ Summary Mockify/ReturnValue.pm »