line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Variable::Strongly::Typed::Code; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
36
|
use version; $VERSION = qv('1.0.0'); |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
50
|
|
4
|
|
|
|
|
|
|
|
5
|
7
|
|
|
7
|
|
510
|
use warnings; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
185
|
|
6
|
7
|
|
|
7
|
|
42
|
use strict; |
|
7
|
|
|
|
|
21
|
|
|
7
|
|
|
|
|
207
|
|
7
|
7
|
|
|
7
|
|
35
|
use Carp; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
435
|
|
8
|
|
|
|
|
|
|
|
9
|
7
|
|
|
7
|
|
43
|
use base qw(Variable::Strongly::Typed); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
1230
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
{ |
12
|
|
|
|
|
|
|
sub new { |
13
|
2
|
|
|
2
|
0
|
6
|
my($class, $symbol, $referent, $type) = @_; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
|
|
7
|
my $self = bless \my($anon_scalar), $class; |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
6
|
my $full_sub_name = $$symbol; |
18
|
2
|
|
|
|
|
17
|
$full_sub_name =~ s/^\*//; |
19
|
7
|
|
|
7
|
|
36
|
my $sub_ref = do { no strict 'refs'; *{$full_sub_name}{CODE} }; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
436
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
6
|
|
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
11
|
$self->_init($sub_ref, $type); |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
4
|
my $checked_sub = $self->_make_checker_for; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Install it |
26
|
|
|
|
|
|
|
{ |
27
|
7
|
|
|
7
|
|
44
|
no strict 'refs'; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
197
|
|
|
1
|
|
|
|
|
2
|
|
28
|
7
|
|
|
7
|
|
32
|
no warnings 'redefine'; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
1755
|
|
29
|
1
|
|
|
|
|
2
|
*{$full_sub_name} = $checked_sub; |
|
1
|
|
|
|
|
5
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
4
|
return; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _make_checker_for { |
36
|
1
|
|
|
1
|
|
3
|
my($self) = @_; |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
7
|
my $valid_type = $self->_get_type; |
39
|
1
|
|
|
|
|
8
|
my $original_sub = $self->_get_object; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return sub { |
42
|
|
|
|
|
|
|
# Call $original_sub correctly |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
0
|
|
|
if (!defined wantarray) { |
45
|
0
|
|
|
|
|
|
$self->_error("Throwing away return value of $valid_type"); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
if (wantarray) { |
49
|
0
|
|
|
|
|
|
my @ret = $original_sub->(@_); |
50
|
0
|
|
|
|
|
|
$self->_check_values(@ret); |
51
|
0
|
|
|
|
|
|
return @ret; |
52
|
|
|
|
|
|
|
} else { |
53
|
0
|
|
|
|
|
|
my $ret = $original_sub->(@_); |
54
|
0
|
|
|
|
|
|
$self->_check_values($ret); |
55
|
0
|
|
|
|
|
|
return $ret; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
1
|
|
|
|
|
18
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |