1. Toby Inkster
  2. p5-moosex-arrayref

Commits

Toby Inkster  committed 26c527c

better inlined code

  • Participants
  • Parent commits 213565c
  • Branches default
  • Tags 0.004

Comments (0)

Files changed (5)

File lib/MooseX/ArrayRef.pm

View file
 
 BEGIN {
 	$MooseX::ArrayRef::AUTHORITY = 'cpan:TOBYINK';
-	$MooseX::ArrayRef::VERSION   = '0.003';
+	$MooseX::ArrayRef::VERSION   = '0.004';
 }
 
 use Moose ();

File lib/MooseX/ArrayRef/Meta/Class.pm

View file
 
 BEGIN {
 	$MooseX::ArrayRef::Meta::Class::AUTHORITY = 'cpan:TOBYINK';
-	$MooseX::ArrayRef::Meta::Class::VERSION   = '0.003';
+	$MooseX::ArrayRef::Meta::Class::VERSION   = '0.004';
 }
 
 use Moose::Role;
 
-#has slot_to_index_map => (
-#	is         => 'ro',
-#	isa        => 'HashRef[Num]',
-#	lazy_build => 1,
-#);
-
 has next_index => (
 	is         => 'rw',
 	isa        => 'Num',
 	lazy_build => 1,
 );
 
+# This was originally a builder for a lazy attribute, but it was built
+# too early (before all attributes existed), so I just do it on the fly
+# now. It would be nice if some of this could be memoized though.
 sub slot_to_index_map
 {
 	my $meta = shift;

File lib/MooseX/ArrayRef/Meta/Instance.pm

View file
 
 BEGIN {
 	$MooseX::ArrayRef::Meta::Instance::AUTHORITY = 'cpan:TOBYINK';
-	$MooseX::ArrayRef::Meta::Instance::VERSION   = '0.003';
+	$MooseX::ArrayRef::Meta::Instance::VERSION   = '0.004';
 }
 
 use Moose::Role;
-use Moose::Util::MetaRole;
 use Scalar::Util qw( isweak weaken );
 
 use constant EMPTY => \0;
 	$instance."->[$i]"
 };
 
+override inline_get_slot_value => sub {
+	my ($meta, $instance, $slot_name) = @_;
+	my $get = $meta->inline_slot_access($instance, $slot_name);
+	sprintf('do { no warnings; %s == MooseX::ArrayRef::Meta::Instance::EMPTY ? undef : %s }', $get, $get);
+};
+
+override inline_deinitialize_slot => sub {
+	my ($meta, $instance, $slot_name) = @_;
+	my $get = $meta->inline_slot_access($instance, $slot_name);
+	sprintf('%s = MooseX::ArrayRef::Meta::Instance::EMPTY', $get);
+};
+
+override inline_is_slot_initialized => sub {
+	my ($meta, $instance, $slot_name) = @_;
+	my $get = $meta->inline_slot_access($instance, $slot_name);
+	sprintf('do { no warnings; %s != MooseX::ArrayRef::Meta::Instance::EMPTY }', $get);
+};
+
 1;
 

File meta/changes.pret

View file
 `MooseX-ArrayRef 0.003 cpan:TOBYINK`
 	issued  2012-09-04;
 	label   "This is not my day...".
+
+`MooseX-ArrayRef 0.004 cpan:TOBYINK`
+	issued  2012-09-04;
+	changeset [
+		item "Improved generated inline code."^^Change;
+	].
+

File t/04inlining.t

View file
+use Test::More tests => 4;
+
+{
+	package Local::Foo;
+	use MooseX::ArrayRef;
+	has foo => (is => 'rw', clearer => 'clear_foo', predicate => 'has_foo');
+	__PACKAGE__->meta->make_immutable;
+}
+
+my $obj = Local::Foo->new(foo => 1);
+ok($obj->has_foo);
+
+$obj->clear_foo;
+ok not($obj->has_foo);
+is($obj->foo, undef);
+
+$obj->foo(2);
+ok($obj->has_foo);