| 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
| |||||||||||||||||||||||||||||
| 30 | 7 | ▶ | unshift @args, @ALL if $all; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 7 | my %roles; | |||||||||||||||||||||||||||
| 33 | my %options; | ||||||||||||||||||||||||||||
| 34 | 7 | ▶ | while (my $name = shift @args) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 14 | my $details; | |||||||||||||||||||||||||||
| 37 | 14 | ▶ | if ($name =~ /^-/ or ref $args[0]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$name =~ /^-/ or ref $args[0]
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]
| |||||||||||||||||||||||||||||
| 38 | 5 | { $details = shift @args } | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 14 | ▶ | if ($name =~ /^\-(.+)$/i) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
keys %options and not keys %roles
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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;
}
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;
}
| |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $role_pkg->$setup_method( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||