0.05
* Class::MOP::Class
- added the &attribute_metaclass and &method_metaclass
- functions which return a metaclass name to use for
+ attributes which contain a metaclass name to use for
attributes/methods respectively
+
+ * Class::MOP
+ - bootstrap additional attributes for Class::MOP::Class
* examples/
- adjusted the example code and tests to use the new
t/010_self_introspection.t
t/011_create_class.t
t/012_package_variables.t
+t/013_add_attribute_alternate.t
t/020_attribute.t
t/030_method.t
t/100_BinaryTree_test.t
-Class::MOP version 0.04
+Class::MOP version 0.05
===========================
See the individual module documentation for more information
use Class::MOP 'meta';
-our $VERSION = '0.01';
+our $VERSION = '0.02';
use base 'Class::MOP::Class';
+sub initialize {
+ (shift)->SUPER::initialize(@_,
+ # use the custom attribute metaclass here
+ ':attribute_metaclass' => 'ClassEncapsulatedAttributes::Attribute'
+ );
+}
+
sub construct_instance {
my ($class, %params) = @_;
my $instance = {};
return $instance;
}
-sub attribute_metaclass { 'ClassEncapsulatedAttributes::Attribute' }
-
package # hide the package from PAUSE
ClassEncapsulatedAttributes::Attribute;
return $instance;
}
-sub attribute_metaclass { 'InsideOutClass::Attribute' }
-
package # hide the package from PAUSE
InsideOutClass::Attribute;
package Foo;
- sub meta { InsideOutClass->initialize($_[0]) }
+ sub meta {
+ InsideOutClass->initialize($_[0] => (
+ # tell our metaclass to use the
+ # InsideOut attribute metclass
+ # to construct all it's attributes
+ ':attribute_metaclass' => 'InsideOutClass::Attribute'
+ ))
+ }
__PACKAGE__->meta->add_attribute('foo' => (
reader => 'get_foo',
## Class::MOP::Class
Class::MOP::Class->meta->add_attribute(
- Class::MOP::Attribute->new('$:pkg' => (
- init_arg => ':pkg'
+ Class::MOP::Attribute->new('$:package' => (
+ init_arg => ':package'
))
);
Class::MOP::Class->meta->add_attribute(
- Class::MOP::Attribute->new('%:attrs' => (
- init_arg => ':attrs',
+ Class::MOP::Attribute->new('%:attributes' => (
+ init_arg => ':attributes',
default => sub { {} }
))
);
+Class::MOP::Class->meta->add_attribute(
+ Class::MOP::Attribute->new('$:attribute_metaclass' => (
+ init_arg => ':attribute_metaclass',
+ default => 'Class::MOP::Attribute',
+ ))
+);
+
+Class::MOP::Class->meta->add_attribute(
+ Class::MOP::Attribute->new('$:method_metaclass' => (
+ init_arg => ':method_metaclass',
+ default => 'Class::MOP::Method',
+ ))
+);
+
## Class::MOP::Attribute
Class::MOP::Attribute->meta->add_attribute(Class::MOP::Attribute->new('name'));
# After all, do package definitions even get reaped?
my %METAS;
sub initialize {
- my ($class, $package_name) = @_;
+ my $class = shift;
+ my $package_name = shift;
(defined $package_name && $package_name)
|| confess "You must pass a package name";
return $METAS{$package_name} if exists $METAS{$package_name};
- $METAS{$package_name} = $class->construct_class_instance($package_name);
+ $METAS{$package_name} = $class->construct_class_instance($package_name, @_);
}
# NOTE: (meta-circularity)
# class. All other classes will use the more
# normal &construct_instance.
sub construct_class_instance {
- my ($class, $package_name) = @_;
+ my $class = shift;
+ my $package_name = shift;
(defined $package_name && $package_name)
|| confess "You must pass a package name";
$class = blessed($class) || $class;
if ($class =~ /^Class::MOP::/) {
bless {
- '$:pkg' => $package_name,
- '%:attrs' => {}
+ '$:package' => $package_name,
+ '%:attributes' => {},
+ '$:attribute_metaclass' => 'Class::MOP::Attribute',
+ '$:method_metaclass' => 'Class::MOP::Method',
} => $class;
}
else {
- bless $class->meta->construct_instance(':pkg' => $package_name) => $class
+ bless $class->meta->construct_instance(':package' => $package_name, @_) => $class
}
}
}
# Informational
-sub name { $_[0]->{'$:pkg'} }
+sub name { $_[0]->{'$:package'} }
sub version {
my $self = shift;
## Methods
# un-used right now ...
-sub method_metaclass { 'Class::MOP::Method' }
+sub method_metaclass { $_[0]->{'$:method_metaclass'} }
sub add_method {
my ($self, $method_name, $method) = @_;
## Attributes
-sub attribute_metaclass { 'Class::MOP::Attribute' }
+sub attribute_metaclass { $_[0]->{'$:attribute_metaclass'} }
sub add_attribute {
my $self = shift;
use strict;
use warnings;
-use Test::More tests => 56;
+use Test::More tests => 60;
use Test::Exception;
BEGIN {
}
foreach my $attribute_name (
- '$:pkg', '%:attrs'
+ '$:package', '%:attributes',
+ '$:attribute_metaclass', '$:method_metaclass'
) {
ok($meta->has_attribute($attribute_name), '... Class::MOP::Class->has_attribute(' . $attribute_name . ')');
isa_ok($meta->get_attribute($attribute_name), 'Class::MOP::Attribute');
{
package Foo;
- sub meta { InsideOutClass->initialize($_[0]) }
+ sub meta {
+ InsideOutClass->initialize($_[0] => (
+ ':attribute_metaclass' => 'InsideOutClass::Attribute'
+ ))
+ }
Foo->meta->add_attribute('foo' => (
accessor => 'foo',