line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
111
|
use 5.008; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
179
|
|
2
|
5
|
|
|
5
|
|
24
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
176
|
|
3
|
5
|
|
|
5
|
|
22
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
287
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Type::Tiny::Wrapped; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
33
|
use Scalar::Util 'weaken'; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
309
|
|
11
|
5
|
|
|
5
|
|
29
|
use Type::Tiny 0.022 (); |
|
5
|
|
|
|
|
107
|
|
|
5
|
|
|
|
|
96
|
|
12
|
5
|
|
|
5
|
|
23
|
use base 'Type::Tiny'; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
4533
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
1
|
23
|
sub wrapper { $_[0]{wrapper} } |
15
|
132
|
|
|
132
|
1
|
544
|
sub wrapped { $_[0]{parent} } |
16
|
75
|
|
|
75
|
1
|
409
|
sub pre_check { $_[0]{wrapper}{pre_check} } |
17
|
20
|
|
|
20
|
1
|
130
|
sub pre_coerce { $_[0]{wrapper}{pre_coerce} } |
18
|
75
|
|
|
75
|
1
|
280
|
sub post_check { $_[0]{wrapper}{post_check} } |
19
|
20
|
|
|
20
|
1
|
162
|
sub post_coerce { $_[0]{wrapper}{post_coerce} } |
20
|
104
|
|
|
104
|
1
|
515
|
sub inlined_pre_check { $_[0]{wrapper}{inlined_pre_check} } |
21
|
7
|
|
|
7
|
1
|
91
|
sub inlined_pre_coerce { $_[0]{wrapper}{inlined_pre_coerce} } |
22
|
29
|
|
|
29
|
1
|
146
|
sub inlined_post_check { $_[0]{wrapper}{inlined_post_check} } |
23
|
27
|
|
|
27
|
1
|
204
|
sub inlined_post_coerce { $_[0]{wrapper}{inlined_post_coerce} } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _build_compiled_check { |
26
|
10
|
|
|
10
|
|
1918
|
my $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
10
|
50
|
|
|
|
77
|
return Eval::TypeTiny::eval_closure( |
29
|
|
|
|
|
|
|
source => sprintf('sub ($) { %s }', $self->inline_check('$_[0]')), |
30
|
|
|
|
|
|
|
description => sprintf("compiled check '%s'", $self), |
31
|
|
|
|
|
|
|
) if $self->can_be_inlined; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
my $pre = $self->pre_check; |
34
|
0
|
|
|
|
|
0
|
my $orig = $self->wrapped->compiled_check(@_); |
35
|
0
|
|
|
|
|
0
|
my $post = $self->post_check; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
0
|
|
|
0
|
return $orig unless $pre || $post; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
0
|
weaken $self; |
40
|
|
|
|
|
|
|
return sub { |
41
|
0
|
|
|
0
|
|
0
|
local $_ = $_[0]; |
42
|
0
|
0
|
0
|
|
|
0
|
return if defined($pre) && !$pre->($self, @_); |
43
|
0
|
0
|
|
|
|
0
|
return if !$orig->(@_); |
44
|
0
|
0
|
0
|
|
|
0
|
return if defined($post) && !$post->($self, @_); |
45
|
0
|
|
|
|
|
0
|
return !!1; |
46
|
0
|
|
|
|
|
0
|
}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _strict_check { |
50
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
51
|
0
|
|
|
|
|
0
|
local $_ = $_[0]; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
my $pre = $self->pre_check; |
54
|
0
|
|
|
|
|
0
|
my $post = $self->post_check; |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
0
|
|
|
0
|
return if defined($pre) && !$pre->($self, @_); |
57
|
0
|
0
|
|
|
|
0
|
return if !$self->wrapped->_strict_check(@_); |
58
|
0
|
0
|
0
|
|
|
0
|
return if defined($post) && !$post->($self, @_); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
return !!1; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub is_subtype_of { |
64
|
3
|
|
|
3
|
1
|
112
|
my $self = shift; |
65
|
3
|
100
|
|
|
|
12
|
$self->wrapper->is_a_type_of(@_) or $self->SUPER::is_subtype_of(@_); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub inline_check { |
69
|
29
|
|
|
29
|
1
|
12878
|
my $self = shift; |
70
|
29
|
|
|
|
|
56
|
local $_ = (my $var = $_[0]); |
71
|
|
|
|
|
|
|
|
72
|
29
|
50
|
|
|
|
96
|
Type::Tiny::_croak('Cannot inline type constraint check for "%s"', $self) |
73
|
|
|
|
|
|
|
unless $self->can_be_inlined; |
74
|
|
|
|
|
|
|
|
75
|
29
|
|
|
|
|
477
|
my @r; |
76
|
29
|
50
|
|
|
|
66
|
if (my $pre = $self->inlined_pre_check) { |
77
|
29
|
|
|
|
|
119
|
push @r, $pre->($self, $var); |
78
|
|
|
|
|
|
|
} |
79
|
29
|
|
|
|
|
134
|
push @r, $self->wrapped->inline_check($var); |
80
|
29
|
50
|
|
|
|
10723
|
if (my $post = $self->inlined_post_check) { |
81
|
0
|
|
|
|
|
0
|
push @r, $post->($self, $var); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
29
|
100
|
|
|
|
52
|
my $r = join " && " => map { /[;{}]/ ? "do { $_ }" : "($_)" } @r; |
|
101
|
|
|
|
|
439
|
|
85
|
29
|
50
|
|
|
|
254
|
return @r==1 ? $r : "($r)"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub can_be_inlined { |
89
|
75
|
|
|
75
|
1
|
11338
|
my $self = shift; |
90
|
75
|
50
|
33
|
|
|
152
|
return if $self->pre_check && ! $self->inlined_pre_check; |
91
|
75
|
50
|
33
|
|
|
161
|
return if $self->post_check && ! $self->inlined_post_check; |
92
|
75
|
|
|
|
|
153
|
return $self->wrapped->can_be_inlined; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |