Revision history for Perl extension Class-MOP.
+0.30
+ * Class::MOP::Instance
+ - added new instance construction protocol
+ - added tests for this
+ - changed all relevant modules and examples
+ - Class::MOP::Class
+ - Class::MOP::Attribute
+ - examples/*
+
0.26 Mon. April 24, 2006
* Class::MOP::Class
- added find_attribute_by_name method
-Class::MOP version 0.26
+Class::MOP version 0.30
===========================
See the individual module documentation for more information
use strict;
use warnings;
-our $VERSION = '0.05';
+our $VERSION = '0.06';
use base 'Class::MOP::Class';
use strict;
use warnings;
-our $VERSION = '0.03';
+our $VERSION = '0.04';
use base 'Class::MOP::Attribute';
$val = $self->default($meta_instance->get_instance);
}
# now add this to the instance structure
- $meta_instance->get_slot_value($class->name)->{$self->name} = $val;
+ $meta_instance->get_slot_value(
+ $meta_instance->get_instance,
+ $class->name
+ )->{$self->name} = $val;
}
sub generate_accessor_method {
use strict;
use warnings;
-our $VERSION = '0.05';
+our $VERSION = '0.06';
use Carp 'confess';
use Scalar::Util 'refaddr';
use Carp 'confess';
-our $VERSION = '0.03';
+our $VERSION = '0.04';
use base 'Class::MOP::Attribute';
use Class::MOP::Attribute;
use Class::MOP::Method;
-our $VERSION = '0.26';
+our $VERSION = '0.30';
## ----------------------------------------------------------------------------
## Setting up our environment ...
))
);
+Class::MOP::Class->meta->add_attribute(
+ Class::MOP::Attribute->new('$:instance_metaclass' => (
+ reader => 'instance_metaclass',
+ init_arg => ':instance_metaclass',
+ default => 'Class::MOP::Instance',
+ ))
+);
+
## Class::MOP::Attribute
Class::MOP::Attribute->meta->add_attribute(
use Carp 'confess';
use Scalar::Util 'blessed', 'reftype', 'weaken';
-our $VERSION = '0.07';
+our $VERSION = '0.08';
sub meta {
require Class::MOP::Class;
sub generate_accessor_method {
my ($self, $attr_name) = @_;
+ my $meta_instance = $self->associated_class->instance_metaclass;
sub {
- $_[0]->{$attr_name} = $_[1] if scalar(@_) == 2;
- $_[0]->{$attr_name};
+ $meta_instance->set_slot_value($_[0], $attr_name, $_[1]) if scalar(@_) == 2;
+ $meta_instance->get_slot_value($_[0], $attr_name);
};
}
sub generate_reader_method {
my ($self, $attr_name) = @_;
+ my $meta_instance = $self->associated_class->instance_metaclass;
sub {
confess "Cannot assign a value to a read-only accessor" if @_ > 1;
- $_[0]->{$attr_name};
+ $meta_instance->get_slot_value($_[0], $attr_name);
};
}
sub generate_writer_method {
my ($self, $attr_name) = @_;
- sub { $_[0]->{$attr_name} = $_[1] };
+ my $meta_instance = $self->associated_class->instance_metaclass;
+ sub {
+ $meta_instance->set_slot_value($_[0], $attr_name, $_[1]);
+ };
}
sub generate_predicate_method {
my ($self, $attr_name) = @_;
- sub { defined $_[0]->{$attr_name} ? 1 : 0 };
+ my $meta_instance = $self->associated_class->instance_metaclass;
+ sub {
+ $meta_instance->has_slot_value($_[0], $attr_name);
+ };
}
sub process_accessors {
use Sub::Name 'subname';
use B 'svref_2object';
-our $VERSION = '0.13';
+our $VERSION = '0.14';
use Class::MOP::Instance;
'$:package' => $package_name,
'%:attributes' => {},
'$:attribute_metaclass' => $options{':attribute_metaclass'} || 'Class::MOP::Attribute',
- '$:method_metaclass' => $options{':method_metaclass'} || 'Class::MOP::Method',
+ '$:method_metaclass' => $options{':method_metaclass'} || 'Class::MOP::Method',
+ '$:instance_metaclass' => $options{':instance_metaclass'} || 'Class::MOP::Instance',
} => $class;
}
else {
sub get_attribute_map { $_[0]->{'%:attributes'} }
sub attribute_metaclass { $_[0]->{'$:attribute_metaclass'} }
sub method_metaclass { $_[0]->{'$:method_metaclass'} }
+sub instance_metaclass { $_[0]->{'$:instance_metaclass'} }
# Instance Construction & Cloning
sub construct_instance {
my ($class, %params) = @_;
- my $meta_instance = Class::MOP::Instance->new($class);
+ my $meta_instance = $class->instance_metaclass->new($class);
foreach my $attr ($class->compute_all_applicable_attributes()) {
$attr->initialize_instance_slot($class, $meta_instance, \%params);
}
=over 4
+=item B<instance_metaclass>
+
=item B<new_object (%params)>
This is a convience method for creating a new object of the class, and
}
sub get_slot_value {
- my ($self, $slot_name) = @_;
- return $self->{instance}->{$slot_name};
+ my ($self, $instance, $slot_name) = @_;
+ return $instance->{$slot_name};
}
-*set_slot_value = \&add_slot;
+sub set_slot_value {
+ my ($self, $instance, $slot_name, $value) = @_;
+ $instance->{$slot_name} = $value;
+}
+
+sub has_slot_value {
+ my ($self, $instance, $slot_name) = @_;
+ defined $instance->{$slot_name} ? 1 : 0;
+}
sub get_instance { (shift)->{instance} }
=item B<set_slot_value>
+=item B<has_slot_value>
+
=item B<get_instance>
=back
use strict;
use warnings;
-use Test::More tests => 136;
+use Test::More tests => 140;
use Test::Exception;
BEGIN {
initialize create create_anon_class
+ instance_metaclass
new_object clone_object
construct_instance construct_class_instance clone_instance
check_metaclass_compatability
# check for the right attributes
-my @attributes = ('$:package', '%:attributes', '$:attribute_metaclass', '$:method_metaclass');
+my @attributes = (
+ '$:package',
+ '%:attributes',
+ '$:attribute_metaclass',
+ '$:method_metaclass',
+ '$:instance_metaclass'
+);
is_deeply(
[ sort @attributes ],
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+use Test::Exception;
+
+use Scalar::Util 'reftype', 'isweak';
+
+BEGIN {
+ use_ok('Class::MOP::Instance');
+}
+