6 use Test::More tests => 21;
9 use_ok('MooseX::AttributeHelpers');
17 metaclass => 'String',
20 default => sub { '' },
23 append => 'append_string',
24 prepend => 'prepend_string',
25 match => 'match_string',
26 replace => 'replace_string',
27 chop => 'chop_string',
28 chomp => 'chomp_string',
29 clear => 'clear_string',
32 append => {exclaim => [ '!' ]},
33 replace => {capitalize_last => [ qr/(.)$/, sub { uc $1 } ]},
34 match => {invalid_number => [ qr/\D/ ]}
39 my $page = MyHomePage->new();
40 isa_ok($page, 'MyHomePage');
42 is($page->string, '', '... got the default value');
47 is($page->string, 'b', '... got the incremented value');
50 is($page->string, 'c', '... got the incremented value (again)');
52 $page->append_string("foo$/");
53 is($page->string, "cfoo$/", 'appended to string');
56 is($page->string, "cfoo", 'chomped string');
59 is($page->string, "cfoo", 'chomped is noop');
62 is($page->string, "cfo", 'chopped string');
64 $page->prepend_string("bar");
65 is($page->string, 'barcfo', 'prepended to string');
67 is_deeply( [ $page->match_string(qr/([ao])/) ], [ "a" ], "match" );
69 $page->replace_string(qr/([ao])/, sub { uc($1) });
70 is($page->string, 'bArcfo', "substitution");
73 is($page->string, 'bArcfo!', 'exclaim!');
75 $page->string('Moosex');
76 $page->capitalize_last;
77 is($page->string, 'MooseX', 'capitalize last');
79 $page->string('1234');
80 ok(!$page->invalid_number, 'string "isn\'t an invalid number');
82 $page->string('one two three four');
83 ok($page->invalid_number, 'string an invalid number');
86 is($page->string, '', "clear");
90 my $string = $page->meta->get_attribute('string');
91 isa_ok($string, 'MooseX::AttributeHelpers::String');
93 is($string->helper_type, 'Str', '... got the expected helper type');
95 is($string->type_constraint->name, 'Str', '... got the expected type constraint');
97 is_deeply($string->provides, {
99 append => 'append_string',
100 prepend => 'prepend_string',
101 match => 'match_string',
102 replace => 'replace_string',
103 chop => 'chop_string',
104 chomp => 'chomp_string',
105 clear => 'clear_string',
106 }, '... got the right provides methods');