MooseX/Enumeration/Meta/Attribute/Native/Trait/Enumeration.pm

filter: Statementstmt 96.7% 60 / 62 Branchbran 77.7% 14 / 18 Conditioncond 77.7% 7 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 89.6% 95 / 106 CC 14 SCAR 15.8
CC
14
Cov
91%
__ANON__
9.0
_build_enum
4.6
__ANON__
3.0
CRAP 4.9
« MooseX/Enumeration/Meta/Method/Accessor/Native/Enumeration/assign.pm ↑ Summary MooseX/Enumeration/Meta/Method/Accessor/Native/Enumeration/is.pm »
1 11 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package MooseX::Enumeration::Meta::Attribute::Native::Trait::Enumeration;
6 11 our $AUTHORITY = 'cpan:TOBYINK';
7 11 our $VERSION = '0.010';
8  
9 11 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 with 'Moose::Meta::Attribute::Native::Trait';
11  
12 11 ▶use Module::Runtime qw( use_package_optimistically );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 before _process_isa_option => sub
15 12 ▶{
Subroutine __ANON__: called CC=3 SCAR=11.0
16 12 my $class = shift;
17 12 my ($name, $options) = @_;
18
19 12 ▶ if ($options->{enum})
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"enum"}) 9 3 12
20 {
21 confess "Cannot supply both the 'isa' and 'enum' options"
22 9 ▶ if $options->{isa};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"isa"} 0 9 9
23 9 require MooseX::Enumeration;
24 $options->{isa} = 'MooseX::Enumeration'
25 -> _enum_type_implementation
26 9 -> new( values => $options->{enum} );
27 }
28 11 };
29  
30 36 ▶sub _helper_type { 'Str' }
Subroutine _helper_type: called CC=1 SCAR=0.0
31  
32 12 ▶around _check_helper_type => sub { 1 };
Subroutine __ANON__: called CC=1 SCAR=0.0
33  
34 11 has enum => (is => 'ro', lazy => 1, builder => '_build_enum');
35  
36 sub _build_enum
37 3 ▶{
Subroutine _build_enum: called CC=4 SCAR=15.2
38 3 my $meta = shift;
39
40 3 my $enum;
41 3 my $type = $meta->type_constraint;
42 3 ▶ while (defined $type)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) 3 0 3
43 {
44 3 ▶ if ($type->isa('Type::Tiny::Enum')
Branch: 1 branch
BranchTrueFalseTotal
if ($type->isa("Type::Tiny::Enum") or $type->isa("Moose::Meta::TypeConstraint::Enum")) 3 0 3
Condition66%2/3
$type->isa("Type::Tiny::Enum") or $type->isa("Moose::Meta::TypeConstraint::Enum")
l!l&&r!l&&!r
120
MC/DC0%0/2
$type->isa("Type::Tiny::Enum") or $type->isa("Moose::Meta::TypeConstraint::Enum")
$type->isa("Type::Tiny::Enum") $type->isa("Moose::Meta::TypeConstraint::Enum")
Truth table66%2/3
A or B
A= $type->isa("Type::Tiny::Enum")B= $type->isa("Moose::Meta::TypeConstraint::Enum")
ABresult
1X1
011
000
45 or $type->isa('Moose::Meta::TypeConstraint::Enum'))
46 {
47 3 return $type->values;
48 }
49 0 $type = $type->parent;
50 }
51
52 0 confess "could not find values for enumeration";
53 }
54  
55 around _canonicalize_handles => sub
56 25 ▶{
Subroutine __ANON__: called CC=9 SCAR=22.0
57 25 my $next = shift;
58 25 my $self = shift;
59 25 my $handles = $self->handles;
60
61 25 ▶ return unless $handles;
Branch: 1 branch
BranchTrueFalseTotal
unless $handles 0 25 25
62
63 25 ▶ if (!ref $handles and $handles eq 1)
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $handles and $handles eq 1) { } 10 15 25
elsif (not ref $handles and $handles eq 2) { } 2 26 28
Condition100%3/3
not ref $handles and $handles eq 1
!ll&&!rl&&r
13210
MC/DC100%2/2
not ref $handles and $handles eq 1
not ref $handles $handles eq 1
Truth table100%3/3
not(A) and B
A= not ref $handlesB= $handles eq 1
ABresult
0X0
100
111
64 {
65 10 return map +("is_$_" => ["is", $_]), @{ $self->enum };
66 }
67 ▶ elsif (!ref $handles and $handles eq 2)
Condition66%2/3
not ref $handles and $handles eq 2
!ll&&!rl&&r
1302
MC/DC50%1/2
not ref $handles and $handles eq 2
not ref $handles $handles eq 2
Truth table66%2/3
not(A) and B
A= not ref $handlesB= $handles eq 2
ABresult
0X0
100
111
68 {
69 2 my $attr = $self->name;
70 2 return map +("$attr\_is_$_" => ["is", $_]), @{ $self->enum };
71 }
72
73 13 ▶ if (ref $handles eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $handles eq "ARRAY") 3 10 13
74 {
75 3 return map +($_ => [split /_/, $_, 2]), @$handles;
76 }
77
78 10 my %handles = $self->$next(@_);
79 10 for my $h (values %handles)
80 {
81 42 ▶ next unless $h->[0] =~ /^(is|assign)_(\w+)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $h->[0] =~ /^(is|assign)_(\w+)$/ 32 10 42
82
83 10 my @s = split /_/, shift(@$h), 2;
84 10 unshift @$h, @s;
85 }
86 10 return %handles;
87 11 };
88  
89 around _native_accessor_class_for => sub
90 73 ▶{
Subroutine __ANON__: called CC=1 SCAR=0.0
91 73 my $next = shift;
92 73 my $self = shift;
93 73 my ($suffix) = @_;
94
95 73 my $role
96 = 'MooseX::Enumeration::Meta::Method::Accessor::Native::'
97 . $self->_native_type . '::'
98 . $suffix;
99
100 73 return Moose::Meta::Class->create_anon_class(
101 superclasses => [ $self->accessor_metaclass, $self->delegation_metaclass ],
102 roles => [ use_package_optimistically($role) ],
103 cache => 1,
104 )->name;
105 11 };
106  
107 11 1;
« MooseX/Enumeration/Meta/Method/Accessor/Native/Enumeration/assign.pm ↑ Summary MooseX/Enumeration/Meta/Method/Accessor/Native/Enumeration/is.pm »