| 1 | package MooseX::ClassAttribute::Trait::Mixin::HasClassAttributes; | ||||||||||||||||||||||||||||
| 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 namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | has _class_attribute_map => ( | ||||||||||||||||||||||||||||
| 12 | traits => ['Hash'], | ||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||
| 14 | isa => 'HashRef[Class::MOP::Mixin::AttributeCore]', | ||||||||||||||||||||||||||||
| 15 | handles => { | ||||||||||||||||||||||||||||
| 16 | '_add_class_attribute' => 'set', | ||||||||||||||||||||||||||||
| 17 | 'has_class_attribute' => 'exists', | ||||||||||||||||||||||||||||
| 18 | 'get_class_attribute' => 'get', | ||||||||||||||||||||||||||||
| 19 | '_remove_class_attribute' => 'delete', | ||||||||||||||||||||||||||||
| 20 | 'get_class_attribute_list' => 'keys', | ||||||||||||||||||||||||||||
| 21 | }, | ||||||||||||||||||||||||||||
| 22 | 29 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 8 | init_arg => undef, | |||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # deprecated | ||||||||||||||||||||||||||||
| 27 | 1 | ▶ | sub get_class_attribute_map { | ||||||||||||||||||||||||||
|
Subroutine
get_class_attribute_map: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 1 | return $_[0]->_class_attribute_map(); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 127 | ▶ | sub add_class_attribute { | ||||||||||||||||||||||||||
|
Subroutine
add_class_attribute: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 127 | my $self = shift; | |||||||||||||||||||||||||||
| 33 | 127 | my $attribute = shift; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 127 | ▶ | ( $attribute->isa('Class::MOP::Mixin::AttributeCore') ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | || confess | ||||||||||||||||||||||||||||
| 37 | "Your attribute must be an instance of Class::MOP::Mixin::AttributeCore (or a subclass)"; | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 127 | $self->_attach_class_attribute($attribute); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 127 | my $attr_name = $attribute->name; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 127 | ▶ | $self->remove_class_attribute($attr_name) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | if $self->has_class_attribute($attr_name); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 127 | my $order = ( scalar keys %{ $self->_attribute_map } ); | |||||||||||||||||||||||||||
| 47 | 127 | $attribute->_set_insertion_order($order); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 127 | $self->_add_class_attribute( $attr_name => $attribute ); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # This method is called to allow for installing accessors. Ideally, we'd | ||||||||||||||||||||||||||||
| 52 | # use method overriding, but then the subclass would be responsible for | ||||||||||||||||||||||||||||
| 53 | # making the attribute, which would end up with lots of code | ||||||||||||||||||||||||||||
| 54 | # duplication. Even more ideally, we'd use augment/inner, but this is | ||||||||||||||||||||||||||||
| 55 | # Class::MOP! | ||||||||||||||||||||||||||||
| 56 | 127 | ▶ | $self->_post_add_class_attribute($attribute) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | if $self->can('_post_add_class_attribute'); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 127 | return $attribute; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | ▶ | sub remove_class_attribute { | ||||||||||||||||||||||||||
|
Subroutine
remove_class_attribute: called CC=4 SCAR=14.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | 1 | my $name = shift; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | ▶ | ( defined $name && $name ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $name and $name
MC/DC0%0/2
defined $name and $name
defined $name
$name
Truth table33%1/3
A and B
A= defined $nameB= $name
| |||||||||||||||||||||||||||||
| 67 | || confess 'You must provide an attribute name'; | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | my $removed_attr = $self->get_class_attribute($name); | |||||||||||||||||||||||||||
| 70 | 1 | ▶ | return unless $removed_attr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1 | $self->_remove_class_attribute($name); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | return $removed_attr; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 8 | 1; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # ABSTRACT: A mixin trait for things which have class attributes | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||||||||||