blib/lib/perl5i/2/Signatures.pm

filter: Statementstmt 100% 59 / 59 Branchbran 78.5% 11 / 14 Conditioncond 60.0% 6 / 10 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 3 totaltotal 86.4% 89 / 103 SCAR 24.9
CC
12
Cov
92%
parse_proto
6.0
code_for
4.0
import
3.1
CRAP 12.1
« blib/lib/perl5i/1.pm ↑ Summary blib/lib/perl5i/0/DEFAULT.pm »
1 package perl5i::2::Signatures;
2  
3 109 ▶use perl5i::2::Signature;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # Can't load full autoboxing or signatures would not be available to the
6 # autoboxed definitions
7 109 ▶use perl5i::2::CODE;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 109 ▶use base q/Devel::Declare::MethodInstaller::Simple/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 109 ▶use Sub::Name;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub import {
13 332 ▶ my $class = shift;
Subroutine import: called CC=3 SCAR=11.3
14  
15 332 my %opts = @_;
16 332 ▶ $opts{into} ||= caller;
Condition33%1/3
$opts{"into"} ||= caller
l!l&&r!l&&!r
03320
MC/DC0%0/2
$opts{"into"} ||= caller
$opts{"into"} caller
Truth table33%1/3
A ||= B
A= $opts{"into"}B= caller
ABresult
1X1
011
000
17 332 ▶ $opts{invocant} ||= '$self';
Condition50%1/2
$opts{"invocant"} ||= "\$self"
l!l
0332
MC/DC0%0/1
$opts{"invocant"} ||= "\$self"
$opts{"invocant"}
Truth table50%1/2
A
A= $opts{"invocant"}
Aresult
11
00
18  
19 332 my %def_opts = %opts;
20 332 delete $def_opts{invocant};
21  
22 # Define "method"
23 332 $class->install_methodhandler(
24 name => 'method',
25 %opts
26 );
27  
28 # Define "func"
29 332 $class->install_methodhandler(
30 name => 'func',
31 %def_opts
32 );
33 }
34  
35 sub parse_proto {
36 2071 ▶ my $self = shift;
Subroutine parse_proto: called CC=6 SCAR=18.0
Pod undocumented
37 2071 my ($proto) = @_;
38 2071 ▶ $proto ||= '';
Condition100%2/2
$proto ||= ""
l!l
1853218
MC/DC100%1/1
$proto ||= ""
$proto
Truth table100%2/2
A
A= $proto
Aresult
11
00
39  
40 # Save it for attaching to the code ref later
41 2071 $self->{perl5i}{signature} = $proto;
42  
43 2071 $proto =~ s/[\r\n]//g;
44 2071 my $invocant = $self->{invocant};
45  
46 2071 my $inject = '';
47 2071 ▶ if( $invocant ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($invocant) 1635 436 2071
48 1635 ▶ $invocant = $1 if $proto =~ s{^(\$\w+):\s*}{};
Branch: 1 branch
BranchTrueFalseTotal
if $proto =~ s/^(\$\w+):\s*// 0 1635 1635
49 1635 $inject .= "my ${invocant} = shift;";
50 }
51 2071 ▶ $inject .= "my ($proto) = \@_;" if defined $proto and length $proto;
Branch: 1 branch
BranchTrueFalseTotal
if defined $proto and length $proto 1853 218 2071
Condition66%2/3
defined $proto and length $proto
!ll&&!rl&&r
02181853
MC/DC50%1/2
defined $proto and length $proto
defined $proto length $proto
Truth table66%2/3
A and B
A= defined $protoB= length $proto
ABresult
0X0
100
111
52  
53 2071 return $inject;
54 }
55  
56  
57 sub code_for {
58 2071 ▶ my ($self, $name) = @_;
Subroutine code_for: called CC=4 SCAR=13.9
Pod undocumented
59  
60 2071 my $signature = $self->{perl5i}{signature};
61 2071 ▶ my $is_method = $self->{invocant} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'invocant'} ? : 1635 436 2071
62  
63 2071 ▶ if (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 1635 436 2071
64 1635 my $pkg = $self->get_curstash_name;
65 1635 ▶ $name = join( '::', $pkg, $name )
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /::/ 1635 0 1635
66 unless( $name =~ /::/ );
67 return sub (&) {
68 1635 ▶ my $code = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
69 # So caller() gets the subroutine name
70 109 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
71 1635 *{$name} = subname $name => $code;
72  
73 1635 $self->set_signature(
74 code => $code,
75 signature => $signature,
76 is_method => $is_method,
77 );
78  
79 1635 return;
80 1635 };
81 } else {
82 return sub (&) {
83 436 ▶ my $code = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
84  
85 436 $self->set_signature(
86 code => $code,
87 signature => $signature,
88 is_method => $is_method,
89 );
90 436 return $code;
91 436 };
92 }
93 }
94  
95  
96 sub set_signature {
97 2071 ▶ my $self = shift;
Subroutine set_signature: called CC=2 SCAR=7.0
Pod undocumented
98 2071 my %args = @_;
99  
100 2071 my $sig = perl5i::2::CODE::signature($args{code});
101 2071 ▶ return $sig if $sig;
Branch: 1 branch
BranchTrueFalseTotal
if $sig 0 2071 2071
102  
103 $sig = perl5i::2::Signature->new(
104 signature => $args{signature},
105 is_method => $args{is_method},
106 2071 );
107  
108 2071 perl5i::2::CODE::__set_signature($args{code}, $sig);
109  
110 2071 return $sig;
111 }
112  
113 109 1;
« blib/lib/perl5i/1.pm ↑ Summary blib/lib/perl5i/0/DEFAULT.pm »