Typed/Code.pm

filter: Statementstmt 83.0% 44 / 53 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 1 totaltotal 78.2% 54 / 69 CC 3 SCAR 12.7
CC
3
Cov
77%
__ANON__
12.0
_make_checker_for
1.4
BEGIN
1.0
CRAP 3.6
« Typed/Array.pm ↑ Summary Typed/Hash.pm »
1 package Variable::Strongly::Typed::Code;
2  
3 8 ▶use version; $VERSION = qv('1.0.0');
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 ▶use base qw(Variable::Strongly::Typed);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 {
12 2 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
13 2 my($class, $symbol, $referent, $type) = @_;
14  
15 2 my $self = bless \my($anon_scalar), $class;
16  
17 2 my $full_sub_name = $$symbol;
18 2 $full_sub_name =~ s/^\*//;
19 8 ▶ my $sub_ref = do { no strict 'refs'; *{$full_sub_name}{CODE} };
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 $self->_init($sub_ref, $type);
22  
23 1 my $checked_sub = $self->_make_checker_for;
24  
25 # Install it
26 {
27 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 8 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 *{$full_sub_name} = $checked_sub;
30 }
31  
32 1 return;
33 }
34  
35 1 ▶ sub _make_checker_for {
Subroutine _make_checker_for: called CC=1 SCAR=3.7
36 1 my($self) = @_;
37  
38 1 my $valid_type = $self->_get_type;
39 1 my $original_sub = $self->_get_object;
40  
41 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
42 # Call $original_sub correctly
43  
44 0 ▶ if (!defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
45 0 $self->_error("Throwing away return value of $valid_type");
46 }
47  
48 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
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 }
59 }
60  
61 8 1;
62  
63 __END__
« Typed/Array.pm ↑ Summary Typed/Hash.pm »