line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mockify::Tools; |
2
|
7
|
|
|
7
|
|
84142
|
use Module::Load; |
|
7
|
|
|
|
|
5037
|
|
|
7
|
|
|
|
|
31
|
|
3
|
7
|
|
|
7
|
|
236
|
use strict; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
92
|
|
4
|
7
|
|
|
7
|
|
3523
|
use Data::Dumper; |
|
7
|
|
|
|
|
42438
|
|
|
7
|
|
|
|
|
346
|
|
5
|
7
|
|
|
7
|
|
37
|
use Scalar::Util qw( blessed ); |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
402
|
|
6
|
7
|
|
|
7
|
|
27
|
use base qw( Exporter ); |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
2878
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw ( |
8
|
|
|
|
|
|
|
Error |
9
|
|
|
|
|
|
|
ExistsMethod |
10
|
|
|
|
|
|
|
IsValid |
11
|
|
|
|
|
|
|
LoadPackage |
12
|
|
|
|
|
|
|
Isa |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub LoadPackage { |
17
|
47
|
|
|
47
|
0
|
1659
|
my ($Package) = @_; |
18
|
|
|
|
|
|
|
|
19
|
47
|
|
|
|
|
156
|
my $PackageFileName = join( '/', split /::/, $Package ) . '.pm'; |
20
|
47
|
|
|
|
|
104
|
load($PackageFileName); |
21
|
47
|
|
|
|
|
1595
|
return; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub IsValid { |
25
|
41
|
|
|
41
|
0
|
424
|
my ($Value) = @_; |
26
|
|
|
|
|
|
|
|
27
|
41
|
|
|
|
|
31
|
my $IsValid = 0; |
28
|
41
|
100
|
100
|
|
|
156
|
if( defined($Value) && $Value ne '' ){ |
29
|
30
|
|
|
|
|
26
|
$IsValid = 1; |
30
|
|
|
|
|
|
|
} |
31
|
41
|
|
|
|
|
126
|
return $IsValid; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub ExistsMethod { |
35
|
47
|
|
|
47
|
0
|
828
|
my ( $PathOrObject, $MethodName ) = @_; |
36
|
|
|
|
|
|
|
|
37
|
47
|
100
|
|
|
|
81
|
Error('Path or Object is needed') unless defined $PathOrObject; |
38
|
46
|
100
|
|
|
|
63
|
Error('Method name is needed') unless defined $MethodName; |
39
|
45
|
100
|
|
|
|
186
|
if( not $PathOrObject->can( $MethodName ) ){ |
40
|
3
|
100
|
|
|
|
9
|
if( IsValid( ref( $PathOrObject ) ) ){ |
41
|
1
|
|
|
|
|
2
|
$PathOrObject = ref( $PathOrObject ); |
42
|
|
|
|
|
|
|
} |
43
|
3
|
|
|
|
|
14
|
Error( $PathOrObject." donsn't have a method like: $MethodName", {'Method' => $MethodName}); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
42
|
|
|
|
|
66
|
return 1; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub Isa { |
50
|
10
|
|
|
10
|
0
|
303
|
my ($Object, $ClassName) = @_; |
51
|
10
|
100
|
|
|
|
56
|
return 0 unless blessed( $Object ); |
52
|
8
|
|
|
|
|
36
|
my $ResultIsaCheck = $Object->isa( $ClassName ); |
53
|
8
|
100
|
|
|
|
17
|
if($ResultIsaCheck eq ''){ |
54
|
3
|
|
|
|
|
14
|
return 0; |
55
|
|
|
|
|
|
|
} |
56
|
5
|
|
|
|
|
18
|
return $ResultIsaCheck; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub Error { |
60
|
33
|
|
|
33
|
0
|
1625
|
my ($Message, $hData) = @_; |
61
|
|
|
|
|
|
|
|
62
|
33
|
100
|
|
|
|
65
|
die('Message is needed')unless(defined $Message); |
63
|
|
|
|
|
|
|
|
64
|
32
|
|
|
|
|
34
|
local $Data::Dumper::Terse = 1; |
65
|
32
|
|
|
|
|
30
|
local $Data::Dumper::Indent = 0; |
66
|
32
|
|
|
|
|
28
|
local $Data::Dumper::Pair = '='; |
67
|
32
|
|
|
|
|
25
|
local $Data::Dumper::Quotekeys = 0; |
68
|
32
|
100
|
|
|
|
73
|
my $MockedMethod = delete $hData->{'Method'} if defined $hData->{'Method'}; |
69
|
32
|
|
100
|
|
|
56
|
$MockedMethod //= '-not set-'; |
70
|
32
|
|
|
|
|
78
|
my $DumpedData = Dumper($hData); |
71
|
|
|
|
|
|
|
|
72
|
32
|
|
|
|
|
1548
|
my $CallerStack = ''; |
73
|
32
|
|
|
|
|
34
|
my $CallerStackPosition = 1; |
74
|
32
|
|
|
|
|
214
|
while (my @Caller = caller($CallerStackPosition++) ) { |
75
|
359
|
|
|
|
|
637
|
my $FileName = $Caller[1]; |
76
|
359
|
|
|
|
|
210
|
my $LineNumber = $Caller[2]; |
77
|
359
|
|
|
|
|
220
|
my $FunctionName = $Caller[3]; |
78
|
359
|
|
|
|
|
1978
|
$CallerStack .= sprintf( |
79
|
|
|
|
|
|
|
"%s,%s(line %s)\n", |
80
|
|
|
|
|
|
|
$FunctionName, |
81
|
|
|
|
|
|
|
$FileName, |
82
|
|
|
|
|
|
|
$LineNumber, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
32
|
|
|
|
|
186
|
my $ErrorOutput = sprintf( |
88
|
|
|
|
|
|
|
"%s:\nMockedMethod: %s\nData:%s\n%s\n", |
89
|
|
|
|
|
|
|
$Message, |
90
|
|
|
|
|
|
|
$MockedMethod, |
91
|
|
|
|
|
|
|
$DumpedData, |
92
|
|
|
|
|
|
|
$CallerStack, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
32
|
|
|
|
|
257
|
die($ErrorOutput); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|