| 1 | package Moose::Meta::Method::Accessor::Native::Hash::set; | ||||||||||
| 2 | 7 | our $VERSION = '2.4001'; | |||||||||
| 3 | |||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 7 | ▶ | use List::Util 1.32; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 7 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 7 | with 'Moose::Meta::Method::Accessor::Native::Hash::Writer'; | |||||||||
| 11 | |||||||||||
| 12 | 20 | ▶ | sub _minimum_arguments { 2 } | ||||||||
|
Subroutine
_minimum_arguments: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 20 | ▶ | sub _maximum_arguments { undef } | ||||||||
|
Subroutine
_maximum_arguments: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 43 | ▶ | around _inline_check_argument_count => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 43 | my $orig = shift; | |||||||||
| 18 | 43 | my $self = shift; | |||||||||
| 19 | |||||||||||
| 20 | return ( | ||||||||||
| 21 | 43 | $self->$orig(@_), | |||||||||
| 22 | 'if (@_ % 2) {', | ||||||||||
| 23 | $self->_inline_throw_exception( MustPassEvenNumberOfArguments => | ||||||||||
| 24 | "method_name => '".$self->delegate_to_method."',". | ||||||||||
| 25 | 'args => \@_', | ||||||||||
| 26 | ) . ';', | ||||||||||
| 27 | '}', | ||||||||||
| 28 | ); | ||||||||||
| 29 | 7 | }; | |||||||||
| 30 | |||||||||||
| 31 | 43 | ▶ | sub _inline_process_arguments { | ||||||||
|
Subroutine
_inline_process_arguments: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 43 | my $self = shift; | |||||||||
| 33 | |||||||||||
| 34 | return ( | ||||||||||
| 35 | 43 | 'my @keys_idx = grep { ! ($_ % 2) } 0..$#_;', | |||||||||
| 36 | 'my @values_idx = grep { $_ % 2 } 0..$#_;', | ||||||||||
| 37 | ); | ||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 43 | ▶ | sub _inline_check_arguments { | ||||||||
|
Subroutine
_inline_check_arguments: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 43 | my $self = shift; | |||||||||
| 42 | |||||||||||
| 43 | return ( | ||||||||||
| 44 | 43 | 'for (@keys_idx) {', | |||||||||
| 45 | 'if (!defined($_[$_])) {', | ||||||||||
| 46 | $self->_inline_throw_exception( UndefinedHashKeysPassedToMethod => | ||||||||||
| 47 | 'hash_keys => \@keys_idx,'. | ||||||||||
| 48 | "method_name => '".$self->delegate_to_method."'", | ||||||||||
| 49 | ) . ';', | ||||||||||
| 50 | '}', | ||||||||||
| 51 | '}', | ||||||||||
| 52 | ); | ||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 15 | ▶ | sub _adds_members { 1 } | ||||||||
|
Subroutine
_adds_members: called CC=1 SCAR=0.0
| |||||||||||
| 56 | |||||||||||
| 57 | # We need to override this because while @_ can be written to, we cannot write | ||||||||||
| 58 | # directly to $_[1]. | ||||||||||
| 59 | 43 | ▶ | sub _inline_coerce_new_values { | ||||||||
|
Subroutine
_inline_coerce_new_values: called CC=3 SCAR=11.0
| |||||||||||
| 60 | 43 | my $self = shift; | |||||||||
| 61 | |||||||||||
| 62 | 43 | ▶ | return unless $self->associated_attribute->should_coerce; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | |||||||||||
| 64 | 11 | ▶ | return unless $self->_tc_member_type_can_coerce; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | |||||||||||
| 66 | # Is there a simpler way to do this? | ||||||||||
| 67 | return ( | ||||||||||
| 68 | 4 | '@_ = List::Util::pairmap { $a => $member_coercion->($b) } @_;', | |||||||||
| 69 | ); | ||||||||||
| 70 | }; | ||||||||||
| 71 | |||||||||||
| 72 | 43 | ▶ | sub _potential_value { | ||||||||
|
Subroutine
_potential_value: called CC=1 SCAR=0.0
| |||||||||||
| 73 | 43 | my $self = shift; | |||||||||
| 74 | 43 | my ($slot_access) = @_; | |||||||||
| 75 | |||||||||||
| 76 | 43 | return '{ %{ (' . $slot_access . ') }, @_ }'; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 15 | ▶ | sub _new_members { '@_[ @values_idx ]' } | ||||||||
|
Subroutine
_new_members: called CC=1 SCAR=0.0
| |||||||||||
| 80 | |||||||||||
| 81 | 26 | ▶ | sub _inline_optimized_set_new_value { | ||||||||
|
Subroutine
_inline_optimized_set_new_value: called CC=1 SCAR=0.0
| |||||||||||
| 82 | 26 | my $self = shift; | |||||||||
| 83 | 26 | my ($inv, $new, $slot_access) = @_; | |||||||||
| 84 | |||||||||||
| 85 | 26 | return '@{ (' . $slot_access . ') }{ @_[@keys_idx] } = @_[@values_idx];'; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 86 | ▶ | sub _return_value { | ||||||||
|
Subroutine
_return_value: called CC=1 SCAR=0.0
| |||||||||||
| 89 | 86 | my $self = shift; | |||||||||
| 90 | 86 | my ($slot_access) = @_; | |||||||||
| 91 | |||||||||||
| 92 | 86 | return 'wantarray ' | |||||||||
| 93 | . '? @{ (' . $slot_access . ') }{ @_[@keys_idx] } ' | ||||||||||
| 94 | . ': ' . $slot_access . '->{ $_[$keys_idx[0]] }'; | ||||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 7 | ▶ | no Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 98 | |||||||||||
| 99 | 7 | 1; | |||||||||