Role/Commons.pm

filter: Statementstmt 77.1% 64 / 83 Branchbran 50.0% 16 / 32 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 86.6% 13 / 15 Podpod 100% 2 / 2 totaltotal 68.0% 100 / 147 CC 24 SCAR 31.2
CC
24
Cov
68%
apply_roles_to_object
71.4
parse_arguments
9.1
import
7.1
CRAP 22.6
↑ Summary Role/Commons/Tap.pm »
1 5 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Role::Commons;
6  
7 5 ▶use Carp qw[ carp croak ];
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Module::Runtime qw[ use_package_optimistically ];
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Moo::Role qw[];
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Types::TypeTiny qw[ HashLike ArrayLike ];
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 $Role::Commons::AUTHORITY = 'cpan:TOBYINK';
14 5 $Role::Commons::VERSION = '0.104';
15 }
16  
17 5 my @ALL = qw(
18 Authority
19 ObjectID
20 Tap
21 );
22  
23 sub parse_arguments
24 7 ▶{
Subroutine parse_arguments: called CC=9 SCAR=22.0
Pod documented
25 7 my $class = shift;
26
27 # Translate "-all".
28 7 my $all = 0;
29 7 ▶ my @args = grep { /^\-all$/i ? do { $all++; 0 } : 1 } @_;
Branch: 1 branch
BranchTrueFalseTotal
/^\-all$/i ? : 1 16 17
30 7 ▶ unshift @args, @ALL if $all;
Branch: 1 branch
BranchTrueFalseTotal
if $all 1 6 7
31
32 7 my %roles;
33 my %options;
34 7 ▶ while (my $name = shift @args)
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = shift @args) 14 7 21
35 {
36 14 my $details;
37 14 ▶ if ($name =~ /^-/ or ref $args[0])
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^-/ or ref $args[0]) 5 9 14
Condition66%2/3
$name =~ /^-/ or ref $args[0]
l!l&&r!l&&!r
509
MC/DC50%1/2
$name =~ /^-/ or ref $args[0]
$name =~ /^-/ ref $args[0]
Truth table66%2/3
A or B
A= $name =~ /^-/B= ref $args[0]
ABresult
1X1
011
000
38 5 { $details = shift @args }
39
40 14 ▶ if ($name =~ /^\-(.+)$/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^\-(.+)$/i) { } 5 9 14
41 5 { $options{ lc $1 } = $details }
42 else
43 9 { $roles{ $name } = $details }
44 }
45
46 7 ▶ carp "Role::Commons - no roles specified"
Branch: 1 branch
BranchTrueFalseTotal
if keys %options and not keys %roles 0 7 7
Condition66%2/3
keys %options and not keys %roles
!ll&&!rl&&r
250
MC/DC0%0/2
keys %options and not keys %roles
keys %options not keys %roles
Truth table66%2/3
A and not(B)
A= keys %optionsB= not keys %roles
ABresult
0X0
100
111
47 if keys %options && !keys %roles;
48
49 7 return(\%roles, \%options);
50 }
51  
52 sub import
53 4 ▶{
Subroutine import: called CC=7 SCAR=19.6
54 4 my $class = shift;
55 4 my ($roles, $options) = $class->parse_arguments(@_);
56 4 ▶ $options->{into} = caller unless exists $options->{into};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $options->{"into"} 1 3 4
57
58 4 foreach my $role (sort keys %$roles)
59 {
60 6 use_package_optimistically( join q[::], $class, $role );
61 }
62
63 'Moo::Role'->apply_roles_to_package(
64 $options->{into},
65 4 map { join q[::], $class, $_ } sort keys %$roles,
66 );
67
68 4 foreach my $role (sort keys %$roles)
69 {
70 6 my $role_pkg = join q[::], $class, $role;
71 6 my $details = $roles->{$role};
72 6 ▶ my $setup_method = do {
Branch: 1 branch
BranchTrueFalseTotal
my $setup_method = do { no strict 'refs'; ${"${role_pkg}::setup_for_class";} } or next 6 0 6
73 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
74 6 ${"$role_pkg\::setup_for_class"};
75 } or next;
76 $role_pkg->$setup_method(
77 $options->{into},
78 6 ▶ HashLike->check($details)
Branch: 2 branches
BranchTrueFalseTotal
&HashLike()->check($details) ? : 0 6 6
&ArrayLike()->check($details) ? : 0 6 6
79 ? %$details
80 : ( ArrayLike->check($details) ? @$details : (option => $details) ),
81 );
82 }
83 }
84  
85 sub apply_roles_to_object
86 0 ▶{
Subroutine apply_roles_to_object: not called CC=10 SCAR=42.7
Pod documented
87 0 ▶ my $class = shift unless blessed($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless blessed($_[0]) 0 0 0
88 0 my $object = shift;
89 0 my ($roles, $options) = $class->parse_arguments(@_);
90
91 0 foreach my $role (sort keys %$roles)
92 {
93 0 use_package_optimistically( join q[::], $class, $role );
94 }
95
96 'Moo::Role'->apply_roles_to_object(
97 $object,
98 0 map { join q[::], $class, $_ } sort keys %$roles,
99 );
100
101 0 foreach my $role (sort keys %$roles)
102 {
103 0 my $role_pkg = join q[::], $class, $role;
104 0 my $details = $roles->{$role};
105 my $setup_method = do {
106 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
107 0 ${"$role_pkg\::setup_for_class"};
108 0 ▶ } || sub { 0 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
do { no strict 'refs'; ${"${role_pkg}::setup_for_class";} } || sub { 0; }
l!l&&r!l&&!r
000
MC/DC0%0/2
do { no strict 'refs'; ${"${role_pkg}::setup_for_class";} } || sub { 0; }
do { no strict 'refs'; ${"${role_pkg}::setup_for_class";} } sub { 0; }
Truth table0%0/3
A || B
A= do { no strict 'refs'; ${"${role_pkg}::setup_for_class";} }B= sub { 0; }
ABresult
1X1
011
000
109 0 ▶ $role_pkg->$setup_method(
Branch: 2 branches
BranchTrueFalseTotal
&HashLike()->check($details) ? : 0 0 0
&ArrayLike()->check($details) ? : 0 0 0
110 ref($object),
111 HashLike->check($details)
112 ? %$details
113 : ( ArrayLike->check($details) ? @$details : (option => $details) ),
114 );
115 0 ▶ $setup_method = do {
Branch: 1 branch
BranchTrueFalseTotal
$setup_method = do { no strict 'refs'; ${"${role_pkg}::setup_for_object";} } or next 0 0 0
116 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
117 0 ${"$role_pkg\::setup_for_object"};
118 } or next;
119 0 ▶ $role_pkg->$setup_method(
Branch: 2 branches
BranchTrueFalseTotal
&HashLike()->check($details) ? : 0 0 0
&ArrayLike()->check($details) ? : 0 0 0
120 $object,
121 HashLike->check($details)
122 ? %$details
123 : ( ArrayLike->check($details) ? @$details : (option => $details) ),
124 );
125 }
126 }
127  
128 5 1;
129  
130 __END__
↑ Summary Role/Commons/Tap.pm »