use Scalar::Util 'weaken', 'blessed';
-our $VERSION = '0.01';
+our $VERSION = '0.03';
+our $AUTHORITY = 'cpan:STEVAN';
sub meta {
require Class::MOP::Class;
sub new {
my ($class, $meta, @attrs) = @_;
my @slots = map { $_->slots } @attrs;
- bless {
+ my $instance = bless {
# NOTE:
# I am not sure that it makes
# sense to pass in the meta
# which is *probably* a safe
# assumption,.. but you can
# never tell <:)
- meta => $meta,
- slots => { map { $_ => undef } @slots },
+ '$!meta' => $meta,
+ '@!slots' => { map { $_ => undef } @slots },
} => $class;
+
+ weaken($instance->{'$!meta'});
+
+ return $instance;
}
+sub associated_metaclass { (shift)->{'$!meta'} }
+
sub create_instance {
my $self = shift;
$self->bless_instance_structure({});
sub bless_instance_structure {
my ($self, $instance_structure) = @_;
- bless $instance_structure, $self->{meta}->name;
+ bless $instance_structure, $self->associated_metaclass->name;
}
sub clone_instance {
sub get_all_slots {
my $self = shift;
- return keys %{$self->{slots}};
+ return keys %{$self->{'@!slots'}};
}
sub is_valid_slot {
my ($self, $slot_name) = @_;
- exists $self->{slots}->{$slot_name} ? 1 : 0;
+ exists $self->{'@!slots'}->{$slot_name} ? 1 : 0;
}
# operations on created instances
$self->set_slot_value($instance, $slot_name, undef);
}
+sub deinitialize_slot {
+ my ( $self, $instance, $slot_name ) = @_;
+ delete $instance->{$slot_name};
+}
+
sub initialize_all_slots {
my ($self, $instance) = @_;
foreach my $slot_name ($self->get_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;
$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";
=over 4
+=item B<associated_metaclass>
+
=item B<get_all_slots>
This will return the current list of slots based on what was
=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)>
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>