From: Hans Dieter Pearcey Date: Fri, 10 Jul 2009 22:12:40 +0000 (-0400) Subject: Rename AttributeHelpers.pm to Attribute/Native.pm X-Git-Tag: 0.89_02~86 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fafc8b9b5fd3d9e4cc9f5ad57f3141109b263b1c;p=gitmo%2FMoose.git Rename AttributeHelpers.pm to Attribute/Native.pm Remove loading from Attribute::Native, leave only register_implementations there Give Native traits their shortnames by default (with just 'use Moose') --- diff --git a/lib/Moose.pm b/lib/Moose.pm index f98cdea..47e300c 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -34,6 +34,8 @@ use Moose::Meta::Role::Application::ToInstance; use Moose::Util::TypeConstraints; use Moose::Util (); +use Moose::Attribute::Native; + sub throw_error { # FIXME This shift; diff --git a/lib/Moose/AttributeHelpers.pm b/lib/Moose/Attribute/Native.pm similarity index 77% rename from lib/Moose/AttributeHelpers.pm rename to lib/Moose/Attribute/Native.pm index 7301167..7a3c28b 100644 --- a/lib/Moose/AttributeHelpers.pm +++ b/lib/Moose/Attribute/Native.pm @@ -1,18 +1,31 @@ -package Moose::AttributeHelpers; +package Moose::Attribute::Native; our $VERSION = '0.87'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use Moose (); - -use Moose::Meta::Attribute::Trait::Native::Bool; -use Moose::Meta::Attribute::Trait::Native::Counter; -use Moose::Meta::Attribute::Trait::Native::Number; -use Moose::Meta::Attribute::Trait::Native::String; -use Moose::Meta::Attribute::Trait::Native::Array; -use Moose::Meta::Attribute::Trait::Native::Hash; +my @trait_names = qw(Bool Counter Number String Array Hash); + +for my $trait_name (@trait_names) { + my $trait_class = "Moose::Meta::Attribute::Trait::Native::$trait_name"; + my $meta = Class::MOP::Class->initialize( + "Moose::Meta::Attribute::Custom::Trait::$trait_name" + ); + if ($meta->find_method_by_name('register_implementation')) { + my $class = $meta->name->register_implementation; + Moose->throw_error( + "An implementation for $trait_name already exists " . + "(found '$class' when trying to register '$trait_class')" + ); + } + $meta->add_method(register_implementation => sub { + # resolve_metatrait_alias will load classes anyway, but throws away + # their error message; we WANT to die if there's a problem + Class::MOP::load_class($trait_class); + return $trait_class; + }); +} 1; @@ -22,13 +35,13 @@ __END__ =head1 NAME -Moose::AttributeHelpers - Extend your attribute interfaces +Moose::Attribute::Native - Extend your attribute interfaces =head1 SYNOPSIS package MyClass; use Moose; - use Moose::AttributeHelpers; + use Moose::Attribute::Native; has 'mapping' => ( traits => [ 'Hash' ], diff --git a/lib/Moose/Meta/Attribute/Trait/Native/Array.pm b/lib/Moose/Meta/Attribute/Trait/Native/Array.pm index 61e66ee..1fcbe7c 100644 --- a/lib/Moose/Meta/Attribute/Trait/Native/Array.pm +++ b/lib/Moose/Meta/Attribute/Trait/Native/Array.pm @@ -8,7 +8,7 @@ our $AUTHORITY = 'cpan:STEVAN'; use Moose::Meta::Attribute::Trait::Native::MethodProvider::Array; -with 'Moose::Meta::Attribute::Trait::Native::Collection'; +with 'Moose::Meta::Attribute::Trait::Native'; has 'method_provider' => ( is => 'ro', @@ -21,13 +21,6 @@ sub _helper_type { 'ArrayRef' } no Moose::Role; -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::Trait::Array; -sub register_implementation { - 'Moose::Meta::Attribute::Trait::Native::Array' -} - - 1; __END__ diff --git a/lib/Moose/Meta/Attribute/Trait/Native/Bool.pm b/lib/Moose/Meta/Attribute/Trait/Native/Bool.pm index ae6deab..aba8f58 100644 --- a/lib/Moose/Meta/Attribute/Trait/Native/Bool.pm +++ b/lib/Moose/Meta/Attribute/Trait/Native/Bool.pm @@ -23,10 +23,6 @@ has 'method_provider' => ( no Moose::Role; -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::Trait::Bool; -sub register_implementation { 'Moose::Meta::Attribute::Trait::Native::Bool' } - 1; =pod diff --git a/lib/Moose/Meta/Attribute/Trait/Native/Collection.pm b/lib/Moose/Meta/Attribute/Trait/Native/Collection.pm deleted file mode 100644 index 2bb65ea..0000000 --- a/lib/Moose/Meta/Attribute/Trait/Native/Collection.pm +++ /dev/null @@ -1,62 +0,0 @@ - -package Moose::Meta::Attribute::Trait::Native::Collection; -use Moose::Role; - -our $VERSION = '0.87'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - -with 'Moose::Meta::Attribute::Trait::Native'; - -no Moose::Role; - -1; - -__END__ - -=pod - -=head1 NAME - -Moose::Meta::Attribute::Trait::Native::Collection - Base role for all collection type helpers - -=head1 DESCRIPTION - -Documentation to come. - -=head1 METHODS - -=over 4 - -=item B - -=item B - -=item B - -=item B - -=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@iinteractive.comE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2007-2009 by 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/Moose/Meta/Attribute/Trait/Native/Counter.pm b/lib/Moose/Meta/Attribute/Trait/Native/Counter.pm index 3003216..87681a0 100644 --- a/lib/Moose/Meta/Attribute/Trait/Native/Counter.pm +++ b/lib/Moose/Meta/Attribute/Trait/Native/Counter.pm @@ -39,10 +39,6 @@ after '_check_handles_values' => sub { no Moose::Role; -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::Trait::Counter; -sub register_implementation { 'Moose::Meta::Attribute::Trait::Native::Counter' } - 1; __END__ diff --git a/lib/Moose/Meta/Attribute/Trait/Native/Hash.pm b/lib/Moose/Meta/Attribute/Trait/Native/Hash.pm index 0c79951..a7a9ffa 100644 --- a/lib/Moose/Meta/Attribute/Trait/Native/Hash.pm +++ b/lib/Moose/Meta/Attribute/Trait/Native/Hash.pm @@ -8,7 +8,7 @@ our $AUTHORITY = 'cpan:STEVAN'; use Moose::Meta::Attribute::Trait::Native::MethodProvider::Hash; -with 'Moose::Meta::Attribute::Trait::Native::Collection'; +with 'Moose::Meta::Attribute::Trait::Native'; has 'method_provider' => ( is => 'ro', @@ -21,13 +21,6 @@ sub _helper_type { 'HashRef' } no Moose::Role; -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::Trait::Hash; -sub register_implementation { - 'Moose::Meta::Attribute::Trait::Native::Hash' -} - - 1; __END__ diff --git a/lib/Moose/Meta/Attribute/Trait/Native/Number.pm b/lib/Moose/Meta/Attribute/Trait/Native/Number.pm index c02b008..1114dce 100644 --- a/lib/Moose/Meta/Attribute/Trait/Native/Number.pm +++ b/lib/Moose/Meta/Attribute/Trait/Native/Number.pm @@ -52,10 +52,6 @@ has 'method_constructors' => ( no Moose::Role; -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::Trait::Number; -sub register_implementation { 'Moose::Meta::Attribute::Trait::Native::Number' } - 1; =pod diff --git a/lib/Moose/Meta/Attribute/Trait/Native/String.pm b/lib/Moose/Meta/Attribute/Trait/Native/String.pm index fc77380..1bde822 100644 --- a/lib/Moose/Meta/Attribute/Trait/Native/String.pm +++ b/lib/Moose/Meta/Attribute/Trait/Native/String.pm @@ -37,10 +37,6 @@ after '_check_handles_values' => sub { no Moose::Role; -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::Trait::String; -sub register_implementation { 'Moose::Meta::Attribute::Trait::Native::String' } - 1; __END__ diff --git a/t/070_attribute_traits/000_load.t b/t/070_attribute_traits/000_load.t index d876957..b71f104 100644 --- a/t/070_attribute_traits/000_load.t +++ b/t/070_attribute_traits/000_load.t @@ -5,6 +5,7 @@ use warnings; use Test::More tests => 1; +use Moose (); BEGIN { - use_ok('Moose::AttributeHelpers'); -} \ No newline at end of file + use_ok('Moose::Attribute::Native'); +} diff --git a/t/070_attribute_traits/010_array_from_role.t b/t/070_attribute_traits/010_array_from_role.t index 0b1967b..80aac85 100644 --- a/t/070_attribute_traits/010_array_from_role.t +++ b/t/070_attribute_traits/010_array_from_role.t @@ -14,7 +14,6 @@ use Test::Exception; package Stuffed::Role; use Moose::Role; - use Moose::AttributeHelpers; has 'options' => ( traits => ['Array'], @@ -24,7 +23,6 @@ use Test::Exception; package Bulkie::Role; use Moose::Role; - use Moose::AttributeHelpers; has 'stuff' => ( traits => ['Array'], diff --git a/t/070_attribute_traits/011_counter_with_defaults.t b/t/070_attribute_traits/011_counter_with_defaults.t index 363da28..cc197c7 100644 --- a/t/070_attribute_traits/011_counter_with_defaults.t +++ b/t/070_attribute_traits/011_counter_with_defaults.t @@ -9,7 +9,6 @@ use Test::Moose; { package MyHomePage; use Moose; - use Moose::AttributeHelpers; has 'counter' => ( traits => ['Counter'] ); } diff --git a/t/070_attribute_traits/020_remove_attribute.t b/t/070_attribute_traits/020_remove_attribute.t index dcd3df8..49b2cba 100644 --- a/t/070_attribute_traits/020_remove_attribute.t +++ b/t/070_attribute_traits/020_remove_attribute.t @@ -9,7 +9,6 @@ use Test::Exception; { package MyHomePage; use Moose; - use Moose::AttributeHelpers; has 'counter' => ( traits => ['Counter'], diff --git a/t/070_attribute_traits/100_collection_with_roles.t b/t/070_attribute_traits/100_collection_with_roles.t index f03cffe..43ea86a 100644 --- a/t/070_attribute_traits/100_collection_with_roles.t +++ b/t/070_attribute_traits/100_collection_with_roles.t @@ -9,7 +9,6 @@ use Test::More tests => 28; package Subject; use Moose::Role; - use Moose::AttributeHelpers; has observers => ( traits => ['Array'], @@ -43,7 +42,6 @@ use Test::More tests => 28; package Counter; use Moose; - use Moose::AttributeHelpers; with 'Subject'; diff --git a/t/070_attribute_traits/201_trait_counter.t b/t/070_attribute_traits/201_trait_counter.t index e1e1ee9..b18c941 100644 --- a/t/070_attribute_traits/201_trait_counter.t +++ b/t/070_attribute_traits/201_trait_counter.t @@ -9,7 +9,6 @@ use Test::Moose 'does_ok'; { package MyHomePage; use Moose; - use Moose::AttributeHelpers; has 'counter' => ( traits => ['Counter'], diff --git a/t/070_attribute_traits/202_trait_array.t b/t/070_attribute_traits/202_trait_array.t index cd96943..c4309aa 100644 --- a/t/070_attribute_traits/202_trait_array.t +++ b/t/070_attribute_traits/202_trait_array.t @@ -13,7 +13,6 @@ my $sort; package Stuff; use Moose; - use Moose::AttributeHelpers; has 'options' => ( traits => ['Array'], diff --git a/t/070_attribute_traits/203_trait_hash.t b/t/070_attribute_traits/203_trait_hash.t index 9418f67..ed4066f 100644 --- a/t/070_attribute_traits/203_trait_hash.t +++ b/t/070_attribute_traits/203_trait_hash.t @@ -10,7 +10,6 @@ use Test::Moose 'does_ok'; { package Stuff; use Moose; - use Moose::AttributeHelpers; has 'options' => ( traits => ['Hash'], diff --git a/t/070_attribute_traits/204_trait_number.t b/t/070_attribute_traits/204_trait_number.t index 297614d..a54e5aa 100644 --- a/t/070_attribute_traits/204_trait_number.t +++ b/t/070_attribute_traits/204_trait_number.t @@ -9,7 +9,6 @@ use Test::Moose; { package Real; use Moose; - use Moose::AttributeHelpers; has 'integer' => ( traits => ['Number'], diff --git a/t/070_attribute_traits/205_trait_list.t b/t/070_attribute_traits/205_trait_list.t index e72f509..bc53153 100644 --- a/t/070_attribute_traits/205_trait_list.t +++ b/t/070_attribute_traits/205_trait_list.t @@ -13,7 +13,6 @@ my $up; { package Stuff; use Moose; - use Moose::AttributeHelpers; has '_options' => ( traits => ['Array'], diff --git a/t/070_attribute_traits/207_trait_string.t b/t/070_attribute_traits/207_trait_string.t index 4363025..fca6f0e 100644 --- a/t/070_attribute_traits/207_trait_string.t +++ b/t/070_attribute_traits/207_trait_string.t @@ -10,7 +10,6 @@ my $uc; { package MyHomePage; use Moose; - use Moose::AttributeHelpers; has 'string' => ( traits => ['String'], diff --git a/t/070_attribute_traits/208_trait_bool.t b/t/070_attribute_traits/208_trait_bool.t index eb173d2..ef92860 100644 --- a/t/070_attribute_traits/208_trait_bool.t +++ b/t/070_attribute_traits/208_trait_bool.t @@ -8,7 +8,6 @@ use Test::More tests => 8; { package Room; use Moose; - use Moose::AttributeHelpers; has 'is_lit' => ( traits => ['Bool'],