| 1 | package MooseX::ClassAttribute::Trait::Application::ToRole; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 8 | our $VERSION = '0.29'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use Moose::Util::MetaRole; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use MooseX::ClassAttribute::Trait::Application::ToClass; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 8 | with 'MooseX::ClassAttribute::Trait::Application'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | around apply => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 3 | my $orig = shift; | |||||||||||||||||||||||||||
| 18 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 19 | 3 | my $role1 = shift; | |||||||||||||||||||||||||||
| 20 | 3 | my $role2 = shift; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 3 | $role2 = Moose::Util::MetaRole::apply_metaroles( | |||||||||||||||||||||||||||
| 23 | for => $role2, | ||||||||||||||||||||||||||||
| 24 | role_metaroles => { | ||||||||||||||||||||||||||||
| 25 | role => ['MooseX::ClassAttribute::Trait::Role'], | ||||||||||||||||||||||||||||
| 26 | application_to_class => | ||||||||||||||||||||||||||||
| 27 | ['MooseX::ClassAttribute::Trait::Application::ToClass'], | ||||||||||||||||||||||||||||
| 28 | application_to_role => | ||||||||||||||||||||||||||||
| 29 | ['MooseX::ClassAttribute::Trait::Application::ToRole'], | ||||||||||||||||||||||||||||
| 30 | }, | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 3 | $self->$orig( $role1, $role2 ); | |||||||||||||||||||||||||||
| 34 | 8 | }; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 3 | ▶ | sub _apply_class_attributes { | ||||||||||||||||||||||||||
|
Subroutine
_apply_class_attributes: called CC=4 SCAR=15.9
| |||||||||||||||||||||||||||||
| 37 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 38 | 3 | my $role1 = shift; | |||||||||||||||||||||||||||
| 39 | 3 | my $role2 = shift; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 3 | foreach my $attribute_name ( $role1->get_class_attribute_list() ) { | |||||||||||||||||||||||||||
| 42 | 14 | ▶ | if ( $role2->has_class_attribute($attribute_name) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$role2->has_class_attribute($attribute_name) and $role2->get_class_attribute($attribute_name) != $role1->get_class_attribute($attribute_name)
MC/DC0%0/2
$role2->has_class_attribute($attribute_name) and $role2->get_class_attribute($attribute_name) != $role1->get_class_attribute($attribute_name)
$role2->has_class_attribute($attribute_name)
$role2->get_class_attribute($attribute_name) != $role1->get_class_attribute($attribute_name)
Truth table33%1/3
A and B
A= $role2->has_class_attribute($attribute_name)B= $role2->get_class_attribute($attribute_name) != $role1->get_class_attribute($attribute_name)
| |||||||||||||||||||||||||||||
| 43 | && $role2->get_class_attribute($attribute_name) | ||||||||||||||||||||||||||||
| 44 | != $role1->get_class_attribute($attribute_name) ) { | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | require Moose; | |||||||||||||||||||||||||||
| 47 | 0 | Moose->throw_error( "Role '" | |||||||||||||||||||||||||||
| 48 | . $role1->name() | ||||||||||||||||||||||||||||
| 49 | . "' has encountered a class attribute conflict " | ||||||||||||||||||||||||||||
| 50 | . "during composition. This is fatal error and cannot be disambiguated." | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||||||||||
| 54 | 14 | $role2->add_class_attribute( | |||||||||||||||||||||||||||
| 55 | $role1->get_class_attribute($attribute_name)->clone() ); | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 8 | 1; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # ABSTRACT: A trait that supports applying class attributes to roles | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | __END__ | ||||||||||||||||||||||||||||