Remove extra newline
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Hash / set.pm
CommitLineData
44babf1f 1package Moose::Meta::Method::Accessor::Native::Hash::set;
2
3use strict;
4use warnings;
5
6use Scalar::Util qw( looks_like_number );
7
10bd99ec 8our $VERSION = '1.14';
44babf1f 9$VERSION = eval $VERSION;
10our $AUTHORITY = 'cpan:STEVAN';
11
12use base 'Moose::Meta::Method::Accessor::Native::Hash::Writer';
13
14sub _minimum_arguments { 2 }
15
16sub _maximum_arguments { undef }
17
18sub _inline_check_argument_count {
19 my $self = shift;
20
21 return
22 $self->SUPER::_inline_check_argument_count(@_) . "\n"
23 . $self->_inline_throw_error(
24 q{'You must pass an even number of arguments to set'})
25 . ' if @_ % 2;';
26}
27
28sub _inline_process_arguments {
29 my $self = shift;
30
31 return 'my @keys_idx = grep { ! ($_ % 2) } 0..$#_;' . "\n"
32 . 'my @values_idx = grep { $_ % 2 } 0..$#_;';
33}
34
35sub _inline_check_arguments {
36 my $self = shift;
37
38 return
39 'for (@keys_idx) {' . "\n"
40 . $self->_inline_throw_error(
41 q{'Hash keys passed to set must be defined'})
42 . ' unless defined $_[$_];' . "\n" . '}';
43}
44
45sub _adds_members { 1 }
46
47sub _potential_value {
48 my ( $self, $slot_access ) = @_;
49
fe4e0a8c 50 return "{ %{ $slot_access }, \@_ }";
44babf1f 51}
52
53sub _new_members { '@_[ @values_idx ]' }
54
55sub _inline_optimized_set_new_value {
56 my ( $self, $inv, $new, $slot_access ) = @_;
57
584540d9 58 return "\@{ $slot_access }{ \@_[ \@keys_idx] } = \@_[ \@values_idx ]";
44babf1f 59}
60
611;