line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Type::Tiny::NumEqu; |
2
|
2
|
|
|
2
|
|
33
|
use 5.008001; |
|
2
|
|
|
|
|
6
|
|
3
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
35
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
157
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
13
|
use parent qw( Type::Tiny ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
9
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } |
|
1
|
|
|
|
|
6
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
5
|
|
|
5
|
1
|
12
|
my $class = shift; |
14
|
|
|
|
|
|
|
|
15
|
5
|
50
|
|
|
|
20
|
my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_; |
|
0
|
|
|
|
|
0
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
_croak "NumEqu type constraints cannot have a parent constraint passed to the constructor" |
18
|
5
|
50
|
|
|
|
17
|
if exists $opts{parent}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
_croak "NumEqu type constraints cannot have a constraint coderef passed to the constructor" |
21
|
5
|
50
|
|
|
|
14
|
if exists $opts{constraint}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
_croak "NumEqu type constraints cannot have a inlining coderef passed to the constructor" |
24
|
5
|
50
|
|
|
|
13
|
if exists $opts{inlined}; |
25
|
|
|
|
|
|
|
|
26
|
5
|
50
|
|
|
|
14
|
_croak "Need to supply value" unless exists $opts{value}; |
27
|
|
|
|
|
|
|
|
28
|
5
|
100
|
|
|
|
12
|
if (defined $opts{value}) { |
29
|
2
|
|
|
2
|
|
396
|
use warnings FATAL => 'numeric'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
968
|
|
30
|
3
|
|
|
|
|
6
|
eval { |
31
|
3
|
|
|
|
|
19
|
$opts{value} = $opts{value} + 0; # numify |
32
|
|
|
|
|
|
|
}; |
33
|
3
|
100
|
|
|
|
11
|
if ($@) { |
34
|
1
|
|
|
|
|
8
|
_croak sprintf("`%s` is not number. NumEqu value must be number.", $opts{value}); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
4
|
|
|
|
|
18
|
return $class->SUPER::new( %opts ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
16
|
|
|
16
|
1
|
5929
|
sub value { $_[0]{value} } |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _build_display_name { |
44
|
4
|
|
|
4
|
|
47
|
my $self = shift; |
45
|
|
|
|
|
|
|
|
46
|
4
|
100
|
|
|
|
7
|
defined $self->value |
47
|
|
|
|
|
|
|
? sprintf( "NumEqu[%s]", $self->value ) |
48
|
|
|
|
|
|
|
: "NumEqu[Undef]"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub has_parent { |
52
|
0
|
|
|
0
|
1
|
0
|
!!0; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
4
|
|
33
|
4
|
1
|
578
|
sub constraint { $_[0]{constraint} ||= $_[0]->_build_constraint } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _build_constraint { |
58
|
4
|
|
|
4
|
|
6
|
my $self = shift; |
59
|
|
|
|
|
|
|
|
60
|
4
|
100
|
|
|
|
10
|
if (defined $self->value) { |
61
|
|
|
|
|
|
|
return sub { |
62
|
0
|
0
|
|
0
|
|
0
|
defined $_ && $_ == $self->value; |
63
|
2
|
|
|
|
|
14
|
}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
|
|
|
|
|
|
return sub { |
67
|
0
|
|
|
0
|
|
0
|
!defined $_; |
68
|
2
|
|
|
|
|
19
|
}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub can_be_inlined { |
73
|
4
|
|
|
4
|
1
|
20
|
!!1; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub inline_check { |
77
|
4
|
|
|
4
|
1
|
16
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
4
|
|
|
|
|
9
|
my $value = $self->value; |
80
|
|
|
|
|
|
|
|
81
|
4
|
|
|
|
|
7
|
my $code; |
82
|
4
|
100
|
|
|
|
10
|
if (defined $value) { |
83
|
2
|
|
|
|
|
8
|
$code = "(defined($_[0]) && $_[0] == $value)"; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else { |
86
|
2
|
|
|
|
|
13
|
$code = "!defined($_[0])"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
4
|
50
|
|
|
|
11
|
return "do { $Type::Tiny::SafePackage $code }" |
90
|
|
|
|
|
|
|
if $Type::Tiny::AvoidCallbacks; ## no critic (Variables::ProhibitPackageVars) |
91
|
4
|
|
|
|
|
22
|
return $code; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
__END__ |