From: Jesse Luehrs Date: Mon, 1 Jun 2009 23:52:01 +0000 (-0500) Subject: Merge branch 'master' into traits X-Git-Tag: 0.18_01~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4a35a0ad2542b236a6ea02022d55c4193a58a321;p=gitmo%2FMooseX-AttributeHelpers.git Merge branch 'master' into traits Conflicts: lib/MooseX/AttributeHelpers/Trait/Base.pm --- 4a35a0ad2542b236a6ea02022d55c4193a58a321 diff --cc lib/MooseX/AttributeHelpers.pm index 4a73b89,ea61f20..69331b0 --- a/lib/MooseX/AttributeHelpers.pm +++ b/lib/MooseX/AttributeHelpers.pm @@@ -1,20 -1,15 +1,24 @@@ package MooseX::AttributeHelpers; - our $VERSION = '0.08'; + our $VERSION = '0.17'; + $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; + use Moose 0.56 (); + use MooseX::AttributeHelpers::Meta::Method::Provided; + use MooseX::AttributeHelpers::Meta::Method::Curried; +use MooseX::AttributeHelpers::Trait::Counter; +use MooseX::AttributeHelpers::Trait::Number; +use MooseX::AttributeHelpers::Trait::String; +use MooseX::AttributeHelpers::Trait::Collection::List; +use MooseX::AttributeHelpers::Trait::Collection::Array; +use MooseX::AttributeHelpers::Trait::Collection::Hash; +use MooseX::AttributeHelpers::Trait::Collection::ImmutableHash; +use MooseX::AttributeHelpers::Trait::Collection::Bag; + use MooseX::AttributeHelpers::Counter; use MooseX::AttributeHelpers::Number; use MooseX::AttributeHelpers::String; diff --cc lib/MooseX/AttributeHelpers/Collection/Array.pm index cce6976,e1090fe..44a587a --- a/lib/MooseX/AttributeHelpers/Collection/Array.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Array.pm @@@ -2,11 -2,19 +2,12 @@@ package MooseX::AttributeHelpers::Collection::Array; use Moose; - our $VERSION = '0.01'; + our $VERSION = '0.17'; + $VERSION = eval $VERSION; 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 --cc lib/MooseX/AttributeHelpers/Collection/Bag.pm index 16a1e97,7456dab..3588a3d --- a/lib/MooseX/AttributeHelpers/Collection/Bag.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Bag.pm @@@ -1,14 -1,37 +1,15 @@@ package MooseX::AttributeHelpers::Collection::Bag; use Moose; -use Moose::Util::TypeConstraints; - our $VERSION = '0.01'; + our $VERSION = '0.17'; + $VERSION = eval $VERSION; 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]'; - -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 --cc lib/MooseX/AttributeHelpers/Collection/Hash.pm index 12d71d0,34203c9..f52e61f --- a/lib/MooseX/AttributeHelpers/Collection/Hash.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Hash.pm @@@ -2,11 -2,19 +2,12 @@@ package MooseX::AttributeHelpers::Collection::Hash; use Moose; - our $VERSION = '0.02'; + our $VERSION = '0.17'; + $VERSION = eval $VERSION; 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; diff --cc lib/MooseX/AttributeHelpers/Collection/ImmutableHash.pm index 66c39f5,e1dca3f..dfba523 --- a/lib/MooseX/AttributeHelpers/Collection/ImmutableHash.pm +++ b/lib/MooseX/AttributeHelpers/Collection/ImmutableHash.pm @@@ -2,11 -2,19 +2,12 @@@ package MooseX::AttributeHelpers::Collection::ImmutableHash; use Moose; - our $VERSION = '0.01'; + our $VERSION = '0.17'; + $VERSION = eval $VERSION; 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; diff --cc lib/MooseX/AttributeHelpers/Collection/List.pm index abce353,b81e56d..d6fc0bb --- a/lib/MooseX/AttributeHelpers/Collection/List.pm +++ b/lib/MooseX/AttributeHelpers/Collection/List.pm @@@ -2,11 -2,19 +2,12 @@@ package MooseX::AttributeHelpers::Collection::List; use Moose; - our $VERSION = '0.01'; + our $VERSION = '0.17'; + $VERSION = eval $VERSION; 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 --cc lib/MooseX/AttributeHelpers/Counter.pm index a67d043,38d9875..9a2cea2 --- a/lib/MooseX/AttributeHelpers/Counter.pm +++ b/lib/MooseX/AttributeHelpers/Counter.pm @@@ -2,11 -2,45 +2,12 @@@ package MooseX::AttributeHelpers::Counter; use Moose; - our $VERSION = '0.03'; + our $VERSION = '0.17'; + $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use MooseX::AttributeHelpers::MethodProvider::Counter; - -extends 'MooseX::AttributeHelpers::Base'; - -has '+method_provider' => ( - default => 'MooseX::AttributeHelpers::MethodProvider::Counter' -); - -sub helper_type { 'Num' } - -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} = 'ro' unless exists $options->{is}; - $options->{default} = 0 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::Counter'; no Moose; diff --cc lib/MooseX/AttributeHelpers/Number.pm index 5dc3674,c19ca3f..aefb9a7 --- a/lib/MooseX/AttributeHelpers/Number.pm +++ b/lib/MooseX/AttributeHelpers/Number.pm @@@ -1,12 -1,55 +1,13 @@@ package MooseX::AttributeHelpers::Number; use Moose; - our $VERSION = '0.02'; + our $VERSION = '0.17'; + $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -extends 'MooseX::AttributeHelpers::Base'; +extends 'Moose::Meta::Attribute'; +with 'MooseX::AttributeHelpers::Trait::Number'; -sub helper_type { 'Num' } - -# NOTE: -# we don't use the method provider for this -# module since many of the names of the provied -# methods would conflict with keywords -# - SL - -has '+method_constructors' => ( - default => sub { - return +{ - set => sub { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $_[1]) }; - }, - add => sub { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $reader->($_[0]) + $_[1]) }; - }, - sub => sub { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $reader->($_[0]) - $_[1]) }; - }, - mul => sub { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $reader->($_[0]) * $_[1]) }; - }, - div => sub { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $reader->($_[0]) / $_[1]) }; - }, - mod => sub { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $reader->($_[0]) % $_[1]) }; - }, - abs => sub { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], abs($reader->($_[0])) ) }; - }, - } - } -); - no Moose; # register the alias ... diff --cc lib/MooseX/AttributeHelpers/String.pm index cd915f2,facca62..366c74c --- a/lib/MooseX/AttributeHelpers/String.pm +++ b/lib/MooseX/AttributeHelpers/String.pm @@@ -2,11 -2,45 +2,12 @@@ package MooseX::AttributeHelpers::String; use Moose; - our $VERSION = '0.01'; + our $VERSION = '0.17'; + $VERSION = eval $VERSION; 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; diff --cc lib/MooseX/AttributeHelpers/Trait/Base.pm index 6da6eae,96217a8..44bb4f9 --- a/lib/MooseX/AttributeHelpers/Trait/Base.pm +++ b/lib/MooseX/AttributeHelpers/Trait/Base.pm @@@ -1,12 -1,13 +1,13 @@@ -package MooseX::AttributeHelpers::Base; -use Moose; +package MooseX::AttributeHelpers::Trait::Base; +use Moose::Role; use Moose::Util::TypeConstraints; - our $VERSION = '0.04'; + our $VERSION = '0.17'; + $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -extends 'Moose::Meta::Attribute'; +requires 'helper_type'; # this is the method map you define ... has 'provides' => ( @@@ -141,9 -216,18 +211,18 @@@ after 'remove_accessors' => sub if blessed($method) && $method->isa('MooseX::AttributeHelpers::Meta::Method::Provided'); } + + # curries accessors + foreach my $key (keys %{$attr->curries}) { + my $method_name = $attr->curries->{$key}; + my $method = $class->get_method($method_name); + $class->remove_method($method_name) + if blessed($method) && + $method->isa('MooseX::AttributeHelpers::Meta::Method::Provided'); + } }; -no Moose; +no Moose::Role; no Moose::Util::TypeConstraints; 1; diff --cc lib/MooseX/AttributeHelpers/Trait/Collection.pm index 8b836a6,64ed47d..44c8081 --- a/lib/MooseX/AttributeHelpers/Trait/Collection.pm +++ b/lib/MooseX/AttributeHelpers/Trait/Collection.pm @@@ -1,13 -1,14 +1,14 @@@ -package MooseX::AttributeHelpers::Collection; -use Moose; +package MooseX::AttributeHelpers::Trait::Collection; +use Moose::Role; - our $VERSION = '0.03'; + our $VERSION = '0.17'; + $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -extends 'MooseX::AttributeHelpers::Base'; +with 'MooseX::AttributeHelpers::Trait::Base'; -no Moose; +no Moose::Role; 1;