Inlining for native Bool trait
Dave Rolsky [Tue, 21 Sep 2010 18:22:04 +0000 (13:22 -0500)]
lib/Moose/Meta/Attribute/Native/MethodProvider/Bool.pm [deleted file]
lib/Moose/Meta/Attribute/Native/Trait/Bool.pm
lib/Moose/Meta/Method/Accessor/Native/Bool/Writer.pm [new file with mode: 0644]
lib/Moose/Meta/Method/Accessor/Native/Bool/not.pm [new file with mode: 0644]
lib/Moose/Meta/Method/Accessor/Native/Bool/set.pm [new file with mode: 0644]
lib/Moose/Meta/Method/Accessor/Native/Bool/toggle.pm [new file with mode: 0644]
lib/Moose/Meta/Method/Accessor/Native/Bool/unset.pm [new file with mode: 0644]

diff --git a/lib/Moose/Meta/Attribute/Native/MethodProvider/Bool.pm b/lib/Moose/Meta/Attribute/Native/MethodProvider/Bool.pm
deleted file mode 100644 (file)
index 914ad15..0000000
+++ /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<Moose::Meta::Attribute::Native::Trait::Bool>. Please check there for
-documentation on what methods are provided.
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=back
-
-=head1 BUGS
-
-See L<Moose/BUGS> for details on reporting bugs.
-
-=head1 AUTHOR
-
-Jason May E<lt>jason.a.may@gmail.comE<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright 2007-2009 by Infinity Interactive, Inc.
-
-L<http://www.iinteractive.com>
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
-=cut
index 1deeb77..f767bf2 100644 (file)
@@ -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 (file)
index 0000000..de6fa33
--- /dev/null
@@ -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 (file)
index 0000000..3449e60
--- /dev/null
@@ -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 (file)
index 0000000..ca3a8bd
--- /dev/null
@@ -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 (file)
index 0000000..d5ed290
--- /dev/null
@@ -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 (file)
index 0000000..d7732b5
--- /dev/null
@@ -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;