| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Smart::Dispatch::Match; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
BEGIN { |
|
4
|
|
|
|
|
|
|
*_TYPES = $ENV{PERL_SMART_DISPATCH_TYPE_CHECKS}==42 |
|
5
|
|
|
|
|
|
|
? sub () { 1 } |
|
6
|
5
|
50
|
|
7
|
|
143
|
: sub () { 0 }; |
|
7
|
|
|
|
|
|
|
}; |
|
8
|
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
153
|
use 5.010; |
|
|
5
|
|
|
|
|
21
|
|
|
|
5
|
|
|
|
|
209
|
|
|
10
|
5
|
|
|
5
|
|
31
|
use Moo; |
|
|
5
|
|
|
|
|
12
|
|
|
|
5
|
|
|
|
|
43
|
|
|
11
|
5
|
|
|
5
|
|
1757
|
use Carp; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
430
|
|
|
12
|
5
|
|
|
5
|
|
32
|
use if _TYPES, 'MooX::Types::MooseLike::Base', ':all'; |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
44
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
197
|
use namespace::clean; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
54
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
BEGIN { |
|
17
|
5
|
|
|
5
|
|
1623
|
$Smart::Dispatch::Match::AUTHORITY = 'cpan:TOBYINK'; |
|
18
|
5
|
|
|
|
|
216
|
$Smart::Dispatch::Match::VERSION = '0.006'; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use constant { |
|
22
|
5
|
|
|
|
|
992
|
FLAG_HAS_VALUE => 2, |
|
23
|
|
|
|
|
|
|
FLAG_HAS_DISPATCH => 4, |
|
24
|
|
|
|
|
|
|
FLAG_IS_FAILOVER => 8, |
|
25
|
|
|
|
|
|
|
FLAG_IS_UNCONDITIONAL => 16, |
|
26
|
5
|
|
|
5
|
|
37
|
}; |
|
|
5
|
|
|
|
|
15
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use overload |
|
29
|
2
|
|
|
2
|
|
643
|
'&{}' => sub { my $x=shift; sub { $x->conduct_dispatch($_[0]) } }, |
|
|
2
|
|
|
|
|
13
|
|
|
|
2
|
|
|
|
|
9
|
|
|
30
|
|
|
|
|
|
|
'~~' => 'value_matches', |
|
31
|
20
|
|
|
20
|
|
176
|
bool => sub { 1 }, |
|
32
|
5
|
|
|
5
|
|
31
|
; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
95
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has test => ( |
|
35
|
|
|
|
|
|
|
(_TYPES?(isa=>Any()):()), |
|
36
|
|
|
|
|
|
|
is => 'ro', |
|
37
|
|
|
|
|
|
|
required => 1, |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has dispatch => ( |
|
41
|
|
|
|
|
|
|
(_TYPES?(isa=>CodeRef()):()), |
|
42
|
|
|
|
|
|
|
is => 'ro', |
|
43
|
|
|
|
|
|
|
required => 0, |
|
44
|
|
|
|
|
|
|
predicate => 'has_dispatch', |
|
45
|
|
|
|
|
|
|
); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has value => ( |
|
48
|
|
|
|
|
|
|
(_TYPES?(isa=>Any()):()), |
|
49
|
|
|
|
|
|
|
is => 'ro', |
|
50
|
|
|
|
|
|
|
required => 0, |
|
51
|
|
|
|
|
|
|
predicate => 'has_value', |
|
52
|
|
|
|
|
|
|
); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has note => ( |
|
55
|
|
|
|
|
|
|
(_TYPES?(isa=>Str()):()), |
|
56
|
|
|
|
|
|
|
is => 'ro', |
|
57
|
|
|
|
|
|
|
required => 0, |
|
58
|
|
|
|
|
|
|
); |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
has bitflags => ( |
|
61
|
|
|
|
|
|
|
(_TYPES?(isa=>Num()):()), |
|
62
|
|
|
|
|
|
|
is => 'lazy', |
|
63
|
|
|
|
|
|
|
init_arg => undef, |
|
64
|
|
|
|
|
|
|
); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
has is_failover => ( |
|
67
|
|
|
|
|
|
|
(_TYPES?(isa=>Bool()):()), |
|
68
|
|
|
|
|
|
|
is => 'ro', |
|
69
|
|
|
|
|
|
|
required => 1, |
|
70
|
|
|
|
|
|
|
default => sub { 0 }, |
|
71
|
|
|
|
|
|
|
); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
has is_unconditional => ( |
|
74
|
|
|
|
|
|
|
(_TYPES?(isa=>Bool()):()), |
|
75
|
|
|
|
|
|
|
is => 'ro', |
|
76
|
|
|
|
|
|
|
required => 1, |
|
77
|
|
|
|
|
|
|
default => sub { 0 }, |
|
78
|
|
|
|
|
|
|
); |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _build_bitflags |
|
81
|
|
|
|
|
|
|
{ |
|
82
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
|
83
|
0
|
|
|
|
|
0
|
my $rv = 1; |
|
84
|
0
|
0
|
|
|
|
0
|
$rv += FLAG_HAS_VALUE if $self->has_value; |
|
85
|
0
|
0
|
|
|
|
0
|
$rv += FLAG_HAS_DISPATCH if $self->has_dispatch; |
|
86
|
0
|
0
|
|
|
|
0
|
$rv += FLAG_IS_FAILOVER if $self->is_failover; |
|
87
|
0
|
0
|
|
|
|
0
|
$rv += FLAG_IS_UNCONDITIONAL if $self->is_unconditional; |
|
88
|
0
|
|
|
|
|
0
|
return $rv; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub value_matches |
|
92
|
|
|
|
|
|
|
{ |
|
93
|
66
|
|
|
66
|
1
|
1488
|
my ($self, $value) = @_; |
|
94
|
66
|
|
|
|
|
96
|
local $_ = $value; |
|
95
|
5
|
|
|
5
|
|
21799
|
no warnings; # stupid useless warnings below |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
952
|
|
|
96
|
66
|
|
|
|
|
465
|
return ($value ~~ $self->test); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub conduct_dispatch |
|
100
|
|
|
|
|
|
|
{ |
|
101
|
13
|
|
|
13
|
1
|
785
|
my ($self, $value, @args) = @_; |
|
102
|
13
|
|
|
|
|
23
|
local $_ = $value; |
|
103
|
13
|
100
|
|
|
|
62
|
if ($self->has_dispatch) |
|
|
|
50
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
{ |
|
105
|
11
|
|
|
|
|
174
|
return $self->dispatch->($value, @args); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
elsif ($self->has_value) |
|
108
|
|
|
|
|
|
|
{ |
|
109
|
2
|
|
|
|
|
117
|
return $self->value; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
else |
|
112
|
|
|
|
|
|
|
{ |
|
113
|
0
|
|
|
|
|
|
return; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__PACKAGE__ |
|
118
|
|
|
|
|
|
|
__END__ |