RoleFor/Meta/Role/Trait/RoleFor.pm

filter: Statementstmt 90.7% 49 / 54 Branchbran 66.6% 12 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 82.7% 72 / 87 CC 14 SCAR 24.5
CC
14
Cov
83%
__ANON__
18.4
BEGIN
1.0
BEGIN
1.0
CRAP 11.6
↑ Summary RoleFor.pm »
1 package MooseX::RoleFor::Meta::Role::Trait::RoleFor;
2  
3 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 BEGIN
8 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 $MooseX::RoleFor::Meta::Role::Trait::RoleFor::AUTHORITY = 'cpan:TOBYINK';
10 1 $MooseX::RoleFor::Meta::Role::Trait::RoleFor::VERSION = '0.003';
11 }
12  
13 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Carp qw[croak carp];
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Scalar::Util qw[blessed];
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 has role_is_for => (
20 is => 'rw',
21 isa => 'Undef|Str|ArrayRef[Str]',
22 );
23  
24 1 has role_misapplication_consequence => (
25 is => 'rw',
26 isa => enum([qw/croak carp/]),
27 default => 'carp',
28 );
29  
30 before apply => sub
31 11 ▶{
Subroutine __ANON__: called CC=14 SCAR=29.1
32 11 my ($meta, $thing, @options) = @_;
33  
34 11 my $applying_to = $thing;
35 11 ▶ if ($applying_to->isa('Moose::Meta::Class'))
Branch: 1 branch
BranchTrueFalseTotal
if ($applying_to->isa("Moose::Meta::Class")) 3 8 11
36 {
37 3 $applying_to = $thing->name;
38 }
39
40 11 my @targets;
41 @targets = ref $meta->role_is_for
42 0 ▶ ? @{$meta->role_is_for}
Branch: 2 branches
BranchTrueFalseTotal
if defined $meta->role_is_for 11 0 11
ref $meta->role_is_for ? : 0 11 11
43 : ($meta->role_is_for)
44 if defined $meta->role_is_for;
45
46 11 ▶ return unless @targets;
Branch: 1 branch
BranchTrueFalseTotal
unless @targets 0 11 11
47
48 11 my $compliance = 0;
49 11 TARGET: foreach (@targets)
50 {
51 11 ▶ if ($applying_to->DOES($_))
Branch: 1 branch
BranchTrueFalseTotal
if ($applying_to->DOES($_)) 6 5 11
52 {
53 6 $compliance = 1;
54 6 last TARGET;
55 }
56 }
57
58 11 ▶ return if $compliance;
Branch: 1 branch
BranchTrueFalseTotal
if $compliance 6 5 11
59
60 my $message = sprintf(
61 "Role '%s' must only be applied to classes %s (not '%s')",
62 $meta->name,
63 5 ▶ (join '|', map {"'$_'"} @targets),
Condition33%1/3
ref $applying_to || $applying_to
l!l&&r!l&&!r
500
MC/DC0%0/2
ref $applying_to || $applying_to
ref $applying_to $applying_to
Truth table33%1/3
A || B
A= ref $applying_toB= $applying_to
ABresult
1X1
011
000
64 (ref $applying_to || $applying_to),
65 );
66
67 5 foreach (keys %INC)
68 {
69 1267 s{\.pm$}{};
70 1267 s{[/\\]}{::}g;
71 1267 ▶ $Carp::Internal{$_}++ if /^(?:Class::MOP|Moose|MooseX)\b/
Branch: 1 branch
BranchTrueFalseTotal
if /^(?:Class::MOP|Moose|MooseX)\b/ 387 880 1267
72 }
73
74 5 ▶ $meta->role_misapplication_consequence eq 'croak'
Branch: 1 branch
BranchTrueFalseTotal
$meta->role_misapplication_consequence eq 'croak' ? : 5 0 5
75 ? croak($message)
76 : carp($message);
77
78 0 foreach (keys %INC)
79 {
80 0 s{\.pm$}{};
81 0 s{[/\\]}{::}g;
82 0 ▶ $Carp::Internal{$_}-- if /^(?:Class::MOP|Moose|MooseX)\b/
Branch: 1 branch
BranchTrueFalseTotal
if /^(?:Class::MOP|Moose|MooseX)\b/ 0 0 0
83 }
84 1 };
85  
86 1 'Yay!';
87  
88 __END__
↑ Summary RoleFor.pm »