## 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;
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;
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);
}
}
};
));
__PACKAGE__->meta->add_attribute('handles' => (
reader => 'handles',
+ writer => '_set_handles',
predicate => 'has_handles',
));
__PACKAGE__->meta->add_attribute('documentation' => (
use warnings;
use Test::More tests => 14;
+use Test::Moose;
BEGIN {
use_ok('Moose::AttributeHelpers');
package MyHomePage;
use Moose;
- has 'counter' => (metaclass => 'Counter');
+ has 'counter' => (traits => ['Counter']);
}
my $page = MyHomePage->new();
# 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');
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;
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/ ] ],
},
);
}
$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');
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');
flip_switch => 'toggle',
is_dark => 'not',
},
- }
)
}