since all the same info can be gotten from the
attribute meta-object itself
- updated docs & tests to reflect
-
+ - added &clone_instance method which does a deep clone
+ of the instance structure created by &construct_instance
+ - added docs & tests for this
+ - added &new_object and &clone_object convience methods to
+ return blessed new or cloned instances
+ - added docs & tests for this
+
* examples/
- adjusting code to use the &Class::MOP::Class::meta
fix detailed above
- clean up all ->initialize($_[0]) handling
-(DONE)
+(PARTIALLY DONE) - needs tests
We should always be sure that $_[0] is a package name, and not
a blessed intstance.
- General Purpose &clone_instance method
-(PARTIALLY DONE) - need to implement the deep cloning
+(PARTIALLY DONE) - need to implement the deep cloning & tests
It can be a method of the metaclass, like construct_instance is,
actually it should be called clone_instance, and it should
- General Purpose &new_object and &clone_object method
+(PARTIALLY DONE) - needs tests
+
I seem to be writing a new method each time, but since we dont
have a Object class to always inherit from, this is needed.
However, there is nothing to say that I cannot do something like:
- Foo->meta->new_object()
+ Foo->meta->new_object(%params)
and ...
- $foo->meta->clone_object()
+ $foo->meta->clone_object($foo, %params)
Give it some more thought, but I think it is the best way to
approach this.
} => $class;
}
else {
+ # NOTE:
+ # it is safe to use meta here because
+ # class will always be a subclass of
+ # Class::MOP::Class, which defines meta
bless $class->meta->construct_instance(':package' => $package_name, @_) => $class
}
}
# Instance Construction & Cloning
+sub new_object {
+ my $class = shift;
+ bless $class->construct_instance(@_) => $class->name;
+}
sub construct_instance {
my ($class, %params) = @_;
return $instance;
}
+sub clone_object {
+ my $class = shift;
+ my $instance = shift;
+ bless $class->clone_instance($instance, @_) => $class->name;
+}
+
sub clone_instance {
my ($class, $self, %params) = @_;
(blessed($self))
=over 4
+=item B<new_object (%params)>
+
+This is a convience method for creating a new object of the class, and
+blessing it into the appropriate package as well. Ideally your class
+would call a C<new> this method like so:
+
+ sub MyClass::new {
+ my ($class, %param) = @_;
+ $class->meta->new_object(%params);
+ }
+
+Of course the ideal place for this would actually be in C<UNIVERSAL::>
+but that is considered bad style, so we do not do that.
+
=item B<construct_instance (%params)>
This method is used to construct an instace structure suitable for
in C<%params> or any default value or initializer found in the
attribute meta-object.
+=item B<clone_object ($instance, %params)>
+
+This is a convience method for cloning an object instance, then
+blessing it into the appropriate package. Ideally your class
+would call a C<clone> this method like so:
+
+ sub MyClass::clone {
+ my ($self, %param) = @_;
+ $self->meta->clone_object($self, %params);
+ }
+
+Of course the ideal place for this would actually be in C<UNIVERSAL::>
+but that is considered bad style, so we do not do that.
+
=item B<clone_instance($instance, %params)>
This method is a compliment of C<construct_instance> (which means if