$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
-sub append : method {
+sub append : method {
my ($attr, $reader, $writer) = @_;
return sub { $writer->( $_[0], $reader->($_[0]) . $_[1] ) };
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 {
=head1 NAME
MooseX::AttributeHelpers::MethodProvider::String
-
+
=head1 DESCRIPTION
-This is a role which provides the method generators for
+This is a role which provides the method generators for
L<MooseX::AttributeHelpers::String>.
=head1 METHODS
=item B<clear>
+=item B<length>
+
=item B<substr>
=back
=head1 BUGS
-All complex software has bugs lurking in it, and this module is no
+All complex software has bugs lurking in it, and this module is no
exception. If you find a bug please either email me, or add the bug
to cpan-RT.
use strict;
use warnings;
-use Test::More tests => 27;
+use Test::More tests => 30;
BEGIN {
use_ok('MooseX::AttributeHelpers');
chomp => 'chomp_string',
clear => 'clear_string',
substr => 'sub_string',
+ length => 'length_string',
},
curries => {
append => {exclaim => [ '!' ]},
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;
+$page->inc_string;
is($page->string, 'b', '... got the incremented value');
-$page->inc_string;
+$page->inc_string;
is($page->string, 'c', '... got the incremented value (again)');
$page->append_string("foo$/");
$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!');
is($string->type_constraint->name, 'Str', '... got the expected type constraint');
-is_deeply($string->provides, {
+is_deeply($string->provides, {
inc => 'inc_string',
append => 'append_string',
prepend => 'prepend_string',
chomp => 'chomp_string',
clear => 'clear_string',
substr => 'sub_string',
+ length => 'length_string',
}, '... got the right provides methods');
use strict;
use warnings;
-use Test::More tests => 27;
+use Test::More tests => 30;
use Test::Moose 'does_ok';
BEGIN {
- use_ok('MooseX::AttributeHelpers');
+ use_ok('MooseX::AttributeHelpers');
}
{
chomp => 'chomp_string',
clear => 'clear_string',
substr => 'sub_string',
+ length => 'length_string',
},
curries => {
append => {exclaim => [ '!' ]},
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;
+$page->inc_string;
is($page->string, 'b', '... got the incremented value');
-$page->inc_string;
+$page->inc_string;
is($page->string, 'c', '... got the incremented value (again)');
$page->append_string("foo$/");
$page->prepend_string("bar");
is($page->string, 'barcfo', 'prepended to string');
+is($page->length_string, 6, 'right length');
is_deeply( [ $page->match_string(qr/([ao])/) ], [ "a" ], "match" );
is($string->type_constraint->name, 'Str', '... got the expected type constraint');
-is_deeply($string->provides, {
+is_deeply($string->provides, {
inc => 'inc_string',
append => 'append_string',
prepend => 'prepend_string',
chomp => 'chomp_string',
clear => 'clear_string',
substr => 'sub_string',
+ length => 'length_string',
}, '... got the right provides methods');