return $instance;
}
+sub inline_create_instance {
+ my $self = shift;
+ my ($class) = @_;
+
+ return $self->get_meta_instance->inline_create_instance($class);
+}
+
sub clone_object {
my $class = shift;
my $instance = shift;
Returns an instance of the C<instance_metaclass> to be used in the
construction of a new instance of the class.
+=item B<< $metaclass->inline_create_instance($class_var) >>
+
+This method takes a variable name, and uses it create an inline snippet of
+code that will create a new instance of the class.
+
=back
=head2 Informational predicates
## cached values ...
-sub _meta_instance {
- my $self = shift;
- $self->{'meta_instance'} ||= $self->associated_metaclass->get_meta_instance;
-}
-
sub _attributes {
my $self = shift;
$self->{'attributes'} ||= [ $self->associated_metaclass->get_all_attributes ]
$source .= "\n" . 'my $params = @_ == 1 ? $_[0] : {@_};';
- $source .= "\n" . 'my $instance = ' . $self->_meta_instance->inline_create_instance('$class');
+ $source .= "\n" . 'my $instance = ' . $self->associated_metaclass->inline_create_instance('$class');
my $idx = 0;
$source .= ";\n" . (join ";\n" => map {
$self->_generate_slot_initializer($_, $idx++)
}
if ( defined( my $init_arg = $attr->init_arg ) ) {
- my $mi = $self->_meta_instance;
- my $attr_name = $attr->name;
-
return (
'if(exists $params->{\''
. $init_arg . '\'}){' . "\n"
- . $mi->inline_set_slot_value(
+ . $attr->inline_set(
'$instance',
- $attr_name,
'$params->{\'' . $init_arg . '\'}'
)
. "\n" . '} '
. (
!defined $default ? '' : 'else {' . "\n"
- . $mi->inline_set_slot_value(
+ . $attr->inline_set(
'$instance',
- $attr_name,
$default
)
. "\n" . '}'
}
elsif ( defined $default ) {
return (
- $self->_meta_instance->inline_set_slot_value(
+ $attr->inline_set(
'$instance',
- $attr->name,
$default
)
. "\n"
create_anon_class is_anon_class
instance_metaclass get_meta_instance
+ inline_create_instance
create_meta_instance _create_meta_instance
new_object clone_object
construct_instance _construct_instance