From: Hans Dieter Pearcey Date: Thu, 25 Jun 2009 22:35:14 +0000 (-0400) Subject: more tests passing X-Git-Tag: 0.89_02~124 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=40ef30a58d65221afb73dde34c26a57068c9d746;hp=ac6fe9004eaccaafc48107ec502954305d497f6e;p=gitmo%2FMoose.git more tests passing --- diff --git a/lib/Moose/AttributeHelpers/Trait/Base.pm b/lib/Moose/AttributeHelpers/Trait/Base.pm index 2b2a6a0..e1302c1 100644 --- a/lib/Moose/AttributeHelpers/Trait/Base.pm +++ b/lib/Moose/AttributeHelpers/Trait/Base.pm @@ -86,7 +86,7 @@ around '_canonicalize_handles' => sub { ## methods called after instantiation -before 'install_delegation' => sub { (shift)->check_handles_values }; +before 'install_accessors' => sub { (shift)->check_handles_values }; sub check_handles_values { my $self = shift; diff --git a/lib/Moose/AttributeHelpers/Trait/Counter.pm b/lib/Moose/AttributeHelpers/Trait/Counter.pm index 218f25a..32dfbf9 100644 --- a/lib/Moose/AttributeHelpers/Trait/Counter.pm +++ b/lib/Moose/AttributeHelpers/Trait/Counter.pm @@ -40,9 +40,11 @@ after 'check_handles_values' => sub { my $attr_name = $self->name; foreach my $method (keys %$method_constructors) { - $handles->{$method} = ($method . '_' . $attr_name); + $handles->{$method . '_' . $attr_name} = $method; } } + + $self->_set_handles($handles); }; no Moose::Role; diff --git a/lib/Moose/AttributeHelpers/Trait/String.pm b/lib/Moose/AttributeHelpers/Trait/String.pm index 8a70509..4fd453a 100644 --- a/lib/Moose/AttributeHelpers/Trait/String.pm +++ b/lib/Moose/AttributeHelpers/Trait/String.pm @@ -33,14 +33,14 @@ before 'process_options_for_handles' => sub { after 'check_handles_values' => sub { my $self = shift; - my $provides = $self->provides; + my $handles = $self->handles; - unless (scalar keys %$provides) { + unless (scalar keys %$handles) { my $method_constructors = $self->method_constructors; my $attr_name = $self->name; foreach my $method (keys %$method_constructors) { - $provides->{$method} = ($method . '_' . $attr_name); + $handles->{$method} = ($method . '_' . $attr_name); } } }; diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index c3083ee..07598ac 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -40,6 +40,7 @@ __PACKAGE__->meta->add_attribute('trigger' => ( )); __PACKAGE__->meta->add_attribute('handles' => ( reader => 'handles', + writer => '_set_handles', predicate => 'has_handles', )); __PACKAGE__->meta->add_attribute('documentation' => ( diff --git a/t/070_attribute_helpers/011_counter_with_defaults.t b/t/070_attribute_helpers/011_counter_with_defaults.t index a242cb3..385f41c 100644 --- a/t/070_attribute_helpers/011_counter_with_defaults.t +++ b/t/070_attribute_helpers/011_counter_with_defaults.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More tests => 14; +use Test::Moose; BEGIN { use_ok('Moose::AttributeHelpers'); @@ -13,7 +14,7 @@ BEGIN { package MyHomePage; use Moose; - has 'counter' => (metaclass => 'Counter'); + has 'counter' => (traits => ['Counter']); } my $page = MyHomePage->new(); @@ -42,16 +43,16 @@ is($page->counter, 0, '... got the original value'); # check the meta .. my $counter = $page->meta->get_attribute('counter'); -isa_ok($counter, 'Moose::AttributeHelpers::Counter'); +does_ok($counter, 'Moose::AttributeHelpers::Trait::Counter'); is($counter->helper_type, 'Num', '... got the expected helper type'); is($counter->type_constraint->name, 'Num', '... got the expected default type constraint'); -is_deeply($counter->provides, { - inc => 'inc_counter', - dec => 'dec_counter', - reset => 'reset_counter', - set => 'set_counter', +is_deeply($counter->handles, { + 'inc_counter' => 'inc', + 'dec_counter' => 'dec', + 'reset_counter' => 'reset', + 'set_counter' => 'set', }, '... got the right default provides methods'); diff --git a/t/070_attribute_helpers/207_trait_string.t b/t/070_attribute_helpers/207_trait_string.t index baab0d8..bd23c99 100644 --- a/t/070_attribute_helpers/207_trait_string.t +++ b/t/070_attribute_helpers/207_trait_string.t @@ -3,13 +3,14 @@ use strict; use warnings; -use Test::More tests => 27; +use Test::More tests => 21; use Test::Moose 'does_ok'; BEGIN { use_ok('Moose::AttributeHelpers'); } +my $uc; { package MyHomePage; use Moose; @@ -28,10 +29,9 @@ BEGIN { chop_string => 'chop', chomp_string => 'chomp', clear_string => 'clear', - exclaim => { append => [ '!' ]}, - capitalize_last => { replace => [ qr/(.)$/, sub { uc $1 } ]}, - invalid_number => { match => [ qr/\D/ ]}, - shift_chars => { substr => sub { $_[1]->($_[0], 0, $_[2], '') } }, + exclaim => [ append => [ '!' ] ], + capitalize_last => [ replace => [ qr/(.)$/, $uc = sub { uc $1 } ] ], + invalid_number => [ match => [ qr/\D/ ] ], }, ); } @@ -72,14 +72,6 @@ is($page->string, 'bArcfo', "substitution"); $page->exclaim; is($page->string, 'bArcfo!', 'exclaim!'); -is($page->sub_string(2), 'rcfo!', 'substr(offset)'); -is($page->sub_string(2, 2), 'rc', 'substr(offset, length)'); -is($page->sub_string(2, 2, ''), 'rc', 'substr(offset, length, replacement)'); -is($page->string, 'bAfo!', 'replacement got inserted'); - -is($page->shift_chars(2), 'bA', 'curried substr'); -is($page->string, 'fo!', 'replacement got inserted'); - $page->string('Moosex'); $page->capitalize_last; is($page->string, 'MooseX', 'capitalize last'); @@ -111,5 +103,8 @@ is_deeply($string->handles, { chop_string => 'chop', chomp_string => 'chomp', clear_string => 'clear', + exclaim => [ append => [ '!' ] ], + capitalize_last => [ replace => [ qr/(.)$/, $uc ] ], + invalid_number => [ match => [ qr/\D/ ] ], }, '... got the right provides methods'); diff --git a/t/070_attribute_helpers/208_trait_bool.t b/t/070_attribute_helpers/208_trait_bool.t index 5462d90..67df111 100644 --- a/t/070_attribute_helpers/208_trait_bool.t +++ b/t/070_attribute_helpers/208_trait_bool.t @@ -20,7 +20,6 @@ use Moose::AttributeHelpers; flip_switch => 'toggle', is_dark => 'not', }, - } ) }