Chloro/Trait/Role/Composite.pm

filter: Statementstmt 94.1% 48 / 51 Branchbran 33.3% 2 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 89.3% 59 / 66 CC 7 SCAR 14.5
CC
7
Cov
88%
_merge
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.2
« Chloro/ResultSet.pm ↑ Summary Chloro/Role/Form.pm »
1 ## no critic (Moose::RequireMakeImmutable)
2 package Chloro::Trait::Role::Composite;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.07';
9  
10 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Moose::Util::MetaRole;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Moose::Util qw( does_role );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 with 'Chloro::Trait::Role';
16  
17 1 ▶sub _merge_form_components {
Subroutine _merge_form_components: called CC=1 SCAR=0.0
18 1 my $self = shift;
19  
20 1 $self->_merge('field');
21 1 $self->_merge('group');
22 }
23  
24 2 ▶sub _merge {
Subroutine _merge: called CC=7 SCAR=20.7
25 2 my $self = shift;
26 2 my $thing = shift;
27  
28 2 my $pl_thing = $thing . 's';
29  
30 2 my @all;
31 2 foreach my $role ( @{ $self->get_roles() } ) {
32 4 ▶ if ( does_role( $role, 'Chloro::Trait::Role' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (does_role($role, "Chloro::Trait::Role")) 4 0 4
33 4 push @all, $role->$pl_thing();
34 }
35 }
36  
37 2 my %seen;
38  
39 2 foreach my $thing (@all) {
40 4 my $name = $thing->name();
41  
42 4 ▶ if ( exists $seen{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $seen{$name}) 0 4 4
43 0 ▶ next if $seen{$name} == $thing;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$name} == $thing 0 0 0
44  
45 0 require Moose;
46 0 Moose->throw_error( q{Role '}
47 . $self->name()
48 . q{' has encountered a Chloro $thing conflict }
49 . 'during composition. This is a fatal error and '
50 . 'cannot be disambiguated.' );
51 }
52  
53 4 $seen{$name} = $thing;
54 }
55  
56 2 my $add_meth = 'add_' . $thing;
57  
58 2 foreach my $thing (@all) {
59 4 $self->$add_meth($thing);
60 }
61  
62 2 return keys %seen;
63 }
64  
65 1 ▶around apply_params => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
66 1 my $orig = shift;
67 1 my $self = shift;
68  
69 1 $self->$orig(@_);
70  
71 1 $self = Moose::Util::MetaRole::apply_metaroles(
72 for => $self,
73 role_metaroles => {
74 application_to_class => ['Chloro::Trait::Application::ToClass'],
75 application_to_role => ['Chloro::Trait::Application::ToRole'],
76 },
77 );
78  
79 1 $self->_merge_form_components();
80  
81 1 return $self;
82 1 };
83  
84 1 1;
85  
86 # ABSTRACT: A trait that supports applying multiple roles at once
87  
88 __END__
« Chloro/ResultSet.pm ↑ Summary Chloro/Role/Form.pm »