ClassAttribute/Trait/Mixin/HasClassAttributes.pm

filter: Statementstmt 100% 36 / 36 Branchbran 60.0% 6 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 82.2% 51 / 62 CC 7 SCAR 10.4
CC
7
Cov
88%
remove_class_attribute
4.4
add_class_attribute
4.0
BEGIN
1.0
CRAP 2.8
« ClassAttribute/Trait/Role/Composite.pm ↑ Summary ClassAttribute/Trait/Application/ToClass.pm »
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
BranchTrueFalseTotal
$attribute->isa("Class::MOP::Mixin::AttributeCore") or confess("Your attribute must be an instance of Class::MOP::Mixin::AttributeCore (or a subclass)") 127 0 127
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
BranchTrueFalseTotal
if $self->has_class_attribute($attr_name) 0 127 127
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
BranchTrueFalseTotal
if $self->can("_post_add_class_attribute") 95 32 127
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
BranchTrueFalseTotal
defined $name and $name or confess("You must provide an attribute name") 1 0 1
Condition33%1/3
defined $name and $name
!ll&&!rl&&r
001
MC/DC0%0/2
defined $name and $name
defined $name $name
Truth table33%1/3
A and B
A= defined $nameB= $name
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $removed_attr 0 1 1
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__
« ClassAttribute/Trait/Role/Composite.pm ↑ Summary ClassAttribute/Trait/Application/ToClass.pm »