use Scalar::Util 'weaken', 'blessed';
-our $VERSION = '0.78';
+our $VERSION = '0.96';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
}
sub _new {
- my ( $class, %options ) = @_;
- bless {
+ my $class = shift;
+ return Class::MOP::Class->initialize($class)->new_object(@_)
+ if $class ne __PACKAGE__;
+
+ my $params = @_ == 1 ? $_[0] : {@_};
+ return 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 <:)
- 'associated_metaclass' => $options{associated_metaclass},
- 'attributes' => $options{attributes},
- 'slots' => $options{slots},
- 'slot_hash' => $options{slot_hash},
+ 'associated_metaclass' => $params->{associated_metaclass},
+ 'attributes' => $params->{attributes},
+ 'slots' => $params->{slots},
+ 'slot_hash' => $params->{slot_hash},
} => $class;
}
bless {}, $self->_class_name;
}
-# for compatibility
-sub bless_instance_structure {
- my ($self, $instance_structure) = @_;
- bless $instance_structure, $self->_class_name;
-}
-
sub clone_instance {
my ($self, $instance) = @_;
bless { %$instance }, $self->_class_name;
$self->inline_set_slot_value($instance, $slot_name, $self->inline_slot_access($instance, $slot_name));
}
+sub inline_rebless_instance_structure {
+ my ($self, $instance, $class_variable) = @_;
+ "bless $instance => $class_variable";
+}
+
1;
__END__
=head1 DESCRIPTION
-The meta instance API controls the creation of object instances, and
+The Instance Protocol controls the creation of object instances, and
the storage of attribute values in those instances.
Using this API directly in your own code violates encapsulation, and
The method returns a snippet of code that, when inlined, performs some
operation on the instance.
+=item B<< $metainstance->inline_rebless_instance_structure($instance_variable, $class_variable) >>
+
+This takes the name of a variable that will, when inlined, represent the object
+instance, and the name of a variable that will represent the class to rebless
+into, and returns code to rebless an instance into a class.
+
=back
=head2 Introspection