From: Stevan Little Date: Sun, 6 Apr 2008 20:58:02 +0000 (+0000) Subject: more refactoring to roles X-Git-Tag: 0.04~41 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=de7ba0e9ecf939dde2aeab3a752041a916c93d88;p=gitmo%2FMooseX-MetaDescription.git more refactoring to roles --- diff --git a/lib/MooseX/MetaDescription/Description.pm b/lib/MooseX/MetaDescription/Description.pm index 0008015..aeefdd7 100644 --- a/lib/MooseX/MetaDescription/Description.pm +++ b/lib/MooseX/MetaDescription/Description.pm @@ -4,6 +4,11 @@ use Moose; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; +has 'descriptor' => ( + is => 'ro', + required => 1, +); + no Moose; 1; __END__ diff --git a/lib/MooseX/MetaDescription/Description/Attribute.pm b/lib/MooseX/MetaDescription/Description/Attribute.pm index 0b945f6..36489cd 100644 --- a/lib/MooseX/MetaDescription/Description/Attribute.pm +++ b/lib/MooseX/MetaDescription/Description/Attribute.pm @@ -6,11 +6,8 @@ our $AUTHORITY = 'cpan:STEVAN'; extends 'MooseX::MetaDescription::Description'; -has 'attribute' => ( - is => 'ro', - does => 'MooseX::MetaDescription::Meta::Attribute::Trait', - weak_ref => 1, - required => 1, +has '+descriptor' => ( + does => 'MooseX::MetaDescription::Meta::Attribute::Trait', ); no Moose; 1; diff --git a/lib/MooseX/MetaDescription/Description/Class.pm b/lib/MooseX/MetaDescription/Description/Class.pm index 23a2f73..cc5f63d 100644 --- a/lib/MooseX/MetaDescription/Description/Class.pm +++ b/lib/MooseX/MetaDescription/Description/Class.pm @@ -6,11 +6,8 @@ our $AUTHORITY = 'cpan:STEVAN'; extends 'MooseX::MetaDescription::Description'; -has 'class' => ( - isa => 'MooseX::MetaDescription::Meta::Class', - is => 'ro', - weak_ref => 1, - required => 1, +has '+descriptor' => ( + isa => 'MooseX::MetaDescription::Meta::Class', ); no Moose; 1; diff --git a/lib/MooseX/MetaDescription/Meta/Attribute/Trait.pm b/lib/MooseX/MetaDescription/Meta/Attribute/Trait.pm index 3692411..d7ee8d5 100644 --- a/lib/MooseX/MetaDescription/Meta/Attribute/Trait.pm +++ b/lib/MooseX/MetaDescription/Meta/Attribute/Trait.pm @@ -6,26 +6,11 @@ use MooseX::MetaDescription::Description::Attribute; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; -has 'description' => ( - is => 'ro', - isa => 'HashRef', - lazy => 1, - default => sub { +{} }, -); +with 'MooseX::MetaDescription::Meta::Role::HasMetaDescription'; -has 'metadescription' => ( - is => 'ro', - isa => 'MooseX::MetaDescription::Description', - lazy => 1, - default => sub { - my $self = shift; - - # TODO: handle traits ... - - MooseX::MetaDescription::Description::Attribute->new( - %{$self->description}, - attribute => $self, - ) +has '+metadescription_classname' => ( + default => sub { + 'MooseX::MetaDescription::Description::Attribute' }, ); diff --git a/lib/MooseX/MetaDescription/Meta/Class.pm b/lib/MooseX/MetaDescription/Meta/Class.pm index 3e0395c..ee53920 100644 --- a/lib/MooseX/MetaDescription/Meta/Class.pm +++ b/lib/MooseX/MetaDescription/Meta/Class.pm @@ -7,27 +7,11 @@ our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; extends 'Moose::Meta::Class'; + with 'MooseX::MetaDescription::Meta::Role::HasMetaDescription'; -has 'description' => ( - is => 'ro', - isa => 'HashRef', - lazy => 1, - default => sub { +{} }, -); - -has 'metadescription' => ( - is => 'ro', - isa => 'MooseX::MetaDescription::Description', - lazy => 1, +has '+metadescription_classname' => ( default => sub { - my $self = shift; - - # TODO: handle traits ... - - MooseX::MetaDescription::Description::Class->new( - %{$self->description}, - class => $self, - ) + 'MooseX::MetaDescription::Description::Class' }, ); @@ -47,7 +31,7 @@ MooseX::MetaDescription::Meta::Class - A Moosey solution to this problem =head1 DESCRIPTION -=head1 METHODS +=head1 METHODS =over 4 @@ -57,7 +41,7 @@ MooseX::MetaDescription::Meta::Class - A Moosey solution to this problem =head1 BUGS -All complex software has bugs lurking in it, and this module is no +All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. diff --git a/lib/MooseX/MetaDescription/Meta/Role/HasDescription.pm b/lib/MooseX/MetaDescription/Meta/Role/HasDescription.pm new file mode 100644 index 0000000..cdb56df --- /dev/null +++ b/lib/MooseX/MetaDescription/Meta/Role/HasDescription.pm @@ -0,0 +1,57 @@ +package MooseX::MetaDescription::Meta::Role::HasDescription; +use Moose::Role; + +our $VERSION = '0.01'; +our $AUTHORITY = 'cpan:STEVAN'; + +has 'description' => ( + is => 'ro', + isa => 'HashRef', + lazy => 1, + default => sub { +{} }, +); + +no Moose::Role; 1; + +__END__ + +=pod + +=head1 NAME + +MooseX::MetaDescription::Meta::Role::HasDescription - A Moosey solution to this problem + +=head1 SYNOPSIS + + use MooseX::MetaDescription::Meta::Role::HasDescription; + +=head1 DESCRIPTION + +=head1 METHODS + +=over 4 + +=item B<> + +=back + +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 AUTHOR + +Stevan Little Estevan.little@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2008 Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/lib/MooseX/MetaDescription/Meta/Role/HasMetaDescription.pm b/lib/MooseX/MetaDescription/Meta/Role/HasMetaDescription.pm new file mode 100644 index 0000000..8ff41d3 --- /dev/null +++ b/lib/MooseX/MetaDescription/Meta/Role/HasMetaDescription.pm @@ -0,0 +1,73 @@ +package MooseX::MetaDescription::Meta::Role::HasMetaDescription; +use Moose::Role; + +our $VERSION = '0.01'; +our $AUTHORITY = 'cpan:STEVAN'; + +with 'MooseX::MetaDescription::Meta::Role::HasDescription'; + +has 'metadescription_classname' => ( + is => 'ro', + isa => 'Str', +); + +has 'metadescription' => ( + is => 'ro', + isa => 'MooseX::MetaDescription::Description', + lazy => 1, + default => sub { + my $self = shift; + + # TODO: handle traits ... + + $self->metadescription_classname->new( + %{$self->description}, + descriptor => $self, + ) + }, +); + +no Moose::Role; 1; + +__END__ + +=pod + +=head1 NAME + +MooseX::MetaDescription::Meta::Role::HasMetaDescription - A Moosey solution to this problem + +=head1 SYNOPSIS + + use MooseX::MetaDescription::Meta::Role::HasMetaDescription; + +=head1 DESCRIPTION + +=head1 METHODS + +=over 4 + +=item B<> + +=back + +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 AUTHOR + +Stevan Little Estevan.little@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2008 Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/t/000_load.t b/t/000_load.t index 1e5f285..170dd7b 100644 --- a/t/000_load.t +++ b/t/000_load.t @@ -13,6 +13,9 @@ BEGIN { use_ok('MooseX::MetaDescription::Meta::Attribute'); use_ok('MooseX::MetaDescription::Meta::Attribute::Trait'); + use_ok('MooseX::MetaDescription::Meta::Role::HasDescription'); + use_ok('MooseX::MetaDescription::Meta::Role::HasMetaDescription'); + use_ok('MooseX::MetaDescription::Description'); use_ok('MooseX::MetaDescription::Description::Class'); use_ok('MooseX::MetaDescription::Description::Attribute'); diff --git a/t/001_basic.t b/t/001_basic.t index 4fcfb5d..df22013 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -43,13 +43,13 @@ BEGIN { # check the meta-desc my $foo_class = Foo->meta; -is($foo_class->metadescription->class, $foo_class, '... got the circular ref'); +is($foo_class->metadescription->descriptor, $foo_class, '... got the circular ref'); my $bar_attr = Foo->meta->get_attribute('bar'); -is($bar_attr->metadescription->attribute, $bar_attr, '... got the circular ref'); +is($bar_attr->metadescription->descriptor, $bar_attr, '... got the circular ref'); my $baz_attr = Foo->meta->get_attribute('baz'); -is($baz_attr->metadescription->attribute, $baz_attr, '... got the circular ref'); +is($baz_attr->metadescription->descriptor, $baz_attr, '... got the circular ref'); # check the actual descs