| 1 | package Moose::Meta::Method::Accessor::Native::Collection; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 17 | our $VERSION = '2.4001'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 17 | requires qw( _adds_members _new_members ); | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 208 | ▶ | sub _inline_coerce_new_values { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inline_coerce_new_values: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 208 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 208 | ▶ | return unless $self->associated_attribute->should_coerce; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 21 | ▶ | return unless $self->_tc_member_type_can_coerce; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | '(' . $self->_new_members . ') = map { $member_coercion->($_) }', | |||||||||||||||||||||||||||||||||||||||||
| 20 | $self->_new_members . ';', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 47 | ▶ | sub _tc_member_type_can_coerce { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tc_member_type_can_coerce: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 47 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 47 | my $member_tc = $self->_tc_member_type; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 47 | ▶ | return $member_tc && $member_tc->has_coercion; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$member_tc && $member_tc->has_coercion
MC/DC100%2/2
$member_tc && $member_tc->has_coercion
$member_tc
$member_tc->has_coercion
Truth table100%3/3
A && B
A= $member_tcB= $member_tc->has_coercion
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 686 | ▶ | sub _tc_member_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tc_member_type: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 686 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 686 | my $tc = $self->associated_attribute->type_constraint; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 686 | ▶ | while ($tc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1436 | ▶ | return $tc->type_parameter | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | if $tc->can('type_parameter'); | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 904 | $tc = $tc->parent; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 154 | return; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub _writer_value_needs_copy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_writer_value_needs_copy: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return $self->_constraint_must_be_checked | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->_constraint_must_be_checked && !$self->_check_new_members_only
MC/DC0%0/2
$self->_constraint_must_be_checked && !$self->_check_new_members_only
$self->_constraint_must_be_checked
!$self->_check_new_members_only
Truth table0%0/3
A && not(B)
A= $self->_constraint_must_be_checkedB= !$self->_check_new_members_only
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | && !$self->_check_new_members_only; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 271 | ▶ | sub _inline_tc_code { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inline_tc_code: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 271 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 271 | my ($value, $tc, $coercion, $message, $is_lazy) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 271 | ▶ | return unless $self->_constraint_must_be_checked; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 271 | ▶ | if ($self->_check_new_members_only) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 174 | ▶ | return unless $self->_adds_members; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 141 | return $self->_inline_check_member_constraint($self->_new_members); | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 97 | $self->_inline_check_coercion($value, $tc, $coercion, $is_lazy), | |||||||||||||||||||||||||||||||||||||||||
| 66 | $self->_inline_check_constraint($value, $tc, $message, $is_lazy), | ||||||||||||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 253 | ▶ | sub _check_new_members_only { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_new_members_only: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 253 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 253 | my $attr = $self->associated_attribute; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 253 | my $tc = $attr->type_constraint; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | # If we have a coercion, we could come up with an entirely new value after | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # coercing, so we need to check everything, | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 253 | ▶ | return 0 if $attr->should_coerce && $tc->has_coercion; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$attr->should_coerce and $tc->has_coercion
MC/DC50%1/2
$attr->should_coerce and $tc->has_coercion
$attr->should_coerce
$tc->has_coercion
Truth table66%2/3
A and B
A= $attr->should_coerceB= $tc->has_coercion
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # If the parent is our root type (ArrayRef, HashRef, etc), that means we | ||||||||||||||||||||||||||||||||||||||||||
| 83 | # can just check the new members of the collection, because we know that | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # we will always be generating an appropriate collection type. | ||||||||||||||||||||||||||||||||||||||||||
| 85 | # | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # However, if this type has its own constraint (it's Parameteriz_able_, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # not Paramet_erized_), we don't know what is being checked by the | ||||||||||||||||||||||||||||||||||||||||||
| 88 | # constraint, so we need to check the whole value, not just the members. | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 206 | ▶ | return 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->_is_root_type($tc->parent) and $tc->isa("Moose::Meta::TypeConstraint::Parameterized") || !$tc->can("parameterize")
$tc->isa("Moose::Meta::TypeConstraint::Parameterized") or not $tc->can("parameterize")
MC/DC66%2/3
$self->_is_root_type($tc->parent) and $tc->isa("Moose::Meta::TypeConstraint::Parameterized") || !$tc->can("parameterize")
$self->_is_root_type($tc->parent)
$tc->isa("Moose::Meta::TypeConstraint::Parameterized")
not $tc->can("parameterize")
Truth table75%3/4
A and B or not(C)
A= $self->_is_root_type($tc->parent)B= $tc->isa("Moose::Meta::TypeConstraint::Parameterized")C= not $tc->can("parameterize")
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | if $self->_is_root_type( $tc->parent ) | ||||||||||||||||||||||||||||||||||||||||||
| 91 | && ( $tc->isa('Moose::Meta::TypeConstraint::Parameterized') | ||||||||||||||||||||||||||||||||||||||||||
| 92 | || !$tc->can('parameterize') ); | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 32 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 141 | ▶ | sub _inline_check_member_constraint { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inline_check_member_constraint: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 141 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 141 | my ($new_value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 141 | my $attr_name = $self->associated_attribute->name; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 141 | ▶ | my $check | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | = $self->_tc_member_type->can_be_inlined | ||||||||||||||||||||||||||||||||||||||||||
| 105 | ? '! (' . $self->_tc_member_type->_inline_check('$new_val') . ')' | ||||||||||||||||||||||||||||||||||||||||||
| 106 | : ' !$member_tc->($new_val) '; | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 141 | 'for my $new_val (' . $new_value . ') {', | |||||||||||||||||||||||||||||||||||||||||
| 110 | "if ($check) {", | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 'my $msg = do { local $_ = $new_val; $member_message->($new_val) };'. | ||||||||||||||||||||||||||||||||||||||||||
| 112 | $self->_inline_throw_exception( ValidationFailedForInlineTypeConstraint => | ||||||||||||||||||||||||||||||||||||||||||
| 113 | "attribute_name => '".$attr_name."',". | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 'type_constraint_message => $msg,'. | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 'class_name => $class_name,'. | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 'value => $new_val,'. | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 'new_member => 1', | ||||||||||||||||||||||||||||||||||||||||||
| 118 | ) . ';', | ||||||||||||||||||||||||||||||||||||||||||
| 119 | '}', | ||||||||||||||||||||||||||||||||||||||||||
| 120 | '}', | ||||||||||||||||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 357 | ▶ | sub _inline_get_old_value_for_trigger { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inline_get_old_value_for_trigger: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 357 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 357 | my ($instance, $old) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 357 | my $attr = $self->associated_attribute; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 357 | ▶ | return unless $attr->has_trigger; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 35 | 'my ' . $old . ' = ' . $self->_has_value($instance), | |||||||||||||||||||||||||||||||||||||||||
| 133 | '? ' . $self->_copy_old_value($self->_get_value($instance)), | ||||||||||||||||||||||||||||||||||||||||||
| 134 | ': ();', | ||||||||||||||||||||||||||||||||||||||||||
| 135 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 357 | ▶ | around _eval_environment => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 357 | my $orig = shift; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 357 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 357 | my $env = $self->$orig(@_); | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 357 | my $member_tc = $self->_tc_member_type; | |||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 357 | ▶ | return $env unless $member_tc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 217 | $env->{'$member_tc'} = \( $member_tc->_compiled_type_constraint ); | |||||||||||||||||||||||||||||||||||||||||
| 149 | 217 | ▶ | $env->{'$member_coercion'} = \( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | $member_tc->coercion->_compiled_type_coercion | ||||||||||||||||||||||||||||||||||||||||||
| 151 | ) if $member_tc->has_coercion; | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 217 | ▶ | $env->{'$member_message'} = \( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | $member_tc->has_message | ||||||||||||||||||||||||||||||||||||||||||
| 154 | ? $member_tc->message | ||||||||||||||||||||||||||||||||||||||||||
| 155 | : $member_tc->_default_message | ||||||||||||||||||||||||||||||||||||||||||
| 156 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 217 | my $tc_env = $member_tc->inline_environment(); | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 217 | $env = { %{$env}, %{$tc_env} }; | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 217 | return $env; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 17 | }; | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 17 | ▶ | no Moose::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||