From: Dave Rolsky Date: Fri, 11 Sep 2009 15:17:35 +0000 (-0500) Subject: Do not auto-delegate for any Native Traits X-Git-Tag: 0.90~52 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0964dca1bdcf3267d4238e8691724e0a2684b65a;p=gitmo%2FMoose.git Do not auto-delegate for any Native Traits --- diff --git a/Changes b/Changes index 4ec486a..db05323 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,14 @@ Also see Moose::Manual::Delta for more details of, and workarounds for, noteworthy changes. +Next + * Moose::Meta::Attribute::Native::Trait::Counter + * Moose::Meta::Attribute::Native::Trait::String + - For these two traits, an attribute which did not explicitly provide + methods to handles magically ended up delegating *all* the helper + methods. This has been removed. You must be explicit in your handles + declaration for all Native Traits. (Dave Rolsky) + 0.89_02 Thu, Sep 10, 2009 * Moose::Meta::Attribute::Native - Fix Hash, which still had 'empty' instead of 'is_empty'. (hdp) diff --git a/lib/Moose/Meta/Attribute/Native/Trait/Counter.pm b/lib/Moose/Meta/Attribute/Native/Trait/Counter.pm index 49a7f66..2e2803a 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait/Counter.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait/Counter.pm @@ -21,22 +21,6 @@ sub _default_default { 0 } sub _default_is { 'ro' } sub _helper_type { 'Num' } -after '_check_handles_values' => sub { - my $self = shift; - my $handles = $self->handles; - - unless ( scalar keys %$handles ) { - my $method_constructors = $self->method_constructors; - my $attr_name = $self->name; - - foreach my $method ( keys %$method_constructors ) { - $handles->{ $method . '_' . $attr_name } = $method; - } - - $self->_set_handles($handles); - } -}; - no Moose::Role; 1; diff --git a/lib/Moose/Meta/Attribute/Native/Trait/String.pm b/lib/Moose/Meta/Attribute/Native/Trait/String.pm index 8900614..36123ba 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait/String.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait/String.pm @@ -20,20 +20,6 @@ sub _default_default { q{} } sub _default_is { 'rw' } sub _helper_type { 'Str' } -after '_check_handles_values' => sub { - my $self = shift; - my $handles = $self->handles; - - unless ( scalar keys %$handles ) { - my $method_constructors = $self->method_constructors; - my $attr_name = $self->name; - - foreach my $method ( keys %$method_constructors ) { - $handles->{$method} = ( $method . '_' . $attr_name ); - } - } -}; - no Moose::Role; 1; diff --git a/t/070_native_traits/011_counter_with_defaults.t b/t/070_native_traits/011_counter_with_defaults.t deleted file mode 100644 index 77a5c71..0000000 --- a/t/070_native_traits/011_counter_with_defaults.t +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use Test::More tests => 12; -use Test::Moose; - -{ - package MyHomePage; - use Moose; - - has 'counter' => ( traits => ['Counter'] ); -} - -my $page = MyHomePage->new(); -isa_ok( $page, 'MyHomePage' ); - -can_ok( $page, $_ ) for qw[ - dec_counter - inc_counter - reset_counter -]; - -is( $page->counter, 0, '... got the default value' ); - -$page->inc_counter; -is( $page->counter, 1, '... got the incremented value' ); - -$page->inc_counter; -is( $page->counter, 2, '... got the incremented value (again)' ); - -$page->dec_counter; -is( $page->counter, 1, '... got the decremented value' ); - -$page->reset_counter; -is( $page->counter, 0, '... got the original value' ); - -# check the meta .. - -my $counter = $page->meta->get_attribute('counter'); -does_ok( $counter, 'Moose::Meta::Attribute::Native::Trait::Counter' ); - -is( $counter->type_constraint->name, 'Num', - '... got the expected default type constraint' ); - -is_deeply( - $counter->handles, - { - 'inc_counter' => 'inc', - 'dec_counter' => 'dec', - 'reset_counter' => 'reset', - 'set_counter' => 'set', - }, - '... got the right default handles methods' -); -