From: Dave Rolsky Date: Wed, 20 Jan 2010 21:49:39 +0000 (-0600) Subject: Moved some code to a shared mixin role so we can apply a role to the role metaclass X-Git-Tag: 0.11~31 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aa6390299985f34313f45864361226b8e72ec272;p=gitmo%2FMooseX-ClassAttribute.git Moved some code to a shared mixin role so we can apply a role to the role metaclass --- diff --git a/lib/MooseX/ClassAttribute.pm b/lib/MooseX/ClassAttribute.pm index 286fbaa..0f1c265 100644 --- a/lib/MooseX/ClassAttribute.pm +++ b/lib/MooseX/ClassAttribute.pm @@ -19,13 +19,14 @@ sub init_meta { Moose->init_meta(%p); return Moose::Util::MetaRole::apply_metaclass_roles( - for_class => $p{for_class}, + for => $p{for_class}, class_metaroles => { class => ['MooseX::ClassAttribute::Role::Meta::Class'], }, - role_metaroles => { - role => ['MooseX::ClassAttribute::Role::Meta::Role'], - }, + + # role_metaroles => { + # role => ['MooseX::ClassAttribute::Role::Meta::Role'], + # }, ); } diff --git a/lib/MooseX/ClassAttribute/Role/Meta/Class.pm b/lib/MooseX/ClassAttribute/Role/Meta/Class.pm index 7ec220f..e9ef9da 100644 --- a/lib/MooseX/ClassAttribute/Role/Meta/Class.pm +++ b/lib/MooseX/ClassAttribute/Role/Meta/Class.pm @@ -3,39 +3,27 @@ package MooseX::ClassAttribute::Role::Meta::Class; use strict; use warnings; -use MooseX::AttributeHelpers; use MooseX::ClassAttribute::Role::Meta::Attribute; use Scalar::Util qw( blessed ); +use namespace::autoclean; use Moose::Role; -has class_attribute_map => ( - metaclass => 'Collection::Hash', - is => 'ro', - isa => 'HashRef[Moose::Meta::Attribute]', - provides => { - set => '_add_class_attribute', - exists => 'has_class_attribute', - get => 'get_class_attribute', - delete => '_remove_class_attribute', - keys => 'get_class_attribute_list', - }, - default => sub { {} }, - reader => 'get_class_attribute_map', -); +with 'MooseX::ClassAttribute::Role::Meta::Mixin::HasClassAttributes'; has _class_attribute_values => ( - metaclass => 'Collection::Hash', - is => 'ro', - isa => 'HashRef', - provides => { - get => 'get_class_attribute_value', - set => 'set_class_attribute_value', - exists => 'has_class_attribute_value', - delete => 'clear_class_attribute_value', + traits => ['Hash'], + is => 'ro', + isa => 'HashRef', + handles => { + 'get_class_attribute_value' => 'get', + 'set_class_attribute_value' => 'set', + 'has_class_attribute_value' => 'exists', + 'clear_class_attribute_value' => 'delete', }, - lazy => 1, - default => sub { $_[0]->_class_attribute_values_hashref() }, + lazy => 1, + default => sub { $_[0]->_class_attribute_values_hashref() }, + init_arg => undef, ); sub add_class_attribute { @@ -234,8 +222,6 @@ sub inline_weaken_class_slot_value { . $self->inline_class_slot_access($name) . ')'; } -no Moose::Role; - 1; __END__ diff --git a/lib/MooseX/ClassAttribute/Role/Meta/Mixin/HasClassAttributes.pm b/lib/MooseX/ClassAttribute/Role/Meta/Mixin/HasClassAttributes.pm new file mode 100644 index 0000000..82144d8 --- /dev/null +++ b/lib/MooseX/ClassAttribute/Role/Meta/Mixin/HasClassAttributes.pm @@ -0,0 +1,28 @@ +package MooseX::ClassAttribute::Role::Meta::Mixin::HasClassAttributes; + +use strict; +use warnings; + +use namespace::autoclean; +use Moose::Role; + +has _class_attribute_map => ( + traits => ['Hash'], + is => 'ro', + isa => 'HashRef[Moose::Meta::Attribute]', + handles => { + '_add_class_attribute' => 'set', + 'has_class_attribute' => 'exists', + 'get_class_attribute' => 'get', + '_remove_class_attribute' => 'delete', + 'get_class_attribute_list' => 'keys', + }, + default => sub { {} }, + init_arg => undef, +); + +sub get_class_attribute_map { + return $_[0]->_class_attribute_map(); +} + +1; diff --git a/t/04-with-attribute-helpers.t b/t/04-with-attribute-helpers.t deleted file mode 100644 index 4154b5a..0000000 --- a/t/04-with-attribute-helpers.t +++ /dev/null @@ -1,23 +0,0 @@ -use strict; -use warnings; - -use Test::More tests => 2; - -{ - package MyClass; - - use MooseX::ClassAttribute; - use MooseX::AttributeHelpers; - - class_has counter => - ( metaclass => 'Counter', - is => 'ro', - provides => { inc => 'inc_counter', - }, - ); -} - -is( MyClass->counter(), 0 ); - -MyClass->inc_counter(); -is( MyClass->counter(), 1 );