| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
6
|
|
|
6
|
|
39
|
use strict; |
|
|
6
|
|
|
|
|
11
|
|
|
|
6
|
|
|
|
|
177
|
|
|
2
|
6
|
|
|
6
|
|
26
|
use warnings; |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
288
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Internal value object for the "Unknown::Values" distribution |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Unknown::Values::Instance; |
|
7
|
|
|
|
|
|
|
$Unknown::Values::Instance::VERSION = '0.101'; |
|
8
|
6
|
|
|
6
|
|
35
|
use Carp 'confess'; |
|
|
6
|
|
|
|
|
11
|
|
|
|
6
|
|
|
|
|
328
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
89
|
use 5.01000; |
|
|
6
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
|
|
my @to_overload; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
BEGIN { |
|
14
|
6
|
|
|
6
|
|
114
|
my %to_overload = ( |
|
15
|
|
|
|
|
|
|
sort => [qw{ <=> cmp }], |
|
16
|
|
|
|
|
|
|
compare => [qw{ <= >= < > lt le gt ge == eq != ne}], |
|
17
|
|
|
|
|
|
|
math => [qw{ + - * / ** atan2 cos sin exp log sqrt int abs }], |
|
18
|
|
|
|
|
|
|
string => [qw{ qr x }], |
|
19
|
|
|
|
|
|
|
files => [qw{ <> -X }], |
|
20
|
|
|
|
|
|
|
bits => [qw{ << >> & | ^ ~ }], |
|
21
|
|
|
|
|
|
|
bool => [ 'bool', '!' ], |
|
22
|
|
|
|
|
|
|
dereference => [qw< ${} @{} %{} &{} *{} >], |
|
23
|
|
|
|
|
|
|
nomethod => ['nomethod'], |
|
24
|
|
|
|
|
|
|
); |
|
25
|
6
|
|
|
|
|
83
|
while ( my ( $method, $ops ) = each %to_overload ) { |
|
26
|
54
|
|
|
|
|
578
|
push @to_overload => $_ => $method foreach @$ops; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
6
|
|
|
6
|
|
42
|
use overload @to_overload, '""' => 'to_string'; |
|
|
6
|
|
|
|
|
12
|
|
|
|
6
|
|
|
|
|
78
|
|
|
31
|
|
|
|
|
|
|
my $CORE_UNKNOWN = __PACKAGE__->new; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub to_string { |
|
34
|
6
|
|
|
6
|
0
|
228
|
confess("Attempt to coerce unknown value to a string"); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new { |
|
38
|
15
|
|
|
15
|
0
|
1978
|
my $class = shift; |
|
39
|
15
|
|
|
|
|
37
|
my $unknown = bless {} => $class; |
|
40
|
15
|
|
|
|
|
34
|
return $unknown; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# this helps to prevent some infinite loops |
|
44
|
32
|
|
|
32
|
0
|
452
|
sub bool {$CORE_UNKNOWN} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub compare { |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# this suppresses the "use of unitialized value in sort" warnings |
|
49
|
26
|
50
|
|
26
|
0
|
148
|
wantarray ? () : 0; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub sort { |
|
53
|
26
|
100
|
|
26
|
0
|
103
|
if ( $_[2] ) { return -1 } |
|
|
8
|
100
|
|
|
|
15
|
|
|
54
|
8
|
|
|
|
|
26
|
elsif ( Unknown::Values::is_unknown( $_[1] ) ) { return 0 } # unnecessary? |
|
55
|
10
|
|
|
|
|
21
|
else { return 1 } |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
13
|
|
|
13
|
0
|
12720
|
sub math { confess("Math cannot be performed on unknown values") } |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub dereference { |
|
61
|
0
|
|
|
0
|
0
|
0
|
confess("Dereferencing cannot be performed on unknown values"); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub files { |
|
65
|
0
|
|
|
0
|
0
|
0
|
confess("File operations cannot be performed on unknown values"); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub string { |
|
69
|
0
|
|
|
0
|
0
|
0
|
confess("String operations cannot be performed on unknown values"); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub bits { |
|
73
|
4
|
|
|
4
|
0
|
3512
|
confess("Bit manipulation cannot be performed on unknown values"); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub nomethod { |
|
77
|
0
|
0
|
|
0
|
0
|
|
if ( defined( my $operator = $_[3] ) ) { |
|
78
|
0
|
|
|
|
|
|
confess("'$operator' operations are not allowed with unknown values"); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
else { |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# XXX seems bit manipulation can trigger this |
|
83
|
0
|
|
|
|
|
|
confess("Illegal operation performed on unknown value"); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |