This commit is contained in:
41
CPAN/Moose/Meta/Method/Accessor/Native/Hash/Writer.pm
Normal file
41
CPAN/Moose/Meta/Method/Accessor/Native/Hash/Writer.pm
Normal file
@@ -0,0 +1,41 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::Writer;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Class::MOP::MiniTrait;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Writer',
|
||||
'Moose::Meta::Method::Accessor::Native::Hash',
|
||||
'Moose::Meta::Method::Accessor::Native::Collection';
|
||||
|
||||
sub _inline_coerce_new_values {
|
||||
my $self = shift;
|
||||
|
||||
return unless $self->associated_attribute->should_coerce;
|
||||
|
||||
return unless $self->_tc_member_type_can_coerce;
|
||||
|
||||
return <<'EOF';
|
||||
if (@_) {
|
||||
my %h = @_;
|
||||
@h{ sort keys %h } = map { $member_coercion->($_) } @h{ sort keys %h };
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
sub _new_members { 'values %{ { @_ } }' }
|
||||
|
||||
sub _copy_old_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = @_;
|
||||
|
||||
return '{ %{ (' . $slot_access . ') } }';
|
||||
}
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
61
CPAN/Moose/Meta/Method/Accessor/Native/Hash/accessor.pm
Normal file
61
CPAN/Moose/Meta/Method/Accessor/Native/Hash/accessor.pm
Normal file
@@ -0,0 +1,61 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::accessor;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Hash::set',
|
||||
'Moose::Meta::Method::Accessor::Native::Hash::get';
|
||||
|
||||
sub _inline_process_arguments {
|
||||
my $self = shift;
|
||||
$self->Moose::Meta::Method::Accessor::Native::Hash::set::_inline_process_arguments(@_);
|
||||
}
|
||||
|
||||
sub _inline_check_argument_count {
|
||||
my $self = shift;
|
||||
$self->Moose::Meta::Method::Accessor::Native::Hash::set::_inline_check_argument_count(@_);
|
||||
}
|
||||
|
||||
sub _inline_check_arguments {
|
||||
my $self = shift;
|
||||
$self->Moose::Meta::Method::Accessor::Native::Hash::set::_inline_check_arguments(@_);
|
||||
}
|
||||
|
||||
sub _return_value {
|
||||
my $self = shift;
|
||||
$self->Moose::Meta::Method::Accessor::Native::Hash::set::_return_value(@_);
|
||||
}
|
||||
|
||||
sub _generate_method {
|
||||
my $self = shift;
|
||||
|
||||
my $inv = '$self';
|
||||
my $slot_access = $self->_get_value($inv);
|
||||
|
||||
return (
|
||||
'sub {',
|
||||
'my ' . $inv . ' = shift;',
|
||||
$self->_inline_curried_arguments,
|
||||
$self->_inline_check_lazy($inv, '$type_constraint', '$type_coercion', '$type_message'),
|
||||
# get
|
||||
'if (@_ == 1) {',
|
||||
$self->_inline_check_var_is_valid_key('$_[0]'),
|
||||
$slot_access . '->{$_[0]}',
|
||||
'}',
|
||||
# set
|
||||
'else {',
|
||||
$self->_inline_writer_core($inv, $slot_access),
|
||||
'}',
|
||||
'}',
|
||||
);
|
||||
}
|
||||
|
||||
sub _minimum_arguments { 1 }
|
||||
sub _maximum_arguments { 2 }
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
37
CPAN/Moose/Meta/Method/Accessor/Native/Hash/clear.pm
Normal file
37
CPAN/Moose/Meta/Method/Accessor/Native/Hash/clear.pm
Normal file
@@ -0,0 +1,37 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::clear;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Hash::Writer';
|
||||
|
||||
sub _maximum_arguments { 0 }
|
||||
|
||||
sub _adds_members { 0 }
|
||||
|
||||
# The inner () in this expression is for the benefit of inlining code that
|
||||
# might end up looking like "values %{ {} }". This is a syntax error in perl
|
||||
# but 'values %{ { () } }' is not.
|
||||
sub _potential_value { '{ ( ) }' }
|
||||
|
||||
# There are no new members so we don't need to coerce new values (none exist)
|
||||
# and we always want to check the new (empty) hash as a whole.
|
||||
sub _inline_coerce_new_values { '' }
|
||||
|
||||
sub _check_new_members_only { 0 }
|
||||
|
||||
sub _inline_optimized_set_new_value {
|
||||
my $self = shift;
|
||||
my ($inv, $new, $slot_access) = @_;
|
||||
|
||||
return $slot_access . ' = {};';
|
||||
}
|
||||
|
||||
sub _return_value { '' }
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
22
CPAN/Moose/Meta/Method/Accessor/Native/Hash/count.pm
Normal file
22
CPAN/Moose/Meta/Method/Accessor/Native/Hash/count.pm
Normal file
@@ -0,0 +1,22 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::count;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Reader';
|
||||
|
||||
sub _maximum_arguments { 0 }
|
||||
|
||||
sub _return_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = @_;
|
||||
|
||||
return 'scalar keys %{ (' . $slot_access . ') }';
|
||||
}
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
31
CPAN/Moose/Meta/Method/Accessor/Native/Hash/defined.pm
Normal file
31
CPAN/Moose/Meta/Method/Accessor/Native/Hash/defined.pm
Normal file
@@ -0,0 +1,31 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::defined;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Reader',
|
||||
'Moose::Meta::Method::Accessor::Native::Hash';
|
||||
|
||||
sub _minimum_arguments { 1 }
|
||||
|
||||
sub _maximum_arguments { 1 }
|
||||
|
||||
sub _inline_check_arguments {
|
||||
my $self = shift;
|
||||
|
||||
return $self->_inline_check_var_is_valid_key('$_[0]');
|
||||
}
|
||||
|
||||
sub _return_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = @_;
|
||||
|
||||
return 'defined ' . $slot_access . '->{ $_[0] }';
|
||||
}
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
46
CPAN/Moose/Meta/Method/Accessor/Native/Hash/delete.pm
Normal file
46
CPAN/Moose/Meta/Method/Accessor/Native/Hash/delete.pm
Normal file
@@ -0,0 +1,46 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::delete;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Hash::Writer';
|
||||
|
||||
sub _adds_members { 0 }
|
||||
|
||||
# There are no new members so we don't need to coerce new values (none exist)
|
||||
# and we always want to check the new (empty) hash as a whole.
|
||||
sub _inline_coerce_new_values { '' }
|
||||
|
||||
sub _check_new_members_only { 0 }
|
||||
|
||||
sub _potential_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = @_;
|
||||
|
||||
return '(do { '
|
||||
. 'my %potential = %{ (' . $slot_access . ') }; '
|
||||
. '@return = delete @potential{@_}; '
|
||||
. '\%potential; '
|
||||
. '})';
|
||||
}
|
||||
|
||||
sub _inline_optimized_set_new_value {
|
||||
my $self = shift;
|
||||
my ($inv, $new, $slot_access) = @_;
|
||||
|
||||
return '@return = delete @{ (' . $slot_access . ') }{@_};';
|
||||
}
|
||||
|
||||
sub _return_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = @_;
|
||||
|
||||
return 'wantarray ? @return : $return[-1]';
|
||||
}
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
23
CPAN/Moose/Meta/Method/Accessor/Native/Hash/elements.pm
Normal file
23
CPAN/Moose/Meta/Method/Accessor/Native/Hash/elements.pm
Normal file
@@ -0,0 +1,23 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::elements;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Reader';
|
||||
|
||||
sub _maximum_arguments { 0 }
|
||||
|
||||
sub _return_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = @_;
|
||||
|
||||
return 'map { $_, ' . $slot_access . '->{$_} } '
|
||||
. 'keys %{ (' . $slot_access . ') }';
|
||||
}
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
31
CPAN/Moose/Meta/Method/Accessor/Native/Hash/exists.pm
Normal file
31
CPAN/Moose/Meta/Method/Accessor/Native/Hash/exists.pm
Normal file
@@ -0,0 +1,31 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::exists;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Reader',
|
||||
'Moose::Meta::Method::Accessor::Native::Hash';
|
||||
|
||||
sub _minimum_arguments { 1 }
|
||||
|
||||
sub _maximum_arguments { 1 }
|
||||
|
||||
sub _inline_check_arguments {
|
||||
my $self = shift;
|
||||
|
||||
return $self->_inline_check_var_is_valid_key('$_[0]');
|
||||
}
|
||||
|
||||
sub _return_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = shift;
|
||||
|
||||
return 'exists ' . $slot_access . '->{ $_[0] }';
|
||||
}
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
35
CPAN/Moose/Meta/Method/Accessor/Native/Hash/get.pm
Normal file
35
CPAN/Moose/Meta/Method/Accessor/Native/Hash/get.pm
Normal file
@@ -0,0 +1,35 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::get;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Reader',
|
||||
'Moose::Meta::Method::Accessor::Native::Hash';
|
||||
|
||||
sub _minimum_arguments { 1 }
|
||||
|
||||
sub _inline_check_arguments {
|
||||
my $self = shift;
|
||||
|
||||
return (
|
||||
'for (@_) {',
|
||||
$self->_inline_check_var_is_valid_key('$_'),
|
||||
'}',
|
||||
);
|
||||
}
|
||||
|
||||
sub _return_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = @_;
|
||||
|
||||
return '@_ > 1 '
|
||||
. '? @{ (' . $slot_access . ') }{@_} '
|
||||
. ': ' . $slot_access . '->{$_[0]}';
|
||||
}
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
22
CPAN/Moose/Meta/Method/Accessor/Native/Hash/is_empty.pm
Normal file
22
CPAN/Moose/Meta/Method/Accessor/Native/Hash/is_empty.pm
Normal file
@@ -0,0 +1,22 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::is_empty;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Reader';
|
||||
|
||||
sub _maximum_arguments { 0 }
|
||||
|
||||
sub _return_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = @_;
|
||||
|
||||
return 'scalar keys %{ (' . $slot_access . ') } ? 0 : 1';
|
||||
}
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
22
CPAN/Moose/Meta/Method/Accessor/Native/Hash/keys.pm
Normal file
22
CPAN/Moose/Meta/Method/Accessor/Native/Hash/keys.pm
Normal file
@@ -0,0 +1,22 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::keys;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Reader';
|
||||
|
||||
sub _maximum_arguments { 0 }
|
||||
|
||||
sub _return_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = @_;
|
||||
|
||||
return 'keys %{ (' . $slot_access . ') }';
|
||||
}
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
23
CPAN/Moose/Meta/Method/Accessor/Native/Hash/kv.pm
Normal file
23
CPAN/Moose/Meta/Method/Accessor/Native/Hash/kv.pm
Normal file
@@ -0,0 +1,23 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::kv;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Reader';
|
||||
|
||||
sub _maximum_arguments { 0 }
|
||||
|
||||
sub _return_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = @_;
|
||||
|
||||
return 'map { [ $_, ' . $slot_access . '->{$_} ] } '
|
||||
. 'keys %{ (' . $slot_access . ') }';
|
||||
}
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
99
CPAN/Moose/Meta/Method/Accessor/Native/Hash/set.pm
Normal file
99
CPAN/Moose/Meta/Method/Accessor/Native/Hash/set.pm
Normal file
@@ -0,0 +1,99 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::set;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use List::Util 1.32;
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Hash::Writer';
|
||||
|
||||
sub _minimum_arguments { 2 }
|
||||
|
||||
sub _maximum_arguments { undef }
|
||||
|
||||
around _inline_check_argument_count => sub {
|
||||
my $orig = shift;
|
||||
my $self = shift;
|
||||
|
||||
return (
|
||||
$self->$orig(@_),
|
||||
'if (@_ % 2) {',
|
||||
$self->_inline_throw_exception( MustPassEvenNumberOfArguments =>
|
||||
"method_name => '".$self->delegate_to_method."',".
|
||||
'args => \@_',
|
||||
) . ';',
|
||||
'}',
|
||||
);
|
||||
};
|
||||
|
||||
sub _inline_process_arguments {
|
||||
my $self = shift;
|
||||
|
||||
return (
|
||||
'my @keys_idx = grep { ! ($_ % 2) } 0..$#_;',
|
||||
'my @values_idx = grep { $_ % 2 } 0..$#_;',
|
||||
);
|
||||
}
|
||||
|
||||
sub _inline_check_arguments {
|
||||
my $self = shift;
|
||||
|
||||
return (
|
||||
'for (@keys_idx) {',
|
||||
'if (!defined($_[$_])) {',
|
||||
$self->_inline_throw_exception( UndefinedHashKeysPassedToMethod =>
|
||||
'hash_keys => \@keys_idx,'.
|
||||
"method_name => '".$self->delegate_to_method."'",
|
||||
) . ';',
|
||||
'}',
|
||||
'}',
|
||||
);
|
||||
}
|
||||
|
||||
sub _adds_members { 1 }
|
||||
|
||||
# We need to override this because while @_ can be written to, we cannot write
|
||||
# directly to $_[1].
|
||||
sub _inline_coerce_new_values {
|
||||
my $self = shift;
|
||||
|
||||
return unless $self->associated_attribute->should_coerce;
|
||||
|
||||
return unless $self->_tc_member_type_can_coerce;
|
||||
|
||||
# Is there a simpler way to do this?
|
||||
return (
|
||||
'@_ = List::Util::pairmap { $a => $member_coercion->($b) } @_;',
|
||||
);
|
||||
};
|
||||
|
||||
sub _potential_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = @_;
|
||||
|
||||
return '{ %{ (' . $slot_access . ') }, @_ }';
|
||||
}
|
||||
|
||||
sub _new_members { '@_[ @values_idx ]' }
|
||||
|
||||
sub _inline_optimized_set_new_value {
|
||||
my $self = shift;
|
||||
my ($inv, $new, $slot_access) = @_;
|
||||
|
||||
return '@{ (' . $slot_access . ') }{ @_[@keys_idx] } = @_[@values_idx];';
|
||||
}
|
||||
|
||||
sub _return_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = @_;
|
||||
|
||||
return 'wantarray '
|
||||
. '? @{ (' . $slot_access . ') }{ @_[@keys_idx] } '
|
||||
. ': ' . $slot_access . '->{ $_[$keys_idx[0]] }';
|
||||
}
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
26
CPAN/Moose/Meta/Method/Accessor/Native/Hash/shallow_clone.pm
Normal file
26
CPAN/Moose/Meta/Method/Accessor/Native/Hash/shallow_clone.pm
Normal file
@@ -0,0 +1,26 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::shallow_clone;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Params::Util ();
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Reader';
|
||||
|
||||
sub _minimum_arguments { 0 }
|
||||
|
||||
sub _maximum_arguments { 0 }
|
||||
|
||||
sub _return_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = @_;
|
||||
|
||||
return '{ %{ (' . $slot_access . ') } }';
|
||||
}
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
22
CPAN/Moose/Meta/Method/Accessor/Native/Hash/values.pm
Normal file
22
CPAN/Moose/Meta/Method/Accessor/Native/Hash/values.pm
Normal file
@@ -0,0 +1,22 @@
|
||||
package Moose::Meta::Method::Accessor::Native::Hash::values;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
with 'Moose::Meta::Method::Accessor::Native::Reader';
|
||||
|
||||
sub _maximum_arguments { 0 }
|
||||
|
||||
sub _return_value {
|
||||
my $self = shift;
|
||||
my ($slot_access) = @_;
|
||||
|
||||
return 'values %{ (' . $slot_access . ') }';
|
||||
}
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user