X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FAttribute%2FNative%2FTrait%2FString.pm;h=8be88f317359e9b8d2ee9e5e26cbe33aa5581dd5;hb=3543f4d4b3d568ba01455d600fbe60c6b9a8a2c0;hp=010c45e53b40b3108e0c87401826a058858964c8;hpb=1c7518d411958aa1651b82bbc8238265c6248f75;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Attribute/Native/Trait/String.pm b/lib/Moose/Meta/Attribute/Native/Trait/String.pm index 010c45e..8be88f3 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait/String.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait/String.pm @@ -1,21 +1,23 @@ package Moose::Meta::Attribute::Native::Trait::String; use Moose::Role; -our $VERSION = '1.13'; +our $VERSION = '1.23'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use Moose::Meta::Attribute::Native::MethodProvider::String; +use Moose::Meta::Method::Accessor::Native::String::append; +use Moose::Meta::Method::Accessor::Native::String::chomp; +use Moose::Meta::Method::Accessor::Native::String::chop; +use Moose::Meta::Method::Accessor::Native::String::clear; +use Moose::Meta::Method::Accessor::Native::String::inc; +use Moose::Meta::Method::Accessor::Native::String::length; +use Moose::Meta::Method::Accessor::Native::String::match; +use Moose::Meta::Method::Accessor::Native::String::prepend; +use Moose::Meta::Method::Accessor::Native::String::replace; +use Moose::Meta::Method::Accessor::Native::String::substr; with 'Moose::Meta::Attribute::Native::Trait'; -has 'method_provider' => ( - is => 'ro', - isa => 'ClassName', - predicate => 'has_method_provider', - default => 'Moose::Meta::Attribute::Native::MethodProvider::String', -); - sub _default_default { q{} } sub _default_is { 'rw' } sub _helper_type { 'Str' } @@ -38,100 +40,98 @@ Moose::Meta::Attribute::Native::Trait::String - Helper trait for Str attributes use Moose; has 'text' => ( - traits => ['String'], - is => 'rw', - isa => 'Str', - default => q{}, - handles => { + traits => ['String'], + is => 'rw', + isa => 'Str', + default => q{}, + handles => { add_text => 'append', replace_text => 'replace', }, ); my $page = MyHomePage->new(); - $page->add_text("foo"); # same as $page->text($page->text . "foo"); + $page->add_text("foo"); # same as $page->text($page->text . "foo"); =head1 DESCRIPTION -This module provides a simple string attribute, to which mutating string -operations can be applied more easily (no need to make an lvalue attribute -metaclass or use temporary variables). Additional methods are provided for -completion. +This trait provides native delegation methods for strings. -If your attribute definition does not include any of I, I, -I or I but does use the C metaclass, -then this module applies defaults as in the L -above. This allows for a very basic string definition: +=head1 DEFAULT TYPE - has 'foo' => (traits => ['String']); - $obj->append_foo; +If you don't provide an C value for your attribute, it will default to +C. =head1 PROVIDED METHODS -These methods are implemented in -L. It is important to -note that all those methods do in place modification of the value stored in -the attribute. - =over 4 -=item B +=item * B Increments the value stored in this slot using the magical string autoincrement operator. Note that Perl doesn't provide analogous behavior in C<-->, so -C is not available. +C is not available. This method returns the new value. + +This method does not accept any arguments. + +=item * B + +Appends to the string, like C<.=>, and returns the new value. -=item B +This method requires a single argument. -Append a string, like C<.=>. +=item * B -=item B +Prepends to the string and returns the new value. -Prepend a string. +This method requires a single argument. -=item B +=item * B Performs a regexp substitution (L). There is no way to provide the C flag, but code references will be accepted for the replacement, causing the regex to be modified with a single C. C can be applied using the -C operator. +C operator. This method returns the new value. -=item B +This method requires two arguments. -Like C but without the replacement. Provided mostly for completeness. +=item * B -=item B +Runs the regex against the string and returns the matching value(s). -L +This method requires a single argument. -=item B +=item * B -L +Just like L. This method returns the chopped character. -=item B +This method does not accept any arguments. -Sets the string to the empty string (not the value passed to C). +=item * B -=item B +Just like L. This method returns the number of characters +removed. -L +This method does not accept any arguments. -=item B +=item * B -L. We go to some lengths to match the different functionality -based on C's arity. +Sets the string to the empty string (not the value passed to C). -=back +This method does not have a defined return value. -=head1 METHODS +This method does not accept any arguments. -=over 4 +=item * B + +Just like L, returns the length of the string. -=item B +=item * B -=item B +This acts just like L. When called as a writer, it returns +the substring that was replaced, just like the Perl builtin. -=item B +This method requires at least one argument, and accepts no more than three. =back @@ -145,7 +145,7 @@ Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE -Copyright 2007-2009 by Infinity Interactive, Inc. +Copyright 2007-2010 by Infinity Interactive, Inc. L