use strict;
use warnings;
-use Scalar::Util 'weaken';
+use Scalar::Util 'weaken', 'blessed';
-our $VERSION = '0.01';
+our $VERSION = '0.02';
sub meta {
require Class::MOP::Class;
# assumption,.. but you can
# never tell <:)
meta => $meta,
- slots => \@slots,
+ slots => { map { $_ => undef } @slots },
} => $class;
}
bless $instance_structure, $self->{meta}->name;
}
+sub clone_instance {
+ my ($self, $instance) = @_;
+ $self->bless_instance_structure({ %$instance });
+}
+
# operations on meta instance
sub get_all_slots {
my $self = shift;
- return @{$self->{slots}};
+ return keys %{$self->{slots}};
+}
+
+sub is_valid_slot {
+ my ($self, $slot_name) = @_;
+ exists $self->{slots}->{$slot_name} ? 1 : 0;
}
# operations on created instances
sub initialize_slot {
my ($self, $instance, $slot_name) = @_;
- $instance->{$slot_name} = undef;
+ $self->set_slot_value($instance, $slot_name, undef);
+}
+
+sub deinitialize_slot {
+ my ( $self, $instance, $slot_name ) = @_;
+ delete $instance->{$slot_name};
}
sub initialize_all_slots {
}
}
+sub deinitialize_all_slots {
+ my ($self, $instance) = @_;
+ foreach my $slot_name ($self->get_all_slots) {
+ $self->deinitialize_slot($instance, $slot_name);
+ }
+}
+
sub is_slot_initialized {
my ($self, $instance, $slot_name, $value) = @_;
exists $instance->{$slot_name} ? 1 : 0;
# inlinable operation snippets
+sub is_inlinable { 1 }
+
+sub inline_create_instance {
+ my ($self, $class_variable) = @_;
+ 'bless {} => ' . $class_variable;
+}
+
sub inline_slot_access {
my ($self, $instance, $slot_name) = @_;
sprintf "%s->{%s}", $instance, $slot_name;
$self->inline_set_slot_value($instance, $slot_name, 'undef'),
}
+sub inline_deinitialize_slot {
+ my ($self, $instance, $slot_name) = @_;
+ "delete " . $self->inline_slot_access($instance, $slot_name);
+}
sub inline_is_slot_initialized {
my ($self, $instance, $slot_name) = @_;
"exists " . $self->inline_slot_access($instance, $slot_name) . " ? 1 : 0";
This does just exactly what it says it does.
+=item B<clone_instance ($instance_structure)>
+
=back
=head2 Instrospection
This will return the current list of slots based on what was
given to this object in C<new>.
+=item B<is_valid_slot ($slot_name)>
+
=back
=head2 Operations on Instance Structures
=item B<initialize_slot ($instance_structure, $slot_name)>
+=item B<deinitialize_slot ($instance_structure, $slot_name)>
+
=item B<initialize_all_slots ($instance_structure)>
+=item B<deinitialize_all_slots ($instance_structure)>
+
=item B<is_slot_initialized ($instance_structure, $slot_name)>
=item B<weaken_slot_value ($instance_structure, $slot_name)>
=head2 Inlineable Instance Operations
+This part of the API is currently un-used. It is there for use
+in future experiments in class finailization mostly. Best to
+ignore this for now.
+
=over 4
+=item B<is_inlinable>
+
+Each meta-instance should override this method to tell Class::MOP if it's
+possible to inline the slot access.
+
+This is currently only used by Class::MOP::Class::Immutable when performing
+optimizations.
+
+=item B<inline_create_instance>
+
=item B<inline_slot_access ($instance_structure, $slot_name)>
=item B<inline_get_slot_value ($instance_structure, $slot_name)>
=item B<inline_initialize_slot ($instance_structure, $slot_name)>
+=item B<inline_deinitialize_slot ($instance_structure, $slot_name)>
+
=item B<inline_is_slot_initialized ($instance_structure, $slot_name)>
=item B<inline_weaken_slot_value ($instance_structure, $slot_name)>
=back
-=head1 AUTHOR
+=head1 AUTHORS
Yuval Kogman E<lt>nothingmuch@woobling.comE<gt>