line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mockify::Tools; |
2
|
26
|
|
|
26
|
|
373485
|
use Module::Load; |
|
26
|
|
|
|
|
26687
|
|
|
26
|
|
|
|
|
145
|
|
3
|
26
|
|
|
26
|
|
1182
|
use strict; |
|
26
|
|
|
|
|
50
|
|
|
26
|
|
|
|
|
433
|
|
4
|
26
|
|
|
26
|
|
113
|
use warnings; |
|
26
|
|
|
|
|
44
|
|
|
26
|
|
|
|
|
562
|
|
5
|
26
|
|
|
26
|
|
14376
|
use Data::Dumper; |
|
26
|
|
|
|
|
163427
|
|
|
26
|
|
|
|
|
1767
|
|
6
|
26
|
|
|
26
|
|
201
|
use Scalar::Util qw( blessed ); |
|
26
|
|
|
|
|
47
|
|
|
26
|
|
|
|
|
1229
|
|
7
|
26
|
|
|
26
|
|
158
|
use base qw( Exporter ); |
|
26
|
|
|
|
|
53
|
|
|
26
|
|
|
|
|
13926
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw ( |
9
|
|
|
|
|
|
|
Error |
10
|
|
|
|
|
|
|
ExistsMethod |
11
|
|
|
|
|
|
|
IsValid |
12
|
|
|
|
|
|
|
LoadPackage |
13
|
|
|
|
|
|
|
Isa |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
17
|
|
|
|
|
|
|
sub LoadPackage { |
18
|
116
|
|
|
116
|
0
|
2485
|
my ($Package) = @_; |
19
|
|
|
|
|
|
|
|
20
|
116
|
|
|
|
|
490
|
my $PackageFileName = join( '/', split /::/sm, $Package ); ## no critic (ProhibitNoisyQuotes) |
21
|
116
|
|
|
|
|
610
|
load("$PackageFileName.pm"); |
22
|
116
|
|
|
|
|
14875
|
return; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
25
|
|
|
|
|
|
|
sub IsValid { |
26
|
68
|
|
|
68
|
0
|
748
|
my ($Value) = @_; |
27
|
|
|
|
|
|
|
|
28
|
68
|
|
|
|
|
104
|
my $IsValid = 0; |
29
|
68
|
100
|
100
|
|
|
327
|
if( defined($Value) && $Value ne '' ){ |
30
|
62
|
|
|
|
|
126
|
$IsValid = 1; |
31
|
|
|
|
|
|
|
} |
32
|
68
|
|
|
|
|
255
|
return $IsValid; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
35
|
|
|
|
|
|
|
sub ExistsMethod { |
36
|
128
|
|
|
128
|
0
|
1631
|
my ( $PathOrObject, $MethodName, $hAdditionalInfo ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
128
|
|
100
|
|
|
465
|
$hAdditionalInfo //= {}; |
39
|
128
|
100
|
|
|
|
271
|
Error('Path or Object is needed') unless defined $PathOrObject; |
40
|
127
|
100
|
|
|
|
240
|
Error('Method name is needed') unless defined $MethodName; |
41
|
126
|
100
|
|
|
|
610
|
if( not $PathOrObject->can( $MethodName ) ){ |
42
|
3
|
100
|
|
|
|
12
|
if( IsValid( ref( $PathOrObject ) ) ){ |
43
|
1
|
|
|
|
|
5
|
$PathOrObject = ref( $PathOrObject ); |
44
|
|
|
|
|
|
|
} |
45
|
3
|
|
|
|
|
14
|
Error( $PathOrObject." doesn't have a method like: $MethodName", {'Method' => $MethodName, %{$hAdditionalInfo}}); |
|
3
|
|
|
|
|
19
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
123
|
|
|
|
|
299
|
return 1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
51
|
|
|
|
|
|
|
sub Isa { |
52
|
5
|
|
|
5
|
0
|
791
|
my ($Object, $ClassName) = @_; |
53
|
5
|
100
|
|
|
|
29
|
return 0 unless blessed( $Object ); |
54
|
3
|
100
|
|
|
|
14
|
return 0 unless $ClassName; |
55
|
2
|
|
|
|
|
17
|
my $ResultIsaCheck = $Object->isa( $ClassName ); |
56
|
2
|
100
|
|
|
|
9
|
if($ResultIsaCheck eq ''){ |
57
|
1
|
|
|
|
|
5
|
return 0; |
58
|
|
|
|
|
|
|
} |
59
|
1
|
|
|
|
|
11
|
return $ResultIsaCheck; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
62
|
|
|
|
|
|
|
sub Error { |
63
|
107
|
|
|
107
|
0
|
4429
|
my ($Message, $hData) = @_; |
64
|
|
|
|
|
|
|
|
65
|
107
|
100
|
|
|
|
265
|
die('Message is needed')unless(defined $Message); |
66
|
|
|
|
|
|
|
# print hData |
67
|
106
|
|
|
|
|
196
|
local $Data::Dumper::Terse = 1; |
68
|
106
|
|
|
|
|
176
|
local $Data::Dumper::Indent = 0; |
69
|
106
|
|
|
|
|
166
|
local $Data::Dumper::Pair = '='; ## no critic (ProhibitNoisyQuotes) |
70
|
106
|
|
|
|
|
154
|
local $Data::Dumper::Quotekeys = 0; |
71
|
106
|
100
|
|
|
|
259
|
my $MockedMethod = delete $hData->{'Method'} if defined $hData->{'Method'}; ## no critic (ProhibitConditionalDeclarations) |
72
|
106
|
|
100
|
|
|
264
|
$MockedMethod //= '-no method set-'; |
73
|
106
|
|
|
|
|
306
|
my $DumpedData = Dumper($hData); |
74
|
|
|
|
|
|
|
# print Callerstack |
75
|
106
|
|
|
|
|
5032
|
my $CallerStack = ''; |
76
|
106
|
|
|
|
|
150
|
my $CallerStackPosition = 1; # 0 would be this function |
77
|
106
|
|
|
|
|
608
|
while (my @Caller = caller($CallerStackPosition++) ) { |
78
|
1039
|
|
|
|
|
5122
|
my $FileName = $Caller[1]; |
79
|
1039
|
|
|
|
|
1052
|
my $LineNumber = $Caller[2]; |
80
|
1039
|
|
|
|
|
1073
|
my $FunctionName = $Caller[3]; |
81
|
1039
|
|
|
|
|
5029
|
$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
|
|
|
|
|
1083
|
my $ErrorOutput = sprintf( |
91
|
|
|
|
|
|
|
"%s:\nMockedMethod: %s\nData:%s\n%s\n", |
92
|
|
|
|
|
|
|
$Message, |
93
|
|
|
|
|
|
|
$MockedMethod, |
94
|
|
|
|
|
|
|
$DumpedData, |
95
|
|
|
|
|
|
|
$CallerStack, |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
|
98
|
106
|
|
|
|
|
968
|
die($ErrorOutput); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |