From: Jesse Luehrs Date: Sun, 31 Oct 2010 20:45:47 +0000 (-0500) Subject: more cleanups X-Git-Tag: 1.9900~39 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1e2c801e852e22b0ab5af1efc34667710ba952de;p=gitmo%2FMoose.git more cleanups --- diff --git a/lib/Moose/Meta/Method/Accessor.pm b/lib/Moose/Meta/Method/Accessor.pm index a369d87..a3aaa90 100644 --- a/lib/Moose/Meta/Method/Accessor.pm +++ b/lib/Moose/Meta/Method/Accessor.pm @@ -58,7 +58,7 @@ sub _generate_accessor_method_inline { my $self = shift; my $inv = '$_[0]'; - my $slot_access = $self->_inline_get($inv); + my $slot_access = $self->_get_value($inv); my $value = $self->_value_needs_copy ? '$val' : '$_[1]'; my $old = '@old'; @@ -70,12 +70,12 @@ sub _generate_accessor_method_inline { $self->_inline_check_required, $self->_inline_tc_code($value), $self->_inline_get_old_value_for_trigger($inv, $old), - $self->_inline_store($inv, $value), + $self->_inline_store_value($inv, $value), $self->_inline_trigger($inv, $value, $old), '}', $self->_inline_check_lazy($inv), $self->_inline_post_body(@_), - 'return ' . $self->_inline_auto_deref($slot_access) . ';', + $self->_inline_return_auto_deref($slot_access), '}', ]); } @@ -94,7 +94,7 @@ sub _generate_writer_method_inline { $self->_inline_check_required, $self->_inline_tc_code($value), $self->_inline_get_old_value_for_trigger($inv, $old), - $self->_inline_store($inv, $value), + $self->_inline_store_value($inv, $value), $self->_inline_post_body(@_), $self->_inline_trigger($inv, $value, $old), '}', @@ -105,7 +105,7 @@ sub _generate_reader_method_inline { my $self = shift; my $inv = '$_[0]'; - my $slot_access = $self->_inline_get($inv); + my $slot_access = $self->_get_value($inv); $self->_compile_code([ 'sub {', @@ -118,7 +118,7 @@ sub _generate_reader_method_inline { '}', $self->_inline_check_lazy($inv), $self->_inline_post_body(@_), - 'return ' . $self->_inline_auto_deref($slot_access) . ';', + $self->_inline_return_auto_deref($slot_access), '}', ]); } @@ -127,7 +127,7 @@ sub _inline_copy_value { my $self = shift; my ($value) = @_; - return '' unless $self->_value_needs_copy; + return unless $self->_value_needs_copy; return 'my ' . $value . ' = $_[1];' } @@ -174,30 +174,32 @@ sub _generate_clearer_method { sub _inline_pre_body { return } sub _inline_post_body { return } +sub _inline_tc_code { + my $self = shift; + return ( + $self->_inline_check_coercion(@_), + $self->_inline_check_constraint(@_), + ); +} + sub _inline_check_constraint { my $self = shift; my ($value) = @_; my $attr = $self->associated_attribute; - return '' unless $attr->has_type_constraint; - - my $attr_name = quotemeta( $attr->name ); - - return 'if (!$type_constraint->(' . $value . ')) {', - $self->_inline_throw_error( - '"Attribute (' . $attr_name . ') does not pass the type ' - . 'constraint because: " . ' - . '$type_constraint_obj->get_message(' . $value . ')', - 'data => ' . $value - ) . ';', - '}'; -} + return unless $attr->has_type_constraint; + + my $attr_name = quotemeta($attr->name); -sub _inline_tc_code { - my $self = shift; return ( - $self->_inline_check_coercion(@_), - $self->_inline_check_constraint(@_), + 'if (!$type_constraint->(' . $value . ')) {', + $self->_inline_throw_error( + '"Attribute (' . $attr_name . ') does not pass the type ' + . 'constraint because: " . ' + . '$type_constraint_obj->get_message(' . $value . ')', + 'data => ' . $value + ) . ';', + '}', ); } @@ -206,8 +208,7 @@ sub _inline_check_coercion { my ($value) = @_; my $attr = $self->associated_attribute; - return '' unless $attr->should_coerce - && $attr->type_constraint->has_coercion; + return unless $attr->should_coerce && $attr->type_constraint->has_coercion; return $value . ' = $type_constraint_obj->coerce(' . $value . ');'; } @@ -216,16 +217,18 @@ sub _inline_check_required { my $self = shift; my $attr = $self->associated_attribute; - return '' unless $attr->is_required; + return unless $attr->is_required; - my $attr_name = quotemeta( $attr->name ); + my $attr_name = quotemeta($attr->name); - return 'if (@_ < 2) {', - $self->_inline_throw_error( - '"Attribute (' . $attr_name . ') is required, so cannot ' - . 'be set to undef"' # defined $_[1] is not good enough - ) . ';', - '}'; + return ( + 'if (@_ < 2) {', + $self->_inline_throw_error( + '"Attribute (' . $attr_name . ') is required, so cannot ' + . 'be set to undef"' # defined $_[1] is not good enough + ) . ';', + '}', + ); } sub _inline_check_lazy { @@ -235,11 +238,13 @@ sub _inline_check_lazy { my $attr = $self->associated_attribute; return unless $attr->is_lazy; - my $slot_exists = $self->_inline_has($instance); + my $slot_exists = $self->_has_value($instance); - return 'if (!' . $slot_exists . ') {', - $self->_inline_init_from_default($instance, '$default', 'lazy'), - '}'; + return ( + 'if (!' . $slot_exists . ') {', + $self->_inline_init_from_default($instance, '$default', 'lazy'), + '}', + ); } sub _inline_init_from_default { @@ -251,16 +256,17 @@ sub _inline_init_from_default { return $self->_inline_init_slot($attr, $instance, 'undef') unless $attr->has_default || $attr->has_builder; - return $self->_inline_generate_default($instance, $default), - $attr->has_type_constraint - # intentionally not using _inline_tc_code, since that can be - # overridden to do things like possibly only do member tc - # checks, which isn't appropriate for checking the result - # of a default - ? ($self->_inline_check_coercion($default, $for_lazy), - $self->_inline_check_constraint($default, $for_lazy)) - : (), - $self->_inline_init_slot($attr, $instance, $default); + return ( + $self->_inline_generate_default($instance, $default), + # intentionally not using _inline_tc_code, since that can be overridden + # to do things like possibly only do member tc checks, which isn't + # appropriate for checking the result of a default + $attr->has_type_constraint + ? ($self->_inline_check_coercion($default, $for_lazy), + $self->_inline_check_constraint($default, $for_lazy)) + : (), + $self->_inline_init_slot($attr, $instance, $default), + ); } sub _inline_generate_default { @@ -273,23 +279,27 @@ sub _inline_generate_default { return 'my ' . $default . ' = $attr->default(' . $instance . ');'; } elsif ($attr->has_builder) { - return 'my ' . $default . ';', - 'if (my $builder = ' . $instance . '->can($attr->builder)) {', - $default . ' = ' . $instance . '->$builder;', - '}', - 'else {', - 'my $class = ref(' . $instance . ') || ' . $instance . ';', - 'my $builder_name = $attr->builder;', - 'my $attr_name = $attr->name;', - $self->_inline_throw_error( - '"$class does not support builder method ' - . '\'$builder_name\' for attribute \'$attr_name\'"' - ) . ';', - '}'; + return ( + 'my ' . $default . ';', + 'if (my $builder = ' . $instance . '->can($attr->builder)) {', + $default . ' = ' . $instance . '->$builder;', + '}', + 'else {', + 'my $class = ref(' . $instance . ') || ' . $instance . ';', + 'my $builder_name = $attr->builder;', + 'my $attr_name = $attr->name;', + $self->_inline_throw_error( + '"$class does not support builder method ' + . '\'$builder_name\' for attribute \'$attr_name\'"' + ) . ';', + '}', + ); } else { - $self->throw_error("Can't generate a default for " . $attr->name - . " since no default or builder was specified"); + $self->throw_error( + "Can't generate a default for " . $attr->name + . " since no default or builder was specified" + ); } } @@ -301,15 +311,15 @@ sub _inline_init_slot { return '$attr->set_initial_value(' . $inv . ', ' . $value . ');'; } else { - return $self->_inline_store($inv, $value) . ';'; + return $self->_inline_store_value($inv, $value); } } -sub _inline_store { +sub _inline_store_value { my $self = shift; - my ($instance, $value) = @_; + my ($inv, $value) = @_; - return $self->associated_attribute->inline_set( $instance, $value ) . ';'; + return $self->_store_value($inv, $value) . ';'; } sub _inline_get_old_value_for_trigger { @@ -317,11 +327,13 @@ sub _inline_get_old_value_for_trigger { my ($instance, $old) = @_; my $attr = $self->associated_attribute; - return '' unless $attr->has_trigger; + return unless $attr->has_trigger; - return 'my ' . $old . ' = ' . $self->_inline_has($instance) - . ' ? ' . $self->_inline_get($instance) - . ' : ();'; + return ( + 'my ' . $old . ' = ' . $self->_has_value($instance), + '? ' . $self->_get_value($instance), + ': ();', + ); } sub _inline_trigger { @@ -329,26 +341,39 @@ sub _inline_trigger { my ($instance, $value, $old) = @_; my $attr = $self->associated_attribute; - return '' unless $attr->has_trigger; + return unless $attr->has_trigger; + + return '$attr->trigger->(' . $instance . ', ' . $value . ', ' . $old . ');'; +} + +sub _inline_return_auto_deref { + my $self = shift; - return sprintf('$attr->trigger->(%s, %s, %s);', $instance, $value, $old); + return 'return ' . $self->_auto_deref(@_) . ';'; } # expressions -sub _inline_get { +sub _store_value { + my $self = shift; + my ($instance, $value) = @_; + + return $self->associated_attribute->inline_set($instance, $value) . ';'; +} + +sub _get_value { my ($self, $instance) = @_; return $self->associated_attribute->inline_get($instance); } -sub _inline_has { +sub _has_value { my ($self, $instance) = @_; return $self->associated_attribute->inline_has($instance); } -sub _inline_auto_deref { +sub _auto_deref { my $self = shift; my ($ref_value) = @_; @@ -366,14 +391,16 @@ sub _inline_auto_deref { } else { $self->throw_error( - "Can not auto de-reference the type constraint '" + 'Can not auto de-reference the type constraint \'' . $type_constraint->name - . "'", + . '\'', type_constraint => $type_constraint, ); } - "(wantarray() ? $sigil\{ ( $ref_value ) || return } : ( $ref_value ) )"; + return 'wantarray ' + . '? ' . $sigil . '{ (' . $ref_value . ') || return } ' + . ': (' . $ref_value . ')'; } 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native.pm b/lib/Moose/Meta/Method/Accessor/Native.pm index 49d214b..e9ccde7 100644 --- a/lib/Moose/Meta/Method/Accessor/Native.pm +++ b/lib/Moose/Meta/Method/Accessor/Native.pm @@ -17,13 +17,12 @@ around new => sub { my $class = shift; my %options = @_; - exists $options{curried_arguments} - || ( $options{curried_arguments} = [] ); + $options{curried_arguments} = [] + unless exists $options{curried_arguments}; - ( $options{curried_arguments} - && ( 'ARRAY' eq ref $options{curried_arguments} ) ) - || confess - 'You must supply a curried_arguments which is an ARRAY reference'; + confess 'You must supply a curried_arguments which is an ARRAY reference' + unless $options{curried_arguments} + && ref($options{curried_arguments}) eq 'ARRAY'; $options{definition_context} = $options{attribute}->definition_context; @@ -54,7 +53,7 @@ sub _inline_curried_arguments { return unless @{ $self->curried_arguments }; - return ('unshift @_, @curried;'); + return 'unshift @_, @curried;'; } sub _inline_check_argument_count { @@ -99,15 +98,13 @@ sub _inline_return_value { my $self = shift; my ($slot_access, $for_writer) = @_; - return ( - 'return ' . $self->_return_value($slot_access, $for_writer) . ';', - ); + return 'return ' . $self->_return_value($slot_access, $for_writer) . ';'; } sub _minimum_arguments { 0 } sub _maximum_arguments { undef } -override _inline_get => sub { +override _get_value => sub { my $self = shift; my ($instance) = @_; @@ -116,7 +113,7 @@ override _inline_get => sub { : $instance . '->$reader'; }; -override _inline_store => sub { +override _store_value => sub { my $self = shift; my ($instance, $value) = @_; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array.pm b/lib/Moose/Meta/Method/Accessor/Native/Array.pm index 0eb17a3..8940384 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array.pm @@ -18,8 +18,7 @@ sub _inline_check_var_is_valid_index { return ( 'if (!defined(' . $var . ') || ' . $var . ' !~ /^-?\d+$/) {', $self->_inline_throw_error( - '"The index passed to ' - . $self->delegate_to_method + '"The index passed to ' . $self->delegate_to_method . ' must be an integer"', ) . ';', '}', diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/Writer.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/Writer.pm index 31bd29f..2247833 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/Writer.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/Writer.pm @@ -15,9 +15,9 @@ with 'Moose::Meta::Method::Accessor::Native::Writer' => { 'Moose::Meta::Method::Accessor::Native::Array', 'Moose::Meta::Method::Accessor::Native::Collection'; -sub _new_members {'@_'} +sub _new_members { '@_' } -sub _inline_copy_old_value { +sub _copy_old_value { my $self = shift; my ($slot_access) = @_; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/accessor.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/accessor.pm index 393fc1f..5d3fdab 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/accessor.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/accessor.pm @@ -33,7 +33,7 @@ sub _generate_method { my $self = shift; my $inv = '$self'; - my $slot_access = $self->_inline_get($inv); + my $slot_access = $self->_get_value($inv); return ( 'sub {', @@ -48,15 +48,15 @@ sub _generate_method { '}', # set 'else {', - $self->_writer_core($inv, $slot_access), + $self->_inline_writer_core($inv, $slot_access), $self->_inline_post_body(@_), '}', '}', ); } -sub _minimum_arguments {1} -sub _maximum_arguments {2} +sub _minimum_arguments { 1 } +sub _maximum_arguments { 2 } no Moose::Role; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/clear.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/clear.pm index e73384c..1e02731 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/clear.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/clear.pm @@ -23,7 +23,7 @@ sub _maximum_arguments { 0 } sub _adds_members { 0 } -sub _potential_value { return '[]' } +sub _potential_value { '[]' } sub _optimized_set_new_value { my $self = shift; @@ -32,7 +32,7 @@ sub _optimized_set_new_value { return $slot_access . ' = []'; } -sub _return_value { return '' } +sub _return_value { '' } no Moose::Role; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/first.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/first.pm index bb3b687..5d4482b 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/first.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/first.pm @@ -42,7 +42,7 @@ sub _return_value { my $self = shift; my ($slot_access) = @_; - return '&List::Util::first( $_[0], @{ (' . $slot_access . ') } )'; + return '&List::Util::first($_[0], @{ (' . $slot_access . ') })'; } no Moose::Role; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/natatime.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/natatime.pm index 37f73ba..b2ced02 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/natatime.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/natatime.pm @@ -23,9 +23,9 @@ with 'Moose::Meta::Method::Accessor::Native::Reader' => { ] }; -sub _minimum_arguments {1} +sub _minimum_arguments { 1 } -sub _maximum_arguments {2} +sub _maximum_arguments { 2 } sub _inline_check_arguments { my $self = shift; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/sort_in_place.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/sort_in_place.pm index a11c082..83549a8 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/sort_in_place.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/sort_in_place.pm @@ -47,7 +47,7 @@ sub _potential_value { . ': sort @{ (' . $slot_access . ') } ]'; } -sub _return_value { return '' } +sub _return_value { '' } no Moose::Role; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Collection.pm b/lib/Moose/Meta/Method/Accessor/Native/Collection.pm index 517ff54..2f9222d 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Collection.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Collection.pm @@ -124,8 +124,8 @@ sub _inline_get_old_value_for_trigger { return unless $attr->has_trigger; return ( - 'my ' . $old . ' = ' . $self->_inline_has($instance), - '? ' . $self->_inline_copy_old_value($self->_inline_get($instance)), + 'my ' . $old . ' = ' . $self->_has_value($instance), + '? ' . $self->_copy_old_value($self->_get_value($instance)), ': ();', ); } diff --git a/lib/Moose/Meta/Method/Accessor/Native/Counter/Writer.pm b/lib/Moose/Meta/Method/Accessor/Native/Counter/Writer.pm index 2df502c..e01af6a 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Counter/Writer.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Counter/Writer.pm @@ -17,8 +17,9 @@ sub _constraint_must_be_checked { my $attr = $self->associated_attribute; return $attr->has_type_constraint - && ( $attr->type_constraint->name =~ /^(?:Num|Int)$/ - || ( $attr->should_coerce && $attr->type_constraint->has_coercion ) ); + && ($attr->type_constraint->name =~ /^(?:Num|Int)$/ + || ($attr->should_coerce && $attr->type_constraint->has_coercion) + ); } no Moose::Role; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Counter/dec.pm b/lib/Moose/Meta/Method/Accessor/Native/Counter/dec.pm index 119c174..2de5bdb 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Counter/dec.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Counter/dec.pm @@ -19,14 +19,14 @@ with 'Moose::Meta::Method::Accessor::Native::Writer' => { ] }; -sub _minimum_arguments {0} -sub _maximum_arguments {1} +sub _minimum_arguments { 0 } +sub _maximum_arguments { 1 } sub _potential_value { my $self = shift; my ($slot_access) = @_; - return $slot_access . ' - ( defined $_[0] ? $_[0] : 1 )'; + return $slot_access . ' - (defined $_[0] ? $_[0] : 1)'; } sub _optimized_set_new_value { diff --git a/lib/Moose/Meta/Method/Accessor/Native/Counter/inc.pm b/lib/Moose/Meta/Method/Accessor/Native/Counter/inc.pm index 2a0b44e..28add83 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Counter/inc.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Counter/inc.pm @@ -26,7 +26,7 @@ sub _potential_value { my $self = shift; my ($slot_access) = @_; - return $slot_access . ' + ( defined $_[0] ? $_[0] : 1 )'; + return $slot_access . ' + (defined $_[0] ? $_[0] : 1)'; } sub _optimized_set_new_value { diff --git a/lib/Moose/Meta/Method/Accessor/Native/Counter/set.pm b/lib/Moose/Meta/Method/Accessor/Native/Counter/set.pm index 4ca9d86..3ed83e2 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Counter/set.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Counter/set.pm @@ -19,10 +19,10 @@ with 'Moose::Meta::Method::Accessor::Native::Writer' => { ] }; -sub _minimum_arguments {1} -sub _maximum_arguments {1} +sub _minimum_arguments { 1 } +sub _maximum_arguments { 1 } -sub _potential_value {'$_[0]'} +sub _potential_value { '$_[0]' } sub _optimized_set_new_value { my $self = shift; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash.pm index 5ed7110..9d0fda4 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash.pm @@ -16,8 +16,7 @@ sub _inline_check_var_is_valid_key { return ( 'if (!defined(' . $var . ')) {', $self->_inline_throw_error( - '"The key passed to ' - . $self->delegate_to_method + '"The key passed to ' . $self->delegate_to_method . ' must be a defined value"', ) . ';', '}', diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/Writer.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/Writer.pm index 99bf3d2..68147d5 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/Writer.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/Writer.pm @@ -17,13 +17,13 @@ with 'Moose::Meta::Method::Accessor::Native::Writer' => { 'Moose::Meta::Method::Accessor::Native::Hash', 'Moose::Meta::Method::Accessor::Native::Collection'; -sub _new_values {'@values'} +sub _new_values { '@values' } -sub _inline_copy_old_value { +sub _copy_old_value { my $self = shift; my ($slot_access) = @_; - return '{ %{(' . $slot_access . ')} }'; + return '{ %{ (' . $slot_access . ') } }'; } no Moose::Role; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/accessor.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/accessor.pm index b3db6d6..d2a04dc 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/accessor.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/accessor.pm @@ -36,7 +36,7 @@ sub _generate_method { my $self = shift; my $inv = '$self'; - my $slot_access = $self->_inline_get($inv); + my $slot_access = $self->_get_value($inv); return ( 'sub {', @@ -51,15 +51,15 @@ sub _generate_method { '}', # set 'else {', - $self->_writer_core($inv, $slot_access), + $self->_inline_writer_core($inv, $slot_access), $self->_inline_post_body(@_), '}', '}', ); } -sub _minimum_arguments {1} -sub _maximum_arguments {2} +sub _minimum_arguments { 1 } +sub _maximum_arguments { 2 } no Moose::Role; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/clear.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/clear.pm index 08dc8a3..debb63b 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/clear.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/clear.pm @@ -23,7 +23,7 @@ sub _maximum_arguments { 0 } sub _adds_members { 0 } -sub _potential_value { return '{}' } +sub _potential_value { '{}' } sub _optimized_set_new_value { my $self = shift; @@ -32,7 +32,7 @@ sub _optimized_set_new_value { return $slot_access . ' = {}'; } -sub _return_value { return '' } +sub _return_value { '' } no Moose::Role; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/abs.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/abs.pm index aa99138..d2c2c09 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Number/abs.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/abs.pm @@ -18,7 +18,7 @@ with 'Moose::Meta::Method::Accessor::Native::Writer' => { ] }; -sub _maximum_arguments {0} +sub _maximum_arguments { 0 } sub _potential_value { my $self = shift; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/add.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/add.pm index e581af4..771cd0d 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Number/add.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/add.pm @@ -19,9 +19,9 @@ with 'Moose::Meta::Method::Accessor::Native::Writer' => { ] }; -sub _minimum_arguments {1} +sub _minimum_arguments { 1 } -sub _maximum_arguments {1} +sub _maximum_arguments { 1 } sub _potential_value { my $self = shift; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/div.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/div.pm index 005ff6f..1b468c6 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Number/div.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/div.pm @@ -19,9 +19,9 @@ with 'Moose::Meta::Method::Accessor::Native::Writer' => { ] }; -sub _minimum_arguments {1} +sub _minimum_arguments { 1 } -sub _maximum_arguments {1} +sub _maximum_arguments { 1 } sub _potential_value { my $self = shift; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/mod.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/mod.pm index affa5c6..c665006 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Number/mod.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/mod.pm @@ -19,9 +19,9 @@ with 'Moose::Meta::Method::Accessor::Native::Writer' => { ] }; -sub _minimum_arguments {1} +sub _minimum_arguments { 1 } -sub _maximum_arguments {1} +sub _maximum_arguments { 1 } sub _potential_value { my $self = shift; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/mul.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/mul.pm index b06e8d9..ac0f267 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Number/mul.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/mul.pm @@ -19,9 +19,9 @@ with 'Moose::Meta::Method::Accessor::Native::Writer' => { ] }; -sub _minimum_arguments {1} +sub _minimum_arguments { 1 } -sub _maximum_arguments {1} +sub _maximum_arguments { 1 } sub _potential_value { my $self = shift; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/set.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/set.pm index 31990b6..eddacde 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Number/set.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/set.pm @@ -19,10 +19,10 @@ with 'Moose::Meta::Method::Accessor::Native::Writer' => { ] }; -sub _minimum_arguments {1} -sub _maximum_arguments {1} +sub _minimum_arguments { 1 } +sub _maximum_arguments { 1 } -sub _potential_value {'$_[0]'} +sub _potential_value { '$_[0]' } sub _optimized_set_new_value { my $self = shift; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/sub.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/sub.pm index 57d0dff..380f070 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Number/sub.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/sub.pm @@ -19,9 +19,9 @@ with 'Moose::Meta::Method::Accessor::Native::Writer' => { ] }; -sub _minimum_arguments {1} +sub _minimum_arguments { 1 } -sub _maximum_arguments {1} +sub _maximum_arguments { 1 } sub _potential_value { my $self = shift; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Reader.pm b/lib/Moose/Meta/Method/Accessor/Native/Reader.pm index 5909153..d892b0c 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Reader.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Reader.pm @@ -17,19 +17,19 @@ sub _generate_method { my $self = shift; my $inv = '$self'; - my $slot_access = $self->_inline_get($inv); + my $slot_access = $self->_get_value($inv); return ( 'sub {', $self->_inline_pre_body(@_), 'my ' . $inv . ' = shift;', $self->_inline_curried_arguments, - $self->_reader_core($inv, $slot_access, @_), + $self->_inline_reader_core($inv, $slot_access, @_), '}', ); } -sub _reader_core { +sub _inline_reader_core { my $self = shift; my ($inv, $slot_access, @extra) = @_; diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/chomp.pm b/lib/Moose/Meta/Method/Accessor/Native/String/chomp.pm index 3c56056..1aa686a 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/String/chomp.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/String/chomp.pm @@ -19,7 +19,7 @@ with 'Moose::Meta::Method::Accessor::Native::Writer' => { ] }; -sub _maximum_arguments {0} +sub _maximum_arguments { 0 } sub _potential_value { my $self = shift; diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/clear.pm b/lib/Moose/Meta/Method/Accessor/Native/String/clear.pm index c2cb974..d881eac 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/String/clear.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/String/clear.pm @@ -20,12 +20,7 @@ with 'Moose::Meta::Method::Accessor::Native::Writer' => { sub _maximum_arguments { 0 } -sub _potential_value { - my $self = shift; - my ($slot_access) = @_; - - return '""'; -} +sub _potential_value { '""' } sub _optimized_set_new_value { my $self = shift; diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/prepend.pm b/lib/Moose/Meta/Method/Accessor/Native/String/prepend.pm index a431f55..66e3031 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/String/prepend.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/String/prepend.pm @@ -27,7 +27,7 @@ sub _potential_value { my $self = shift; my ($slot_access) = @_; - return '( $_[0] . ' . $slot_access . ' )'; + return '$_[0] . ' . $slot_access; } sub _optimized_set_new_value { diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/substr.pm b/lib/Moose/Meta/Method/Accessor/Native/String/substr.pm index b3a0a2f..40195e8 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/String/substr.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/String/substr.pm @@ -40,7 +40,7 @@ sub _generate_method { my $self = shift; my $inv = '$self'; - my $slot_access = $self->_inline_get($inv); + my $slot_access = $self->_get_value($inv); return ( 'sub {', @@ -48,10 +48,10 @@ sub _generate_method { 'my ' . $inv . ' = shift;', $self->_inline_curried_arguments, 'if (@_ == 1 || @_ == 2) {', - $self->_reader_core($inv, $slot_access), + $self->_inline_reader_core($inv, $slot_access), '}', 'elsif (@_ == 3) {', - $self->_writer_core($inv, $slot_access), + $self->_inline_writer_core($inv, $slot_access), $self->_inline_post_body(@_), '}', 'else {', @@ -61,8 +61,8 @@ sub _generate_method { ); } -sub _minimum_arguments {1} -sub _maximum_arguments {3} +sub _minimum_arguments { 1 } +sub _maximum_arguments { 3 } sub _inline_process_arguments { my $self = shift; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Writer.pm b/lib/Moose/Meta/Method/Accessor/Native/Writer.pm index de127f9..9ec8777 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Writer.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Writer.pm @@ -19,20 +19,20 @@ sub _generate_method { my $self = shift; my $inv = '$self'; - my $slot_access = $self->_inline_get($inv); + my $slot_access = $self->_get_value($inv); return ( 'sub {', $self->_inline_pre_body(@_), 'my ' . $inv . ' = shift;', $self->_inline_curried_arguments, - $self->_writer_core($inv, $slot_access), + $self->_inline_writer_core($inv, $slot_access), $self->_inline_post_body(@_), '}', ); } -sub _writer_core { +sub _inline_writer_core { my $self = shift; my ($inv, $slot_access) = @_; @@ -85,8 +85,9 @@ sub _constraint_must_be_checked { my $attr = $self->associated_attribute; return $attr->has_type_constraint - && ( !$self->_is_root_type( $attr->type_constraint ) - || ( $attr->should_coerce && $attr->type_constraint->has_coercion ) ); + && (!$self->_is_root_type( $attr->type_constraint ) + || ( $attr->should_coerce && $attr->type_constraint->has_coercion) + ); } sub _is_root_type { @@ -108,7 +109,7 @@ sub _inline_copy_native_value { ${$potential_ref} = '$potential'; - return ($code); + return $code; } around _inline_tc_code => sub { @@ -130,7 +131,7 @@ sub _inline_check_coercion { # We want to break the aliasing in @_ in case the coercion tries to make a # destructive change to an array member. - return ($value . ' = $type_constraint_obj->coerce(' . $value . ');'); + return $value . ' = $type_constraint_obj->coerce(' . $value . ');'; } around _inline_check_constraint => sub { @@ -148,10 +149,10 @@ sub _inline_capture_return_value { return } sub _set_new_value { my $self = shift; - return $self->_inline_store(@_) + return $self->_store_value(@_) if $self->_value_needs_copy || !$self->_slot_access_can_be_inlined - || !$self->_inline_get_is_lvalue; + || !$self->_get_is_lvalue; return $self->_optimized_set_new_value(@_); } @@ -161,7 +162,7 @@ sub _inline_set_new_value { return $self->_set_new_value(@_) . ';'; } -sub _inline_get_is_lvalue { +sub _get_is_lvalue { my $self = shift; return $self->associated_attribute->associated_class->instance_metaclass->inline_get_is_lvalue; @@ -170,7 +171,7 @@ sub _inline_get_is_lvalue { sub _optimized_set_new_value { my $self = shift; - return $self->_inline_store(@_); + return $self->_store_value(@_); } sub _return_value {