Revision history for Perl extension Class-MOP.
0.06
+ * metaclass
+ - adding new metaclass pragma to make assiging the
+ metaclass a little more straightforward
+
* Class::MOP::Class
- fixing minor meta-circularity issue with &meta, it
is now more useful for subclasses
* examples/
- adjusting code to use the &Class::MOP::Class::meta
fix detailed above
+ - adjusting code to use the metaclass pragma
0.05 Sat Feb. 4, 2006
* Class::MOP::Class
package Foo;
- sub meta { ClassEncapsulatedAttributes->initialize($_[0]) }
+ use metaclass 'ClassEncapsulatedAttributes';
Foo->meta->add_attribute('foo' => (
accessor => 'Foo_foo',
package Foo;
- sub meta {
- InsideOutClass->initialize($_[0] => (
- # tell our metaclass to use the
- # InsideOut attribute metclass
- # to construct all it's attributes
- ':attribute_metaclass' => 'InsideOutClass::Attribute'
- ))
- }
+ use metaclass 'InsideOutClass' => (
+ # 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',
package Foo;
- sub meta { InstanceCountingClass->initialize($_[0]) }
+ use metaclass 'InstanceCountingClass';
+
sub new {
my $class = shift;
bless $class->meta->construct_instance(@_) => $class;
package BinaryTree;
- sub meta {
- LazyClass->initialize($_[0] => (
- ':attribute_metaclass' => 'LazyClass::Attribute'
- ));
- }
+ use metaclass 'LazyClass' => (
+ ':attribute_metaclass' => 'LazyClass::Attribute'
+ );
BinaryTree->meta->add_attribute('$:node' => (
accessor => 'node',
--- /dev/null
+
+package metaclass;
+
+use strict;
+use warnings;
+
+use Carp 'confess';
+
+our $VERSION = '0.01';
+
+use Class::MOP;
+
+sub import {
+ shift;
+ my $metaclass = shift;
+ 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 {
+ # we must re-initialize so that it
+ # works as expected in subclasses,
+ # since metaclass instances are
+ # singletons, this is not really a
+ # big deal anyway.
+ $metaclass->initialize($_[0] => %options)
+ });
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+metaclass - a pragma for installing using Class::MOP metaclasses
+
+=head1 SYNOPSIS
+
+ use metaclass 'MyMetaClass';
+
+ use metaclass 'MyMetaClass' => (
+ ':attribute_metaclass' => 'MyAttributeMetaClass',
+ ':method_metaclass' => 'MyMethodMetaClass',
+ );
+
+=head1 DESCRIPTION
+
+=head1 AUTHOR
+
+Stevan Little E<lt>stevan@iinteractive.comE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2006 by Infinity Interactive, Inc.
+
+L<http://www.iinteractive.com>
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
\ No newline at end of file
{
package Foo;
- sub meta { InstanceCountingClass->initialize($_[0]) }
+ use metaclass 'InstanceCountingClass';
+
sub new {
my $class = shift;
bless $class->meta->construct_instance(@_) => $class;
{
package Foo;
- sub meta {
- InsideOutClass->initialize($_[0] => (
- ':attribute_metaclass' => 'InsideOutClass::Attribute'
- ))
- }
+ use metaclass 'InsideOutClass' => (
+ ':attribute_metaclass' => 'InsideOutClass::Attribute'
+ );
Foo->meta->add_attribute('foo' => (
accessor => 'foo',
{
package Foo;
- sub meta { ClassEncapsulatedAttributes->initialize($_[0]) }
+ use metaclass 'ClassEncapsulatedAttributes';
Foo->meta->add_attribute('foo' => (
accessor => 'foo',
{
package BinaryTree;
- sub meta {
- LazyClass->initialize($_[0] => (
- ':attribute_metaclass' => 'LazyClass::Attribute'
- ));
- }
+ use metaclass 'LazyClass' => (
+ ':attribute_metaclass' => 'LazyClass::Attribute'
+ );
BinaryTree->meta->add_attribute('$:node' => (
accessor => 'node',