blib/lib/Moose/Meta/Method/Accessor/Native.pm

filter: Statementstmt 100% 84 / 84 Branchbran 81.8% 18 / 22 Conditioncond 62.5% 5 / 8 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 20 / 20 Podpod 0.0% 0 / 1 totaltotal 92.1% 129 / 140 CC 15 SCAR 8.9
CC
15
Cov
94%
__ANON__
5.0
__ANON__
4.0
_inline_check_argument_count
3.0
CRAP 2.4
« blib/lib/Class/MOP/Mixin/AttributeCore.pm ↑ Summary blib/lib/Class/MOP/Object.pm »
1 package Moose::Meta::Method::Accessor::Native;
2 48 our $VERSION = '2.4001';
3  
4 48 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 48 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 48 ▶use Carp qw( confess );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 48 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 48 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 48 ▶use Moose::Util 'throw_exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1033 ▶around new => sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
15 1033 my $orig = shift;
16 1033 my $class = shift;
17 1033 my %options = @_;
18  
19 $options{curried_arguments} = []
20 1033 ▶ unless exists $options{curried_arguments};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $options{"curried_arguments"} 0 1033 1033
21  
22 throw_exception( MustSupplyArrayRefAsCurriedArguments => params => \%options,
23 class_name => $class
24 )
25 unless $options{curried_arguments}
26 1033 ▶ && ref($options{curried_arguments}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless $options{"curried_arguments"} and ref $options{"curried_arguments"} eq "ARRAY" 1 1032 1033
Condition66%2/3
$options{"curried_arguments"} and ref $options{"curried_arguments"} eq "ARRAY"
!ll&&!rl&&r
011032
MC/DC50%1/2
$options{"curried_arguments"} and ref $options{"curried_arguments"} eq "ARRAY"
$options{"curried_arguments"} ref $options{"curried_arguments"} eq "ARRAY"
Truth table66%2/3
A and B
A= $options{"curried_arguments"}B= ref $options{"curried_arguments"} eq "ARRAY"
ABresult
0X0
100
111
27  
28 1032 my $attr_context = $options{attribute}->definition_context;
29 1032 my $desc = 'native delegation method ';
30 1032 $desc .= $options{attribute}->associated_class->name;
31 1032 $desc .= '::' . $options{name};
32 1032 $desc .= " ($options{delegate_to_method})";
33 1032 $desc .= " of attribute " . $options{attribute}->name;
34 $options{definition_context} = {
35 1032 ▶ %{ $attr_context || {} },
Condition50%1/2
$attr_context || {}
l!l
10320
MC/DC0%0/1
$attr_context || {}
$attr_context
Truth table50%1/2
A
A= $attr_context
Aresult
11
00
36 description => $desc,
37 };
38  
39 1032 $options{accessor_type} = 'native';
40  
41 1032 return $class->$orig(%options);
42 48 };
43  
44 1032 ▶sub _new {
Subroutine _new: called CC=2 SCAR=7.1
45 1032 my $class = shift;
46 1032 ▶ my $options = @_ == 1 ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 1032 0 1032
47  
48 1032 return bless $options, $class;
49 }
50  
51 1699 ▶sub root_types { (shift)->{'root_types'} }
Subroutine root_types: called CC=1 SCAR=0.0
Pod undocumented
52  
53 1032 ▶sub _initialize_body {
Subroutine _initialize_body: called CC=1 SCAR=0.0
54 1032 my $self = shift;
55  
56 1032 $self->{'body'} = $self->_compile_code( [$self->_generate_method] );
57  
58 1032 return;
59 }
60  
61 1032 ▶sub _inline_curried_arguments {
Subroutine _inline_curried_arguments: called CC=2 SCAR=6.9
62 1032 my $self = shift;
63  
64 1032 ▶ return unless @{ $self->curried_arguments };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->curried_arguments;} 759 273 1032
65  
66 273 return 'unshift @_, @curried;';
67 }
68  
69 1094 ▶sub _inline_check_argument_count {
Subroutine _inline_check_argument_count: called CC=3 SCAR=11.0
70 1094 my $self = shift;
71  
72 1094 my @code;
73  
74 1094 ▶ if (my $min = $self->_minimum_arguments) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $min = $self->_minimum_arguments) 623 471 1094
75 623 push @code, (
76 'if (@_ < ' . $min . ') {',
77 $self->_inline_throw_exception( MethodExpectsMoreArgs =>
78 'method_name => "'.$self->delegate_to_method.'",'.
79 "minimum_args => ".$min,
80 ) . ';',
81 '}',
82 );
83 }
84  
85 1094 ▶ if (defined(my $max = $self->_maximum_arguments)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $max = $self->_maximum_arguments)) 895 199 1094
86 895 push @code, (
87 'if (@_ > ' . $max . ') {',
88 $self->_inline_throw_exception( MethodExpectsFewerArgs =>
89 'method_name => "'.$self->delegate_to_method.'",'.
90 'maximum_args => '.$max,
91 ) . ';',
92 '}',
93 );
94 }
95  
96 1094 return @code;
97 }
98  
99 1057 ▶sub _inline_return_value {
Subroutine _inline_return_value: called CC=1 SCAR=0.0
100 1057 my $self = shift;
101 1057 my ($slot_access, $for_writer) = @_;
102  
103 1057 return 'return ' . $self->_return_value($slot_access, $for_writer) . ';';
104 }
105  
106 433 ▶sub _minimum_arguments { 0 }
Subroutine _minimum_arguments: called CC=1 SCAR=0.0
107 179 ▶sub _maximum_arguments { undef }
Subroutine _maximum_arguments: called CC=1 SCAR=0.0
108  
109 1067 ▶override _get_value => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
110 1067 my $self = shift;
111 1067 my ($instance) = @_;
112  
113 1067 ▶ return $self->_slot_access_can_be_inlined
Branch: 1 branch
BranchTrueFalseTotal
$self->_slot_access_can_be_inlined ? : 965 102 1067
114 ? super()
115 : $instance . '->$reader';
116 48 };
117  
118 295 ▶override _inline_store_value => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
119 295 my $self = shift;
120 295 my ($instance, $value) = @_;
121  
122 295 ▶ return $self->_slot_access_can_be_inlined
Branch: 1 branch
BranchTrueFalseTotal
$self->_slot_access_can_be_inlined ? : 232 63 295
123 ? super()
124 : $instance . '->$writer(' . $value . ');';
125 48 };
126  
127 1032 ▶override _eval_environment => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
128 1032 my $self = shift;
129  
130 1032 my $env = super();
131  
132 1032 $env->{'@curried'} = $self->curried_arguments;
133  
134 1032 ▶ return $env if $self->_slot_access_can_be_inlined;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_slot_access_can_be_inlined 930 102 1032
135  
136 102 my $reader = $self->associated_attribute->get_read_method_ref;
137 102 ▶ $reader = $reader->body if blessed $reader;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($reader) 102 0 102
138  
139 102 $env->{'$reader'} = \$reader;
140  
141 102 my $writer = $self->associated_attribute->get_write_method_ref;
142 102 ▶ $writer = $writer->body if blessed $writer;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($writer) 102 0 102
143  
144 102 $env->{'$writer'} = \$writer;
145  
146 102 return $env;
147 48 };
148  
149 2840 ▶sub _slot_access_can_be_inlined {
Subroutine _slot_access_can_be_inlined: called CC=2 SCAR=7.1
150 2840 my $self = shift;
151  
152 2840 ▶ return $self->is_inline && $self->_instance_is_inlinable;
Condition66%2/3
$self->is_inline && $self->_instance_is_inlinable
!ll&&!rl&&r
31902521
MC/DC50%1/2
$self->is_inline && $self->_instance_is_inlinable
$self->is_inline $self->_instance_is_inlinable
Truth table66%2/3
A && B
A= $self->is_inlineB= $self->_instance_is_inlinable
ABresult
0X0
100
111
153 }
154  
155 48 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
156  
157 48 1;
« blib/lib/Class/MOP/Mixin/AttributeCore.pm ↑ Summary blib/lib/Class/MOP/Object.pm »