From: Stevan Little Date: Sat, 29 Apr 2006 11:56:02 +0000 (+0000) Subject: no-more-inline X-Git-Tag: 0_29_02~31 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c174112e1257a0176822770bb9675e4d7cbf2e57;p=gitmo%2FClass-MOP.git no-more-inline --- diff --git a/lib/Class/MOP/Instance.pm b/lib/Class/MOP/Instance.pm index 1832e29..8f101ab 100644 --- a/lib/Class/MOP/Instance.pm +++ b/lib/Class/MOP/Instance.pm @@ -52,13 +52,6 @@ sub get_all_slots { # operations on created instances -sub initialize_all_slots { - my ($self, $instance) = @_; - foreach my $slot_name ($self->get_all_slots) { - $self->initialize_slot($instance, $slot_name); - } -} - sub get_slot_value { my ($self, $instance, $slot_name) = @_; return $instance->{$slot_name}; @@ -74,33 +67,18 @@ sub initialize_slot { $instance->{$slot_name} = undef; } +sub initialize_all_slots { + my ($self, $instance) = @_; + foreach my $slot_name ($self->get_all_slots) { + $self->initialize_slot($instance, $slot_name); + } +} + sub is_slot_initialized { my ($self, $instance, $slot_name, $value) = @_; exists $instance->{$slot_name} ? 1 : 0; } -# inlinable operation snippets - -sub inline_get_slot_value { - my ($self, $instance_var_name, $slot_name) = @_; - return ($instance_var_name . '->{\'' . $slot_name . '\'}'); -} - -sub inline_set_slot_value { - my ($self, $instance_var_name, $slot_name, $value_name) = @_; - return ($self->inline_get_slot_value($instance_var_name, $slot_name) . ' = ' . $value_name); -} - -sub inline_initialize_slot { - my ($self, $instance_var_name, $slot_name) = @_; - $self->inline_set_slot_value($instance_var_name, $slot_name, 'undef'); -} - -sub inline_is_slot_initialized { - my ($self, $instance_var_name, $slot_name) = @_; - return ('exists ' . $self->inline_get_slot_value($instance_var_name, $slot_name) . ' ? 1 : 0'); -} - 1; __END__ @@ -137,14 +115,6 @@ Class::MOP::Instance - Instance Meta Object =item B -=item B - -=item B - -=item B - -=item B - =back =head2 Introspection diff --git a/t/060_instance.t b/t/060_instance.t index 36657f1..45961cd 100644 --- a/t/060_instance.t +++ b/t/060_instance.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 25; +use Test::More tests => 22; use Test::Exception; BEGIN { @@ -20,9 +20,9 @@ can_ok( "Class::MOP::Instance", $_ ) for qw/ get_slot_value set_slot_value - - inline_get_slot_value - inline_set_slot_value + initialize_slot + initialize_all_slots + is_slot_initialized /; { @@ -73,14 +73,3 @@ $mi_foo->set_slot_value( $i_foo, "moosen", "the value" ); is($mi_foo->get_slot_value( $i_foo, "moosen" ), "the value", "... get slot value"); ok(!$i_foo->can('moosen'), '... Foo cant moosen'); - -eval 'sub Foo::moosen { ' . $mi_foo->inline_get_slot_value( '$_[0]', 'moosen' ) . ' }'; -ok(!$@, "compilation of inline get value had no error"); - -can_ok($i_foo, 'moosen'); - -is($i_foo->moosen, "the value", "... inline get value worked"); - -$mi_foo->set_slot_value( $i_foo, "moosen", "the other value" ); - -is($i_foo->moosen, "the other value", "... inline get value worked (even after value is changed)");