lib/Mite/Trait/HasMethods.pm

filter: Statementstmt 100% 93 / 93 Branchbran 82.1% 23 / 28 Conditioncond 45.4% 5 / 11 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 100% 17 / 17 Podpod 0.0% 0 / 2 totaltotal 87.9% 139 / 158 CC 22 SCAR 12.3
CC
22
Cov
92%
__ANON__
5.5
__ANON__
5.0
BEGIN
4.1
CRAP 3.4
« lib/Mite/Role.pm ↑ Summary lib/Mite/Package.pm »
1 117 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 117 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 117 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Mite::Trait::HasMethods;
6 117 ▶use Mite::Miteception -role, -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 117 our $AUTHORITY = 'cpan:TOBYINK';
9 117 our $VERSION = '0.013000';
10  
11 117 requires qw( _function_for_croak );
12  
13 117 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=14.2
14 117 ▶ *_CONSTANTS_DEFLATE = "$]" >= 5.012 && "$]" < 5.020 ? \&true : \&false;
Branch: 1 branch
BranchTrueFalseTotal
"$]" >= 5.012 && "$]" < 5.02 ? : 0 117 117
Condition33%1/3
"$]" >= "5.012" and "$]" < "5.02"
!ll&&!rl&&r
01170
MC/DC0%0/2
"$]" >= "5.012" and "$]" < "5.02"
"$]" >= "5.012" "$]" < "5.02"
Truth table33%1/3
A and B
A= "$]" >= "5.012"B= "$]" < "5.02"
ABresult
0X0
100
111
15 };
16  
17 has method_signatures =>
18 is => ro,
19 isa => Map[ MethodName, MiteSignature ],
20 158 ▶ builder => sub { {} };
Subroutine __ANON__: called CC=1 SCAR=0.0
21  
22 8 ▶sub add_method_signature {
Subroutine add_method_signature: called CC=2 SCAR=7.0
Pod undocumented
23 8 my ( $self, $method_name, %opts ) = @_;
24  
25 8 ▶ defined $self->method_signatures->{ $method_name }
Branch: 1 branch
BranchTrueFalseTotal
defined $self->method_signatures->{$method_name} and croak("Method signature for %s already exists", $method_name) 0 8 8
26 and croak( 'Method signature for %s already exists', $method_name );
27  
28 8 require Mite::Signature;
29 8 $self->method_signatures->{ $method_name } = 'Mite::Signature'->new(
30 method_name => $method_name,
31 class => $self,
32 %opts,
33 );
34  
35 8 return;
36 }
37  
38 152 ▶sub _all_subs {
Subroutine _all_subs: called CC=1 SCAR=0.0
39 152 my $self = shift;
40 152 my $package = $self->name;
41 117 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
42 152 my $stash = \%{"$package\::"};
43 return {
44 map {;
45 # this is an ugly hack to populate the scalar slot of any globs, to
46 # prevent perl from converting constants back into scalar refs in the
47 # stash when they are used (perl 5.12 - 5.18). scalar slots on their own
48 # aren't detectable through pure perl, so this seems like an acceptable
49 # compromise.
50 120 ${"${package}::${_}"} = ${"${package}::${_}"}
51 if _CONSTANTS_DEFLATE;
52 120 $_ => \&{"${package}::${_}"}
53 }
54 152 grep exists &{"${package}::${_}"},
55 grep !/::\z/,
56 keys %$stash
57 };
58 }
59  
60 152 ▶sub native_methods {
Subroutine native_methods: called CC=4 SCAR=13.9
Pod undocumented
61 152 my $self = shift;
62 152 my %methods = %{ $self->_all_subs };
63  
64 152 require B;
65 152 for my $name ( sort keys %methods ) {
66 120 my $cv = B::svref_2object( $methods{$name} );
67 120 my $stashname = eval { $cv->GV->STASH->NAME };
68 $stashname eq $self->name
69 or $stashname eq 'constant'
70 120 ▶ or delete $methods{$name};
Branch: 1 branch
BranchTrueFalseTotal
$stashname eq $self->name or $stashname eq "constant" or delete $methods{$name} 67 53 120
Condition66%2/3
$stashname eq $self->name or $stashname eq "constant"
l!l&&r!l&&!r
67053
MC/DC50%1/2
$stashname eq $self->name or $stashname eq "constant"
$stashname eq $self->name $stashname eq "constant"
Truth table66%2/3
A or B
A= $stashname eq $self->nameB= $stashname eq "constant"
ABresult
1X1
011
000
71 }
72  
73 152 delete $methods{meta};
74  
75 152 return \%methods;
76 }
77  
78 119 ▶before inject_mite_functions => sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
79 119 my ( $self, $file, $arg ) = ( shift, @_ );
80  
81 119 ▶ my $requested = sub { $arg->{$_[0]} ? 1 : $arg->{'!'.$_[0]} ? 0 : $arg->{'-all'} ? 1 : $_[1]; };
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 3 branches
BranchTrueFalseTotal
$$arg{$_[0]} ? : 0 476 476
$$arg{'!' . $_[0]} ? : 3 473 476
$arg->{'-all'} ? : 40 433 473
82 119 my $defaults = ! $arg->{'!-defaults'};
83 119 my $shim = $self->shim_name;
84 119 my $package = $self->name;
85 119 my $kind = $self->kind;
86 119 ▶ my $parse_mm_args = $shim->can( '_parse_mm_args' ) || \&Mite::Shim::_parse_mm_args;
Condition50%1/2
$shim->can('_parse_mm_args') || \&Mite::Shim::_parse_mm_args
l!l
1190
MC/DC0%0/1
$shim->can('_parse_mm_args') || \&Mite::Shim::_parse_mm_args
$shim->can('_parse_mm_args')
Truth table50%1/2
A
A= $shim->can('_parse_mm_args')
Aresult
11
00
87  
88 117 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
89  
90 119 ▶ if ( $requested->( 'signature_for', $defaults ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$requested("signature_for", $defaults)) 118 1 119
91  
92 118 ▶ *{ $package .'::signature_for' } = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
93 10 my $name = shift;
94 10 ▶ if ( $name =~ /^\+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^\+/) { } 2 8 10
95 2 $name =~ s/^\+//;
96 2 $self->extend_method_signature( $name, @_ );
97 }
98 else {
99 8 $self->add_method_signature( $name, @_ );
100 }
101 10 return;
102 118 };
103  
104 $self->imported_keywords->{signature_for} =
105 118 sprintf 'sub { $SHIM->HANDLE_signature_for( $CALLER, %s, @_ ) }',
106 B::perlstring( $kind );
107 }
108  
109 119 for my $modifier ( qw( before after around ) ) {
110  
111 357 ▶ $requested->( $modifier, $defaults ) or next;
Branch: 1 branch
BranchTrueFalseTotal
&$requested($modifier, $defaults) or next 351 6 357
112  
113 351 ▶ *{ $package .'::'. $modifier } = sub {
Subroutine __ANON__: called CC=5 SCAR=17.0
114 4 my ( $names, $coderef ) = &$parse_mm_args;
115 4 ▶ CodeRef->check( $coderef )
Branch: 1 branch
BranchTrueFalseTotal
&CodeRef()->check($coderef) or croak("Expected a coderef method modifier") 4 0 4
116 or croak "Expected a coderef method modifier";
117 4 ▶ ArrayRef->of(Str)->check( $names ) && @$names
Branch: 1 branch
BranchTrueFalseTotal
&ArrayRef()->of(&Str())->check($names) and @$names or croak("Expected a list of method names to modify") 4 0 4
Condition33%1/3
&ArrayRef()->of(&Str())->check($names) and @$names
!ll&&!rl&&r
004
MC/DC0%0/2
&ArrayRef()->of(&Str())->check($names) and @$names
&ArrayRef()->of(&Str())->check($names) @$names
Truth table33%1/3
A and B
A= &ArrayRef()->of(&Str())->check($names)B= @$names
ABresult
0X0
100
111
118 or croak "Expected a list of method names to modify";
119 4 ▶ $self->add_required_methods( @$names ) if $kind eq 'role';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "role" 1 3 4
120 4 return;
121 351 };
122  
123 351 $self->imported_keywords->{$modifier} =
124 sprintf 'sub { $SHIM->HANDLE_%s( $CALLER, %s, @_ ) }',
125 $modifier, B::perlstring( $kind );
126 }
127 117 };
128  
129 128 ▶around compilation_stages => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
130 128 my ( $next, $self ) = ( shift, shift );
131 128 my @stages = $self->$next( @_ );
132 128 push @stages, '_compile_method_signatures';
133 128 return @stages;
134 117 };
135  
136 128 ▶sub _compile_method_signatures {
Subroutine _compile_method_signatures: called CC=4 SCAR=13.9
137 128 my $self = shift;
138 128 ▶ my %sigs = %{ $self->method_signatures } or return;
Branch: 1 branch
BranchTrueFalseTotal
my(%sigs) = %{$self->method_signatures;} or return 9 119 128
139  
140 9 my $code = "# Method signatures\n"
141 . "our \%SIGNATURE_FOR;\n\n";
142  
143 9 for my $name ( sort keys %sigs ) {
144 10 my $guard = $sigs{$name}->locally_set_compiling_class( $self );
145  
146 $code .= sprintf(
147 '$SIGNATURE_FOR{%s} = %s;' . "\n\n",
148 B::perlstring( $name ),
149 10 $sigs{$name}->_compile_coderef,
150 );
151  
152 10 ▶ if ( my $support = $sigs{$name}->_compile_support ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $support = $sigs{$name}->_compile_support) 5 5 10
153 5 $code .= "$support\n\n";
154 }
155 }
156  
157 9 return $code;
158 }
159  
160 117 1;
« lib/Mite/Role.pm ↑ Summary lib/Mite/Package.pm »