From: Shawn M Moore Date: Sun, 25 May 2008 01:44:42 +0000 (+0000) Subject: Simplify the rest of the attribute helpers X-Git-Tag: 0.18_01~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=090583df3a0efe73192b32a1fa3c3afbf23b9ff0;p=gitmo%2FMooseX-AttributeHelpers.git Simplify the rest of the attribute helpers --- diff --git a/lib/MooseX/AttributeHelpers/Collection/Array.pm b/lib/MooseX/AttributeHelpers/Collection/Array.pm index 7c2acf7..cce6976 100644 --- a/lib/MooseX/AttributeHelpers/Collection/Array.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Array.pm @@ -5,15 +5,8 @@ use Moose; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; -use MooseX::AttributeHelpers::MethodProvider::Array; - -extends 'MooseX::AttributeHelpers::Collection'; - -has '+method_provider' => ( - default => 'MooseX::AttributeHelpers::MethodProvider::Array' -); - -sub helper_type { 'ArrayRef' } +extends 'Moose::Meta::Attribute'; +with 'MooseX::AttributeHelpers::Trait::Collection::Array'; no Moose; diff --git a/lib/MooseX/AttributeHelpers/Collection/Bag.pm b/lib/MooseX/AttributeHelpers/Collection/Bag.pm index 46e0931..16a1e97 100644 --- a/lib/MooseX/AttributeHelpers/Collection/Bag.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Bag.pm @@ -1,37 +1,14 @@ package MooseX::AttributeHelpers::Collection::Bag; use Moose; -use Moose::Util::TypeConstraints; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; -use MooseX::AttributeHelpers::MethodProvider::Bag; - -extends 'MooseX::AttributeHelpers::Collection'; - -has '+method_provider' => ( - default => 'MooseX::AttributeHelpers::MethodProvider::Bag' -); - -subtype 'Bag' => as 'HashRef[Int]' - unless find_type_constraint('Bag'); - -sub helper_type { 'Bag' } - -before 'process_options_for_provides' => sub { - my ($self, $options, $name) = @_; - - # Set some default attribute options here unless already defined - if ((my $type = $self->helper_type) && !exists $options->{isa}){ - $options->{isa} = $type; - } - - $options->{default} = sub { +{} } unless exists $options->{default}; -}; +extends 'Moose::Meta::Attribute'; +with 'MooseX::AttributeHelpers::Trait::Collection::Bag'; no Moose; -no Moose::Util::TypeConstraints; # register the alias ... package # hide me from search.cpan.org diff --git a/lib/MooseX/AttributeHelpers/Collection/Hash.pm b/lib/MooseX/AttributeHelpers/Collection/Hash.pm index eddb3e4..12d71d0 100644 --- a/lib/MooseX/AttributeHelpers/Collection/Hash.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Hash.pm @@ -5,15 +5,8 @@ use Moose; our $VERSION = '0.02'; our $AUTHORITY = 'cpan:STEVAN'; -use MooseX::AttributeHelpers::MethodProvider::Hash; - -extends 'MooseX::AttributeHelpers::Collection'; - -has '+method_provider' => ( - default => 'MooseX::AttributeHelpers::MethodProvider::Hash' -); - -sub helper_type { 'HashRef' } +extends 'Moose::Meta::Attribute'; +with 'MooseX::AttributeHelpers::Trait::Collection::Hash'; no Moose; @@ -92,4 +85,4 @@ L 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 +=cut diff --git a/lib/MooseX/AttributeHelpers/Collection/ImmutableHash.pm b/lib/MooseX/AttributeHelpers/Collection/ImmutableHash.pm index a0c7566..66c39f5 100644 --- a/lib/MooseX/AttributeHelpers/Collection/ImmutableHash.pm +++ b/lib/MooseX/AttributeHelpers/Collection/ImmutableHash.pm @@ -5,15 +5,8 @@ use Moose; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; -use MooseX::AttributeHelpers::MethodProvider::ImmutableHash; - -extends 'MooseX::AttributeHelpers::Collection'; - -has '+method_provider' => ( - default => 'MooseX::AttributeHelpers::MethodProvider::ImmutableHash' -); - -sub helper_type { 'HashRef' } +extends 'Moose::Meta::Attribute'; +with 'MooseX::AttributeHelpers::Trait::Collection::ImmutableHash'; no Moose; @@ -90,4 +83,4 @@ L 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 +=cut diff --git a/lib/MooseX/AttributeHelpers/Collection/List.pm b/lib/MooseX/AttributeHelpers/Collection/List.pm index bc62680..abce353 100644 --- a/lib/MooseX/AttributeHelpers/Collection/List.pm +++ b/lib/MooseX/AttributeHelpers/Collection/List.pm @@ -5,15 +5,8 @@ use Moose; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; -use MooseX::AttributeHelpers::MethodProvider::List; - -extends 'MooseX::AttributeHelpers::Collection'; - -has '+method_provider' => ( - default => 'MooseX::AttributeHelpers::MethodProvider::List' -); - -sub helper_type { 'ArrayRef' } +extends 'Moose::Meta::Attribute'; +with 'MooseX::AttributeHelpers::Trait::Collection::List'; no Moose; diff --git a/lib/MooseX/AttributeHelpers/String.pm b/lib/MooseX/AttributeHelpers/String.pm index 3290e2d..cd915f2 100644 --- a/lib/MooseX/AttributeHelpers/String.pm +++ b/lib/MooseX/AttributeHelpers/String.pm @@ -5,41 +5,8 @@ use Moose; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; -use MooseX::AttributeHelpers::MethodProvider::String; - -extends 'MooseX::AttributeHelpers::Base'; - -has '+method_provider' => ( - default => 'MooseX::AttributeHelpers::MethodProvider::String' -); - -sub helper_type { 'Str' } - -before 'process_options_for_provides' => sub { - my ($self, $options, $name) = @_; - - # Set some default attribute options here unless already defined - if ((my $type = $self->helper_type) && !exists $options->{isa}){ - $options->{isa} = $type; - } - - $options->{is} = 'rw' unless exists $options->{is}; - $options->{default} = '' unless exists $options->{default}; -}; - -after 'check_provides_values' => sub { - my $self = shift; - my $provides = $self->provides; - - unless (scalar keys %$provides) { - my $method_constructors = $self->method_constructors; - my $attr_name = $self->name; - - foreach my $method (keys %$method_constructors) { - $provides->{$method} = ($method . '_' . $attr_name); - } - } -}; +extends 'Moose::Meta::Attribute'; +with 'MooseX::AttributeHelpers::Trait::String'; no Moose;