| 1 | package MooseX::ClassAttribute::Trait::Role::Composite; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | our $VERSION = '0.29'; | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Moose::Util::MetaRole; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Moose::Util qw(does_role); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | with 'MooseX::ClassAttribute::Trait::Role'; | |||||||||
| 15 | |||||||||||
| 16 | 3 | ▶ | sub _merge_class_attributes { | ||||||||
|
Subroutine
_merge_class_attributes: called CC=7 SCAR=20.5
| |||||||||||
| 17 | 3 | my $self = shift; | |||||||||
| 18 | |||||||||||
| 19 | 3 | my @all_attributes; | |||||||||
| 20 | 3 | foreach my $role ( @{ $self->get_roles() } ) { | |||||||||
| 21 | 6 | ▶ | if ( does_role( $role, 'MooseX::ClassAttribute::Trait::Role' ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | push @all_attributes, | ||||||||||
| 23 | 5 | map { $role->get_class_attribute($_) } | |||||||||
| 24 | $role->get_class_attribute_list(); | ||||||||||
| 25 | } | ||||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 3 | my %seen; | |||||||||
| 29 | |||||||||||
| 30 | 3 | foreach my $attribute (@all_attributes) { | |||||||||
| 31 | 5 | my $name = $attribute->name(); | |||||||||
| 32 | |||||||||||
| 33 | 5 | ▶ | if ( exists $seen{$name} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | ▶ | next if $seen{$name} == $attribute; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | |||||||||||
| 36 | 0 | require Moose; | |||||||||
| 37 | 0 | Moose->throw_error( "Role '" | |||||||||
| 38 | . $self->name() | ||||||||||
| 39 | . "' has encountered a class attribute conflict " | ||||||||||
| 40 | . "during composition. This is a fatal error and " | ||||||||||
| 41 | . "cannot be disambiguated." ); | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 5 | $seen{$name} = $attribute; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 3 | foreach my $attribute (@all_attributes) { | |||||||||
| 48 | 5 | $self->add_class_attribute( $attribute->clone() ); | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 3 | return keys %seen; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 3 | ▶ | around apply_params => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 55 | 3 | my $orig = shift; | |||||||||
| 56 | 3 | my $self = shift; | |||||||||
| 57 | |||||||||||
| 58 | 3 | $self->$orig(@_); | |||||||||
| 59 | |||||||||||
| 60 | 3 | $self = Moose::Util::MetaRole::apply_metaroles( | |||||||||
| 61 | for => $self, | ||||||||||
| 62 | role_metaroles => { | ||||||||||
| 63 | application_to_class => | ||||||||||
| 64 | ['MooseX::ClassAttribute::Trait::Application::ToClass'], | ||||||||||
| 65 | application_to_role => | ||||||||||
| 66 | ['MooseX::ClassAttribute::Trait::Application::ToRole'], | ||||||||||
| 67 | }, | ||||||||||
| 68 | ); | ||||||||||
| 69 | |||||||||||
| 70 | 3 | $self->_merge_class_attributes(); | |||||||||
| 71 | |||||||||||
| 72 | 3 | return $self; | |||||||||
| 73 | 1 | }; | |||||||||
| 74 | |||||||||||
| 75 | 1 | 1; | |||||||||
| 76 | |||||||||||
| 77 | # ABSTRACT: A trait that supports applying multiple roles at once | ||||||||||
| 78 | |||||||||||
| 79 | __END__ | ||||||||||