line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mockify::TypeTests; |
2
|
28
|
|
|
28
|
|
460098
|
use strict; |
|
28
|
|
|
|
|
130
|
|
|
28
|
|
|
|
|
784
|
|
3
|
28
|
|
|
28
|
|
136
|
use warnings; |
|
28
|
|
|
|
|
68
|
|
|
28
|
|
|
|
|
893
|
|
4
|
28
|
|
|
28
|
|
175
|
use Scalar::Util qw ( blessed ); |
|
28
|
|
|
|
|
54
|
|
|
28
|
|
|
|
|
1452
|
|
5
|
28
|
|
|
28
|
|
185
|
use base qw( Exporter ); |
|
28
|
|
|
|
|
60
|
|
|
28
|
|
|
|
|
14844
|
|
6
|
|
|
|
|
|
|
our @EXPORT_OK = qw ( |
7
|
|
|
|
|
|
|
IsInteger |
8
|
|
|
|
|
|
|
IsFloat |
9
|
|
|
|
|
|
|
IsString |
10
|
|
|
|
|
|
|
IsArrayReference |
11
|
|
|
|
|
|
|
IsHashReference |
12
|
|
|
|
|
|
|
IsObjectReference |
13
|
|
|
|
|
|
|
IsCodeReference |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
17
|
|
|
|
|
|
|
sub IsInteger { |
18
|
17
|
|
|
17
|
0
|
691
|
my ( $Value ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
17
|
|
|
|
|
28
|
my $IsInteger = 0; |
21
|
17
|
|
|
|
|
24
|
my $Sign = '[-+]?'; # + or - or nothing |
22
|
17
|
100
|
|
|
|
32
|
if( defined $Value ){ |
23
|
16
|
100
|
|
|
|
138
|
if($Value =~ /^$Sign\d+$/sm ) { |
24
|
7
|
|
|
|
|
12
|
$IsInteger = 1; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
17
|
|
|
|
|
81
|
return $IsInteger; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
31
|
|
|
|
|
|
|
sub IsFloat { |
32
|
286
|
|
|
286
|
0
|
1497
|
my ( $Value ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
286
|
|
|
|
|
379
|
my $IsFloat = 0; |
35
|
|
|
|
|
|
|
|
36
|
286
|
|
|
|
|
401
|
my $OptionalSign = '[-+]?'; |
37
|
286
|
|
|
|
|
349
|
my $NumberOptions = '(?=\d|\.\d)\d*(\.\d*)?'; |
38
|
286
|
|
|
|
|
413
|
my $OptionalExponent = '([eE][-+]?\d+)?'; |
39
|
286
|
|
|
|
|
898
|
my $FloatRegex = sprintf('%s%s%s', $OptionalSign, $NumberOptions, $OptionalExponent); |
40
|
|
|
|
|
|
|
|
41
|
286
|
100
|
100
|
|
|
3436
|
if ( defined $Value && $Value =~ /^$FloatRegex$/sm ){ |
42
|
165
|
|
|
|
|
297
|
$IsFloat = 1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
286
|
|
|
|
|
1386
|
return $IsFloat; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
48
|
|
|
|
|
|
|
sub IsString { |
49
|
252
|
|
|
252
|
0
|
1058
|
my ( $Value ) = @_; |
50
|
|
|
|
|
|
|
|
51
|
252
|
|
|
|
|
359
|
my $IsString = 0; |
52
|
|
|
|
|
|
|
|
53
|
252
|
100
|
|
|
|
471
|
if ( defined $Value ){ |
54
|
243
|
50
|
66
|
|
|
982
|
if( $Value =~ /[\w\s]/sm || $Value eq ''){ |
55
|
243
|
|
|
|
|
343
|
$IsString = 1; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
# exclude all "types" |
58
|
243
|
|
|
|
|
420
|
my $ValueType = ref( $Value ); |
59
|
243
|
100
|
66
|
|
|
880
|
if( defined $ValueType && $ValueType ne '' ) { |
60
|
5
|
|
|
|
|
13
|
$IsString = 0; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
252
|
|
|
|
|
956
|
return $IsString; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
67
|
|
|
|
|
|
|
sub IsArrayReference { |
68
|
200
|
|
|
200
|
0
|
890
|
my ( $aValue ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
200
|
|
|
|
|
286
|
my $IsArray = 0; |
71
|
|
|
|
|
|
|
|
72
|
200
|
100
|
|
|
|
467
|
if ( ref($aValue) eq 'ARRAY' ) { |
73
|
19
|
|
|
|
|
34
|
$IsArray = 1; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
200
|
|
|
|
|
520
|
return $IsArray; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
79
|
|
|
|
|
|
|
sub IsHashReference { |
80
|
191
|
|
|
191
|
0
|
1008
|
my ( $hValue ) = @_; |
81
|
|
|
|
|
|
|
|
82
|
191
|
|
|
|
|
310
|
my $IsHash = 0; |
83
|
|
|
|
|
|
|
|
84
|
191
|
100
|
|
|
|
402
|
if ( ref($hValue) eq 'HASH' ) { |
85
|
20
|
|
|
|
|
42
|
$IsHash = 1; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
191
|
|
|
|
|
484
|
return $IsHash; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
91
|
|
|
|
|
|
|
sub IsCodeReference { |
92
|
153
|
|
|
153
|
0
|
1189
|
my ( $hValue ) = @_; |
93
|
|
|
|
|
|
|
|
94
|
153
|
|
|
|
|
191
|
my $IsCode = 0; |
95
|
|
|
|
|
|
|
|
96
|
153
|
100
|
|
|
|
285
|
if ( ref($hValue) eq 'CODE' ) { |
97
|
5
|
|
|
|
|
6
|
$IsCode = 1; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
153
|
|
|
|
|
361
|
return $IsCode; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
103
|
|
|
|
|
|
|
sub IsObjectReference { |
104
|
170
|
|
|
170
|
0
|
944
|
my ( $Value ) = @_; |
105
|
|
|
|
|
|
|
|
106
|
170
|
|
|
|
|
215
|
my $IsObject = 0; |
107
|
|
|
|
|
|
|
|
108
|
170
|
100
|
|
|
|
428
|
if( blessed( $Value ) ) { |
109
|
15
|
|
|
|
|
27
|
$IsObject = 1; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
170
|
|
|
|
|
408
|
return $IsObject; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |