From: Stevan Little Date: Sun, 30 Apr 2006 16:45:04 +0000 (+0000) Subject: tweaking X-Git-Tag: 0_29_02~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1becdfcc1aa4102e91536addfb69cdd0a2b97388;p=gitmo%2FClass-MOP.git tweaking --- diff --git a/Changes b/Changes index 27c5472..71574da 100644 --- a/Changes +++ b/Changes @@ -2,13 +2,28 @@ Revision history for Perl extension Class-MOP. 0.30 * Class::MOP::Instance - - added new instance construction protocol + - added new instance protocol - added tests for this - changed all relevant modules and examples - Class::MOP::Class - Class::MOP::Attribute - examples/* + * metaclass + - you no longer need to specify the metaclass + itself, if it is not there, Class::MOP::Class + is just assumed + - updated tests for this + + * examples/ + - added ArrayBasedStorage example to show + instance storage using ARRAY refs instead of + HASH refs. + - added tests for this + - InsideOutClass is totally revised using the + new instance protocol + - added more tests for this + 0.26 Mon. April 24, 2006 * Class::MOP::Class - added find_attribute_by_name method diff --git a/examples/ArrayBasedStorage.pod b/examples/ArrayBasedStorage.pod index 0702eef..8268d4c 100644 --- a/examples/ArrayBasedStorage.pod +++ b/examples/ArrayBasedStorage.pod @@ -67,7 +67,7 @@ ArrayBasedStorage - An example of an Array based instance storage package Foo; - use metaclass 'Class::MOP::Class' => ( + use metaclass ( ':instance_metaclass' => 'ArrayBasedStorage::Instance' ); @@ -88,6 +88,10 @@ ArrayBasedStorage - An example of an Array based instance storage This is a proof of concept using the Instance sub-protocol which uses ARRAY refs to store the instance data. +This is very similar now to the InsideOutClass example, and +in fact, they both share the exact same test suite, with +the only difference being the Instance metaclass they use. + =head1 AUTHOR Stevan Little Estevan@iinteractive.comE diff --git a/examples/InsideOutClass.pod b/examples/InsideOutClass.pod index 0bf4db6..8466b76 100644 --- a/examples/InsideOutClass.pod +++ b/examples/InsideOutClass.pod @@ -54,7 +54,7 @@ InsideOutClass - A set of example metaclasses which implement the Inside-Out tec package Foo; - use metaclass 'Class::MOP::Class' => ( + use metaclass ( ':instance_metaclass' => 'InsideOutClass::Instance' ); diff --git a/examples/LazyClass.pod b/examples/LazyClass.pod index b4c308c..f28a23e 100644 --- a/examples/LazyClass.pod +++ b/examples/LazyClass.pod @@ -91,8 +91,9 @@ LazyClass - An example metaclass with lazy initialization package BinaryTree; - use metaclass 'Class::MOP::Class' => ( - ':attribute_metaclass' => 'LazyClass::Attribute' + use metaclass ( + ':attribute_metaclass' => 'LazyClass::Attribute', + ':instance_metaclass' => 'LazyClass::Instance', ); BinaryTree->meta->add_attribute('$:node' => ( diff --git a/lib/Class/MOP/Instance.pm b/lib/Class/MOP/Instance.pm index f79c063..48c63ef 100644 --- a/lib/Class/MOP/Instance.pm +++ b/lib/Class/MOP/Instance.pm @@ -114,7 +114,7 @@ Class::MOP::Instance - Instance Meta Object use strict; use warnings; - use metaclass 'Class::MOP::Class' => ( + use metaclass ( ':instance_metaclass' => 'ArrayBasedStorage::Instance', ); @@ -129,9 +129,9 @@ This may seem like over-abstraction, but by abstracting this process into a sub-protocol we make it possible to easily switch the details of how an object's instance is stored with minimal impact. In most cases just subclassing -this class will be all you need to do (occasionally it -requires that you also subclass Class::MOP::Attribute if -you require some kind of specific attribute initializations). +this class will be all you need to do (see the examples; +F and +F for details). =head1 METHODS diff --git a/lib/metaclass.pm b/lib/metaclass.pm index b09417e..b5658dc 100644 --- a/lib/metaclass.pm +++ b/lib/metaclass.pm @@ -7,19 +7,24 @@ use warnings; use Carp 'confess'; use Scalar::Util 'blessed'; -our $VERSION = '0.02'; +our $VERSION = '0.03'; use Class::MOP; sub import { shift; - my $metaclass = shift || 'Class::MOP::Class'; + my $metaclass; + if (!defined($_[0]) || $_[0] =~ /^\:(attribute|method|instance)_metaclass/) { + $metaclass = 'Class::MOP::Class'; + } + else { + $metaclass = shift; + ($metaclass->isa('Class::MOP::Class')) + || confess 'The metaclass must be derived from Class::MOP::Class'; + } my %options = @_; my $package = caller(); - ($metaclass->isa('Class::MOP::Class')) - || confess 'The metaclass must be derived from Class::MOP::Class'; - # create a meta object so we can install &meta my $meta = $metaclass->initialize($package => %options); $meta->add_method('meta' => sub { @@ -60,6 +65,14 @@ metaclass - a pragma for installing and using Class::MOP metaclasses ':method_metaclass' => 'MyMethodMetaClass', ); + # ... or just specify custom attribute + # and method classes, and Class::MOP::Class + # is the assumed metaclass + use metaclass ( + ':attribute_metaclass' => 'MyAttributeMetaClass', + ':method_metaclass' => 'MyMethodMetaClass', + ); + =head1 DESCRIPTION This is a pragma to make it easier to use a specific metaclass diff --git a/t/102_InsideOutClass_test.t b/t/102_InsideOutClass_test.t index ccee85e..658930e 100644 --- a/t/102_InsideOutClass_test.t +++ b/t/102_InsideOutClass_test.t @@ -17,7 +17,7 @@ BEGIN { use strict; use warnings; - use metaclass 'Class::MOP::Class' => ( + use metaclass ( ':instance_metaclass' => 'InsideOutClass::Instance' ); @@ -53,7 +53,7 @@ BEGIN { use strict; use warnings; - use metaclass 'Class::MOP::Class' => ( + use metaclass ( ':instance_metaclass' => 'InsideOutClass::Instance' ); diff --git a/t/106_LazyClass_test.t b/t/106_LazyClass_test.t index 466f55a..d9a8924 100644 --- a/t/106_LazyClass_test.t +++ b/t/106_LazyClass_test.t @@ -14,7 +14,7 @@ BEGIN { { package BinaryTree; - use metaclass 'Class::MOP::Class' => ( + use metaclass ( ':attribute_metaclass' => 'LazyClass::Attribute', ':instance_metaclass' => 'LazyClass::Instance', ); diff --git a/t/108_ArrayBasedStorage_test.t b/t/108_ArrayBasedStorage_test.t index faf4378..74bc438 100644 --- a/t/108_ArrayBasedStorage_test.t +++ b/t/108_ArrayBasedStorage_test.t @@ -16,7 +16,7 @@ BEGIN { use strict; use warnings; - use metaclass 'Class::MOP::Class' => ( + use metaclass ( ':instance_metaclass' => 'ArrayBasedStorage::Instance', ); @@ -52,7 +52,7 @@ BEGIN { use strict; use warnings; - use metaclass 'Class::MOP::Class' => ( + use metaclass ( ':instance_metaclass' => 'ArrayBasedStorage::Instance', );