| 1 | package Moose::Meta::Role::Attribute; | ||||||||||||||||||||||||||||
| 2 | 386 | our $VERSION = '2.4001'; | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 386 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 386 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 386 | ▶ | use List::Util 1.33 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 386 | ▶ | use Scalar::Util 'blessed', 'weaken'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 386 | ▶ | use parent 'Moose::Meta::Mixin::AttributeCore', 'Class::MOP::Object'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 386 | ▶ | use Moose::Util 'throw_exception'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 386 | __PACKAGE__->meta->add_attribute( | |||||||||||||||||||||||||||
| 15 | 'metaclass' => ( | ||||||||||||||||||||||||||||
| 16 | reader => 'metaclass', | ||||||||||||||||||||||||||||
| 17 | Class::MOP::_definition_context(), | ||||||||||||||||||||||||||||
| 18 | ) | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 386 | __PACKAGE__->meta->add_attribute( | |||||||||||||||||||||||||||
| 22 | 'associated_role' => ( | ||||||||||||||||||||||||||||
| 23 | reader => 'associated_role', | ||||||||||||||||||||||||||||
| 24 | Class::MOP::_definition_context(), | ||||||||||||||||||||||||||||
| 25 | ) | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 386 | __PACKAGE__->meta->add_attribute( | |||||||||||||||||||||||||||
| 29 | '_original_role' => ( | ||||||||||||||||||||||||||||
| 30 | reader => '_original_role', | ||||||||||||||||||||||||||||
| 31 | Class::MOP::_definition_context(), | ||||||||||||||||||||||||||||
| 32 | ) | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 386 | __PACKAGE__->meta->add_attribute( | |||||||||||||||||||||||||||
| 36 | 'is' => ( | ||||||||||||||||||||||||||||
| 37 | reader => 'is', | ||||||||||||||||||||||||||||
| 38 | Class::MOP::_definition_context(), | ||||||||||||||||||||||||||||
| 39 | ) | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 386 | __PACKAGE__->meta->add_attribute( | |||||||||||||||||||||||||||
| 43 | 'original_options' => ( | ||||||||||||||||||||||||||||
| 44 | reader => 'original_options', | ||||||||||||||||||||||||||||
| 45 | Class::MOP::_definition_context(), | ||||||||||||||||||||||||||||
| 46 | ) | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 725 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 725 | my ( $class, $name, %options ) = @_; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 725 | ▶ | (defined $name) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | || throw_exception( MustProvideANameForTheAttribute => params => \%options, | ||||||||||||||||||||||||||||
| 54 | class => $class | ||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 722 | my $role = delete $options{_original_role}; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 722 | return bless { | |||||||||||||||||||||||||||
| 60 | name => $name, | ||||||||||||||||||||||||||||
| 61 | original_options => \%options, | ||||||||||||||||||||||||||||
| 62 | _original_role => $role, | ||||||||||||||||||||||||||||
| 63 | %options, | ||||||||||||||||||||||||||||
| 64 | }, $class; | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 723 | ▶ | sub attach_to_role { | ||||||||||||||||||||||||||
|
Subroutine
attach_to_role: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 723 | my ( $self, $role ) = @_; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 723 | ▶ | ( blessed($role) && $role->isa('Moose::Meta::Role') ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($role) and $role->isa("Moose::Meta::Role")
MC/DC50%1/2
builtin::blessed($role) and $role->isa("Moose::Meta::Role")
builtin::blessed($role)
$role->isa("Moose::Meta::Role")
Truth table66%2/3
A and B
A= builtin::blessed($role)B= $role->isa("Moose::Meta::Role")
| |||||||||||||||||||||||||||||
| 71 | || throw_exception( MustPassAMooseMetaRoleInstanceOrSubclass => class => $self, | ||||||||||||||||||||||||||||
| 72 | role => $role | ||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 722 | weaken( $self->{'associated_role'} = $role ); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 947 | ▶ | sub original_role { | ||||||||||||||||||||||||||
|
Subroutine
original_role: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 947 | my $self = shift; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 947 | ▶ | return $self->_original_role || $self->associated_role; | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->_original_role || $self->associated_role
MC/DC0%0/2
$self->_original_role || $self->associated_role
$self->_original_role
$self->associated_role
Truth table66%2/3
A || B
A= $self->_original_roleB= $self->associated_role
| |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 656 | ▶ | sub attribute_for_class { | ||||||||||||||||||||||||||
|
Subroutine
attribute_for_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 656 | my $self = shift; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 656 | my $metaclass = $self->original_role->applied_attribute_metaclass; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | return $metaclass->interpolate_class_and_new( | ||||||||||||||||||||||||||||
| 90 | 656 | $self->name => %{ $self->original_options }, | |||||||||||||||||||||||||||
| 91 | role_attribute => $self, | ||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 291 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 291 | my $self = shift; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 291 | my $role = $self->original_role; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | return ( ref $self )->new( | ||||||||||||||||||||||||||||
| 101 | $self->name, | ||||||||||||||||||||||||||||
| 102 | 291 | %{ $self->original_options }, | |||||||||||||||||||||||||||
| 103 | _original_role => $role, | ||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 8 | ▶ | sub is_same_as { | ||||||||||||||||||||||||||
|
Subroutine
is_same_as: called CC=9 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 109 | 8 | my $attr = shift; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 8 | my $self_options = $self->original_options; | |||||||||||||||||||||||||||
| 112 | 8 | my $other_options = $attr->original_options; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | return 0 | ||||||||||||||||||||||||||||
| 115 | 8 | ▶ | unless ( join q{|}, sort keys %{$self_options} ) eq ( join q{|}, sort keys %{$other_options} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 8 | for my $key ( keys %{$self_options} ) { | |||||||||||||||||||||||||||
| 118 | 11 | ▶ | return 0 if defined $self_options->{$key} && ! defined $other_options->{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self_options->{$key} and not defined $other_options->{$key}
MC/DC0%0/2
defined $self_options->{$key} and not defined $other_options->{$key}
defined $self_options->{$key}
not defined $other_options->{$key}
Truth table33%1/3
A and not(B)
A= defined $self_options->{$key}B= not defined $other_options->{$key}
| |||||||||||||||||||||||||||||
| 119 | 11 | ▶ | return 0 if ! defined $self_options->{$key} && defined $other_options->{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $self_options->{$key} and defined $other_options->{$key}
MC/DC0%0/2
not defined $self_options->{$key} and defined $other_options->{$key}
not defined $self_options->{$key}
defined $other_options->{$key}
Truth table33%1/3
not(A) and B
A= not defined $self_options->{$key}B= defined $other_options->{$key}
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 11 | ▶ | next if all { ! defined } $self_options->{$key}, $other_options->{$key}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 11 | ▶ | return 0 unless $self_options->{$key} eq $other_options->{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 2 | return 1; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 386 | 1; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | # ABSTRACT: The Moose attribute metaclass for Roles | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||