return sub { $writer->( $_[0], '' ) }
}
+sub length : method {
+ my ($attr, $reader, $writer) = @_;
+ return sub {
+ my $v = $reader->($_[0]);
+ return CORE::length($v);
+ };
+}
+
sub substr : method {
my ( $attr, $reader, $writer ) = @_;
return sub {
=item B<clear>
+=item B<length>
+
=item B<substr>
=back
use strict;
use warnings;
-use Test::More tests => 19;
+use Test::More tests => 22;
use Test::Moose 'does_ok';
my $uc;
chop_string => 'chop',
chomp_string => 'chomp',
clear_string => 'clear',
+ length_string => 'length',
exclaim => [ append => ['!'] ],
capitalize_last =>
[ replace => [ qr/(.)$/, $uc = sub { uc $1 } ] ],
isa_ok( $page, 'MyHomePage' );
is( $page->string, '', '... got the default value' );
+is( $page->length_string, 0,'... length is zero' );
$page->string('a');
+is( $page->length_string, 1,'... new string has length of one' );
$page->inc_string;
is( $page->string, 'b', '... got the incremented value' );
$page->replace_string( qr/([ao])/, sub { uc($1) } );
is( $page->string, 'bArcfo', "substitution" );
+is( $page->length_string, 6, 'right length' );
$page->exclaim;
is( $page->string, 'bArcfo!', 'exclaim!' );
chop_string => 'chop',
chomp_string => 'chomp',
clear_string => 'clear',
+ length_string => 'length',
exclaim => [ append => ['!'] ],
capitalize_last => [ replace => [ qr/(.)$/, $uc ] ],
invalid_number => [ match => [qr/\D/] ],