blib/lib/Moose/Meta/Attribute/Native/Trait.pm

filter: Statementstmt 95.0% 76 / 80 Branchbran 77.2% 17 / 22 Conditioncond 44.4% 8 / 18 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 100% 17 / 17 Podpod n/a totaltotal 81.0% 120 / 148 CC 20 SCAR 16.0
CC
20
Cov
84%
_check_helper_type
13.2
_check_handles_values
4.3
_canonicalize_handles_value
4.0
CRAP 4.9
« blib/lib/Moose/Meta/Role/Application/ToClass.pm ↑ Summary blib/lib/Class/MOP/Class.pm »
1 package Moose::Meta::Attribute::Native::Trait;
2 50 our $VERSION = '2.4001';
3  
4 50 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 50 ▶use Module::Runtime 'require_module';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 50 ▶use Moose::Deprecated;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 50 ▶use Moose::Util 'throw_exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 50 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 50 requires '_helper_type';
11  
12 182 ▶before '_process_options' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
13 182 my ( $self, $name, $options ) = @_;
14  
15 182 $self->_check_helper_type( $options, $name );
16 50 };
17  
18 182 ▶sub _check_helper_type {
Subroutine _check_helper_type: called CC=8 SCAR=25.8
19 182 my ( $self, $options, $name ) = @_;
20  
21 182 my $type = $self->_helper_type;
22  
23 $options->{isa} = $type
24 182 ▶ unless exists $options->{isa};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $options->{"isa"} 7 175 182
25  
26 182 my $isa;
27 my $isa_name;
28  
29 182 ▶ if ( blessed( $options->{isa} )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($options->{'isa'}) and $options->{'isa'}->can('does') and $options->{'isa'}->does('Specio::Constraint::Role::Interface')) { } 0 182 182
Condition50%3/6
builtin::blessed($options->{"isa"}) and $options->{"isa"}->can("does") and $options->{"isa"}->does("Specio::Constraint::Role::Interface")
!ll&&!rl&&r
18200
builtin::blessed($options->{"isa"}) and $options->{"isa"}->can("does")
!ll&&!rl&&r
17840
MC/DC0%0/3
builtin::blessed($options->{"isa"}) and $options->{"isa"}->can("does") and $options->{"isa"}->does("Specio::Constraint::Role::Interface")
builtin::blessed($options->{"isa"}) $options->{"isa"}->can("does") $options->{"isa"}->does("Specio::Constraint::Role::Interface")
Truth table50%2/4
A and B and C
A= builtin::blessed($options->{"isa"})B= $options->{"isa"}->can("does")C= $options->{"isa"}->does("Specio::Constraint::Role::Interface")
ABCresult
0XX0
10X0
1100
1111
30 && $options->{isa}->can('does')
31 && $options->{isa}->does('Specio::Constraint::Role::Interface') ) {
32  
33 0 $isa = $options->{isa};
34 0 require Specio::Library::Builtins;
35 0 ▶ return if $isa->is_a_type_of( Specio::Library::Builtins::t($type) );
Branch: 1 branch
BranchTrueFalseTotal
if $isa->is_a_type_of(Specio::Library::Builtins::t($type)) 0 0 0
36 0 ▶ $isa_name = $isa->name() || $isa->description();
Condition0%0/3
$isa->name || $isa->description
l!l&&r!l&&!r
000
MC/DC0%0/2
$isa->name || $isa->description
$isa->name $isa->description
Truth table0%0/3
A || B
A= $isa->nameB= $isa->description
ABresult
1X1
011
000
37 }
38 else {
39 $isa = Moose::Util::TypeConstraints::find_or_create_type_constraint(
40 182 $options->{isa} );
41 182 ▶ return if $isa->is_a_type_of($type);
Branch: 1 branch
BranchTrueFalseTotal
if $isa->is_a_type_of($type) 181 1 182
42 1 $isa_name = $isa->name();
43 }
44  
45 1 throw_exception( WrongTypeConstraintGiven => required_type => $type,
46 given_type => $isa_name,
47 attribute_name => $name,
48 params => $options
49 );
50 }
51  
52 181 ▶before 'install_accessors' => sub { (shift)->_check_handles_values };
Subroutine __ANON__: called CC=1 SCAR=0.0
53  
54 181 ▶sub _check_handles_values {
Subroutine _check_handles_values: called CC=4 SCAR=14.6
55 181 my $self = shift;
56  
57 181 my %handles = $self->_canonicalize_handles;
58  
59 178 for my $original_method ( values %handles ) {
60 1033 my $name = $original_method->[0];
61  
62 1033 my $accessor_class = $self->_native_accessor_class_for($name);
63  
64 1032 ▶ ( $accessor_class && $accessor_class->can('new') )
Branch: 1 branch
BranchTrueFalseTotal
$accessor_class and $accessor_class->can("new") or confess("$name is an unsupported method type - $accessor_class") 1032 0 1032
Condition33%1/3
$accessor_class and $accessor_class->can("new")
!ll&&!rl&&r
001032
MC/DC0%0/2
$accessor_class and $accessor_class->can("new")
$accessor_class $accessor_class->can("new")
Truth table33%1/3
A and B
A= $accessor_classB= $accessor_class->can("new")
ABresult
0X0
100
111
65 || confess
66 "$name is an unsupported method type - $accessor_class";
67 }
68 }
69  
70 362 ▶around '_canonicalize_handles' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
71 362 shift;
72 362 my $self = shift;
73 362 my $handles = $self->handles;
74  
75 362 ▶ return unless $handles;
Branch: 1 branch
BranchTrueFalseTotal
unless $handles 1 361 362
76  
77 361 ▶ unless ( 'HASH' eq ref $handles ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("HASH" eq ref $handles) 2 359 361
78 2 throw_exception( HandlesMustBeAHashRef => instance => $self,
79 given_handles => $handles
80 );
81 }
82  
83 return
84 359 map { $_ => $self->_canonicalize_handles_value( $handles->{$_} ) }
85 keys %$handles;
86 50 };
87  
88 2073 ▶sub _canonicalize_handles_value {
Subroutine _canonicalize_handles_value: called CC=4 SCAR=13.9
89 2073 my $self = shift;
90 2073 my $value = shift;
91  
92 2073 ▶ if ( ref $value && 'ARRAY' ne ref $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value and "ARRAY" ne ref $value) 4 2069 2073
Condition100%3/3
ref $value and "ARRAY" ne ref $value
!ll&&!rl&&r
15235464
MC/DC100%2/2
ref $value and "ARRAY" ne ref $value
ref $value "ARRAY" ne ref $value
Truth table100%3/3
A and B
A= ref $valueB= "ARRAY" ne ref $value
ABresult
0X0
100
111
93 4 throw_exception( InvalidHandleValue => instance => $self,
94 handle_value => $value
95 );
96 }
97  
98 2069 ▶ return ref $value ? $value : [$value];
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 546 1523 2069
99 }
100  
101 1032 ▶around '_make_delegation_method' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.6
102 1032 my $next = shift;
103 1032 my ( $self, $handle_name, $method_to_call ) = @_;
104  
105 1032 my ( $name, @curried_args ) = @$method_to_call;
106  
107 1032 my $accessor_class = $self->_native_accessor_class_for($name);
108  
109 1032 ▶ die "Cannot find an accessor class for $name"
Branch: 1 branch
BranchTrueFalseTotal
unless $accessor_class and $accessor_class->can("new") 0 1032 1032
Condition33%1/3
$accessor_class and $accessor_class->can("new")
!ll&&!rl&&r
001032
MC/DC0%0/2
$accessor_class and $accessor_class->can("new")
$accessor_class $accessor_class->can("new")
Truth table33%1/3
A and B
A= $accessor_classB= $accessor_class->can("new")
ABresult
0X0
100
111
110 unless $accessor_class && $accessor_class->can('new');
111  
112 1032 return $accessor_class->new(
113 name => $handle_name,
114 package_name => $self->associated_class->name,
115 delegate_to_method => $name,
116 attribute => $self,
117 is_inline => 1,
118 curried_arguments => \@curried_args,
119 root_types => [ $self->_root_types ],
120 );
121 50 };
122  
123 976 ▶sub _root_types {
Subroutine _root_types: called CC=1 SCAR=0.0
124 976 return $_[0]->_helper_type;
125 }
126  
127 2065 ▶sub _native_accessor_class_for {
Subroutine _native_accessor_class_for: called CC=1 SCAR=0.0
128 2065 my ( $self, $suffix ) = @_;
129  
130 2065 my $role
131 = 'Moose::Meta::Method::Accessor::Native::'
132 . $self->_native_type . '::'
133 . $suffix;
134  
135 2064 require_module($role);
136 2064 return Moose::Meta::Class->create_anon_class(
137 superclasses =>
138 [ $self->accessor_metaclass, $self->delegation_metaclass ],
139 roles => [$role],
140 cache => 1,
141 )->name;
142 }
143  
144 177 ▶sub _build_native_type {
Subroutine _build_native_type: called CC=3 SCAR=11.0
145 177 my $self = shift;
146  
147 177 for my $role_name ( map { $_->name } $self->meta->calculate_all_roles ) {
148 187 ▶ return $1 if $role_name =~ /::Native::Trait::(\w+)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $role_name =~ /::Native::Trait::(\w+)$/ 176 11 187
149 }
150  
151 1 throw_exception( CannotCalculateNativeType => instance => $self );
152 }
153  
154 50 has '_native_type' => (
155 is => 'ro',
156 isa => 'Str',
157 lazy => 1,
158 builder => '_build_native_type',
159 );
160  
161 50 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
162 50 ▶no Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
163  
164 50 1;
165  
166 # ABSTRACT: Shared role for native delegation traits
167  
168 __END__
« blib/lib/Moose/Meta/Role/Application/ToClass.pm ↑ Summary blib/lib/Class/MOP/Class.pm »