From: Dave Rolsky Date: Wed, 22 Sep 2010 22:21:29 +0000 (-0500) Subject: Add inlining methods for Number native trait X-Git-Tag: 1.15~116 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f23ffd15f41e33dd811073e68eb7a9a929235187;p=gitmo%2FMoose.git Add inlining methods for Number native trait --- diff --git a/lib/Moose/Meta/Attribute/Native/Trait/Number.pm b/lib/Moose/Meta/Attribute/Native/Trait/Number.pm index fa305af..20e9359 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait/Number.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait/Number.pm @@ -5,51 +5,18 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; +use Moose::Meta::Method::Accessor::Native::Number::abs; +use Moose::Meta::Method::Accessor::Native::Number::add; +use Moose::Meta::Method::Accessor::Native::Number::div; +use Moose::Meta::Method::Accessor::Native::Number::mod; +use Moose::Meta::Method::Accessor::Native::Number::mul; +use Moose::Meta::Method::Accessor::Native::Number::set; +use Moose::Meta::Method::Accessor::Native::Number::sub; + with 'Moose::Meta::Attribute::Native::Trait'; sub _helper_type { 'Num' } -# NOTE: we don't use the method provider for this module since many of -# the names of the provided methods would conflict with keywords - SL - -has 'method_constructors' => ( - is => 'ro', - isa => 'HashRef', - lazy => 1, - default => sub { - return +{ - set => sub { - my ( $attr, $reader, $writer ) = @_; - return sub { $writer->( $_[0], $_[1] ) }; - }, - add => sub { - my ( $attr, $reader, $writer ) = @_; - return sub { $writer->( $_[0], $reader->( $_[0] ) + $_[1] ) }; - }, - sub => sub { - my ( $attr, $reader, $writer ) = @_; - return sub { $writer->( $_[0], $reader->( $_[0] ) - $_[1] ) }; - }, - mul => sub { - my ( $attr, $reader, $writer ) = @_; - return sub { $writer->( $_[0], $reader->( $_[0] ) * $_[1] ) }; - }, - div => sub { - my ( $attr, $reader, $writer ) = @_; - return sub { $writer->( $_[0], $reader->( $_[0] ) / $_[1] ) }; - }, - mod => sub { - my ( $attr, $reader, $writer ) = @_; - return sub { $writer->( $_[0], $reader->( $_[0] ) % $_[1] ) }; - }, - abs => sub { - my ( $attr, $reader, $writer ) = @_; - return sub { $writer->( $_[0], abs( $reader->( $_[0] ) ) ) }; - }, - }; - } -); - no Moose::Role; 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/abs.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/abs.pm new file mode 100644 index 0000000..5021ee9 --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/abs.pm @@ -0,0 +1,27 @@ +package Moose::Meta::Method::Accessor::Native::Number::abs; + +use strict; +use warnings; + +our $VERSION = '1.13'; +$VERSION = eval $VERSION; +our $AUTHORITY = 'cpan:STEVAN'; + +use base 'Moose::Meta::Method::Accessor::Native::Writer'; + +sub _minimum_arguments {0} +sub _maximum_arguments {0} + +sub _potential_value { + my ( $self, $slot_access ) = @_; + + return "abs($slot_access);"; +} + +sub _inline_optimized_set_new_value { + my ( $self, $inv, $new, $slot_access ) = @_; + + return "$slot_access = abs($slot_access)"; +} + +1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/add.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/add.pm new file mode 100644 index 0000000..c24052b --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/add.pm @@ -0,0 +1,27 @@ +package Moose::Meta::Method::Accessor::Native::Number::add; + +use strict; +use warnings; + +our $VERSION = '1.13'; +$VERSION = eval $VERSION; +our $AUTHORITY = 'cpan:STEVAN'; + +use base 'Moose::Meta::Method::Accessor::Native::Writer'; + +sub _minimum_arguments {1} +sub _maximum_arguments {1} + +sub _potential_value { + my ( $self, $slot_access ) = @_; + + return "$slot_access + \$_[0];"; +} + +sub _inline_optimized_set_new_value { + my ( $self, $inv, $new, $slot_access ) = @_; + + return "$slot_access += \$_[0];"; +} + +1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/div.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/div.pm new file mode 100644 index 0000000..eddc608 --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/div.pm @@ -0,0 +1,27 @@ +package Moose::Meta::Method::Accessor::Native::Number::div; + +use strict; +use warnings; + +our $VERSION = '1.13'; +$VERSION = eval $VERSION; +our $AUTHORITY = 'cpan:STEVAN'; + +use base 'Moose::Meta::Method::Accessor::Native::Writer'; + +sub _minimum_arguments {1} +sub _maximum_arguments {1} + +sub _potential_value { + my ( $self, $slot_access ) = @_; + + return "$slot_access / \$_[0];"; +} + +sub _inline_optimized_set_new_value { + my ( $self, $inv, $new, $slot_access ) = @_; + + return "$slot_access /= \$_[0];"; +} + +1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/mod.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/mod.pm new file mode 100644 index 0000000..7f57570 --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/mod.pm @@ -0,0 +1,27 @@ +package Moose::Meta::Method::Accessor::Native::Number::mod; + +use strict; +use warnings; + +our $VERSION = '1.13'; +$VERSION = eval $VERSION; +our $AUTHORITY = 'cpan:STEVAN'; + +use base 'Moose::Meta::Method::Accessor::Native::Writer'; + +sub _minimum_arguments {1} +sub _maximum_arguments {1} + +sub _potential_value { + my ( $self, $slot_access ) = @_; + + return "$slot_access % \$_[0];"; +} + +sub _inline_optimized_set_new_value { + my ( $self, $inv, $new, $slot_access ) = @_; + + return "$slot_access %= \$_[0];"; +} + +1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/mul.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/mul.pm new file mode 100644 index 0000000..1ed88c8 --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/mul.pm @@ -0,0 +1,27 @@ +package Moose::Meta::Method::Accessor::Native::Number::mul; + +use strict; +use warnings; + +our $VERSION = '1.13'; +$VERSION = eval $VERSION; +our $AUTHORITY = 'cpan:STEVAN'; + +use base 'Moose::Meta::Method::Accessor::Native::Writer'; + +sub _minimum_arguments {1} +sub _maximum_arguments {1} + +sub _potential_value { + my ( $self, $slot_access ) = @_; + + return "$slot_access * \$_[0];"; +} + +sub _inline_optimized_set_new_value { + my ( $self, $inv, $new, $slot_access ) = @_; + + return "$slot_access *= \$_[0];"; +} + +1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/set.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/set.pm new file mode 100644 index 0000000..ca797bf --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/set.pm @@ -0,0 +1,23 @@ +package Moose::Meta::Method::Accessor::Native::Number::set; + +use strict; +use warnings; + +our $VERSION = '1.13'; +$VERSION = eval $VERSION; +our $AUTHORITY = 'cpan:STEVAN'; + +use base 'Moose::Meta::Method::Accessor::Native::Writer'; + +sub _minimum_arguments {1} +sub _maximum_arguments {1} + +sub _potential_value {'$_[0]'} + +sub _inline_optimized_set_new_value { + my ( $self, $inv, $new, $slot_access ) = @_; + + return "$slot_access = \$_[0];"; +} + +1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/sub.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/sub.pm new file mode 100644 index 0000000..563464a --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/sub.pm @@ -0,0 +1,27 @@ +package Moose::Meta::Method::Accessor::Native::Number::sub; + +use strict; +use warnings; + +our $VERSION = '1.13'; +$VERSION = eval $VERSION; +our $AUTHORITY = 'cpan:STEVAN'; + +use base 'Moose::Meta::Method::Accessor::Native::Writer'; + +sub _minimum_arguments {1} +sub _maximum_arguments {1} + +sub _potential_value { + my ( $self, $slot_access ) = @_; + + return "$slot_access - \$_[0];"; +} + +sub _inline_optimized_set_new_value { + my ( $self, $inv, $new, $slot_access ) = @_; + + return "$slot_access -= \$_[0];"; +} + +1;