From: Dave Rolsky Date: Tue, 21 Sep 2010 18:22:04 +0000 (-0500) Subject: Inlining for native Bool trait X-Git-Tag: 1.15~125 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=664e417b261192c01990eaaa5dd77703f713a8a2;p=gitmo%2FMoose.git Inlining for native Bool trait --- diff --git a/lib/Moose/Meta/Attribute/Native/MethodProvider/Bool.pm b/lib/Moose/Meta/Attribute/Native/MethodProvider/Bool.pm deleted file mode 100644 index 914ad15..0000000 --- a/lib/Moose/Meta/Attribute/Native/MethodProvider/Bool.pm +++ /dev/null @@ -1,70 +0,0 @@ - -package Moose::Meta::Attribute::Native::MethodProvider::Bool; -use Moose::Role; - -our $VERSION = '1.14'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - -sub set : method { - my ( $attr, $reader, $writer ) = @_; - return sub { $writer->( $_[0], 1 ) }; -} - -sub unset : method { - my ( $attr, $reader, $writer ) = @_; - return sub { $writer->( $_[0], 0 ) }; -} - -sub toggle : method { - my ( $attr, $reader, $writer ) = @_; - return sub { $writer->( $_[0], !$reader->( $_[0] ) ) }; -} - -sub not : method { - my ( $attr, $reader, $writer ) = @_; - return sub { !$reader->( $_[0] ) }; -} - -1; - -__END__ - -=pod - -=head1 NAME - -Moose::Meta::Attribute::Native::MethodProvider::Bool - role providing method generators for Bool trait - -=head1 DESCRIPTION - -This is a role which provides the method generators for -L. Please check there for -documentation on what methods are provided. - -=head1 METHODS - -=over 4 - -=item B - -=back - -=head1 BUGS - -See L for details on reporting bugs. - -=head1 AUTHOR - -Jason May Ejason.a.may@gmail.comE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2007-2009 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - -=cut diff --git a/lib/Moose/Meta/Attribute/Native/Trait/Bool.pm b/lib/Moose/Meta/Attribute/Native/Trait/Bool.pm index 1deeb77..f767bf2 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait/Bool.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait/Bool.pm @@ -1,22 +1,22 @@ package Moose::Meta::Attribute::Native::Trait::Bool; use Moose::Role; -use Moose::Meta::Attribute::Native::MethodProvider::Bool; our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; +use Moose::Meta::Method::Accessor::Native::Bool::not; +use Moose::Meta::Method::Accessor::Native::Bool::set; +use Moose::Meta::Method::Accessor::Native::Bool::toggle; +use Moose::Meta::Method::Accessor::Native::Bool::unset; + + with 'Moose::Meta::Attribute::Native::Trait'; sub _default_is { 'rw' } sub _helper_type { 'Bool' } -has 'method_provider' => ( - is => 'ro', - isa => 'ClassName', - predicate => 'has_method_provider', - default => 'Moose::Meta::Attribute::Native::MethodProvider::Bool' -); +sub _native_type { 'Bool' } no Moose::Role; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Bool/Writer.pm b/lib/Moose/Meta/Method/Accessor/Native/Bool/Writer.pm new file mode 100644 index 0000000..de6fa33 --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Bool/Writer.pm @@ -0,0 +1,20 @@ +package Moose::Meta::Method::Accessor::Native::Bool::Writer; + +use strict; +use warnings; + +our $VERSION = '1.13'; +$VERSION = eval $VERSION; +our $AUTHORITY = 'cpan:STEVAN'; + +use base 'Moose::Meta::Method::Accessor::Native::Writer'; + +sub _new_value {q{}} +sub _potential_value {q{}} + +sub _value_needs_copy {0} + +# The Bool type does not have any methods that take a user-provided value +sub _inline_tc_code {q{}} + +1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Bool/not.pm b/lib/Moose/Meta/Method/Accessor/Native/Bool/not.pm new file mode 100644 index 0000000..3449e60 --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Bool/not.pm @@ -0,0 +1,21 @@ +package Moose::Meta::Method::Accessor::Native::Bool::not; + +use strict; +use warnings; + +our $VERSION = '1.13'; +$VERSION = eval $VERSION; +our $AUTHORITY = 'cpan:STEVAN'; + +use base 'Moose::Meta::Method::Accessor::Native::Reader'; + +sub _minimum_arguments { 0 } +sub _maximum_arguments { 0 } + +sub _return_value { + my ( $self, $slot_access ) = @_; + + return "! $slot_access"; +} + +1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Bool/set.pm b/lib/Moose/Meta/Method/Accessor/Native/Bool/set.pm new file mode 100644 index 0000000..ca3a8bd --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Bool/set.pm @@ -0,0 +1,21 @@ +package Moose::Meta::Method::Accessor::Native::Bool::set; + +use strict; +use warnings; + +our $VERSION = '1.13'; +$VERSION = eval $VERSION; +our $AUTHORITY = 'cpan:STEVAN'; + +use base 'Moose::Meta::Method::Accessor::Native::Bool::Writer'; + +sub _minimum_arguments { 0 } +sub _maximum_arguments { 0 } + +sub _inline_optimized_set_new_value { + my ( $self, $inv, $new, $slot_access ) = @_; + + return "$slot_access = 1;"; +} + +1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Bool/toggle.pm b/lib/Moose/Meta/Method/Accessor/Native/Bool/toggle.pm new file mode 100644 index 0000000..d5ed290 --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Bool/toggle.pm @@ -0,0 +1,21 @@ +package Moose::Meta::Method::Accessor::Native::Bool::toggle; + +use strict; +use warnings; + +our $VERSION = '1.13'; +$VERSION = eval $VERSION; +our $AUTHORITY = 'cpan:STEVAN'; + +use base 'Moose::Meta::Method::Accessor::Native::Bool::Writer'; + +sub _minimum_arguments { 0 } +sub _maximum_arguments { 0 } + +sub _inline_optimized_set_new_value { + my ( $self, $inv, $new, $slot_access ) = @_; + + return "$slot_access = $slot_access ? 0 : 1;"; +} + +1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Bool/unset.pm b/lib/Moose/Meta/Method/Accessor/Native/Bool/unset.pm new file mode 100644 index 0000000..d7732b5 --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Bool/unset.pm @@ -0,0 +1,21 @@ +package Moose::Meta::Method::Accessor::Native::Bool::unset; + +use strict; +use warnings; + +our $VERSION = '1.13'; +$VERSION = eval $VERSION; +our $AUTHORITY = 'cpan:STEVAN'; + +use base 'Moose::Meta::Method::Accessor::Native::Bool::Writer'; + +sub _minimum_arguments { 0 } +sub _maximum_arguments { 0 } + +sub _inline_optimized_set_new_value { + my ( $self, $inv, $new, $slot_access ) = @_; + + return "$slot_access = 0;"; +} + +1;