X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FAttribute%2FNative%2FTrait%2FString.pm;h=f09723a28855d6c270e1f5a4f3eab8a9ea53fa8a;hb=bb09ad9144e7ee7b2cad8a90725267f591346406;hp=a4550933610906bd12b7ec954102b3d8c74e82c3;hpb=7543127e02af5649f377d0d4246be1188002f91f;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 a455093..f09723a 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait/String.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait/String.pm @@ -1,39 +1,27 @@ package Moose::Meta::Attribute::Native::Trait::String; use Moose::Role; -our $VERSION = '0.87'; +our $VERSION = '1.17'; $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' } -after '_check_handles_values' => sub { - my $self = shift; - my $handles = $self->handles; - - unless ( scalar keys %$handles ) { - my $method_constructors = $self->method_constructors; - my $attr_name = $self->name; - - foreach my $method ( keys %$method_constructors ) { - $handles->{$method} = ( $method . '_' . $attr_name ); - } - } -}; - no Moose::Role; 1; @@ -44,7 +32,7 @@ __END__ =head1 NAME -Moose::Meta::Attribute::Native::Trait::String +Moose::Meta::Attribute::Native::Trait::String - Helper trait for Str attributes =head1 SYNOPSIS @@ -52,99 +40,104 @@ Moose::Meta::Attribute::Native::Trait::String use Moose; has 'text' => ( - metaclass => '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 counter definition: +=head1 DEFAULT TYPE - has 'foo' => (metaclass => '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 I +=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 I C<$string> +This method requires a single argument. -Append a string, like C<.=>. +=item * B -=item I C<$string> +Prepends to the string and returns the new value. -Prepend a string. +This method requires a single argument. -=item I C<$pattern> C<$replacement> +=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 I C<$pattern> +This method requires two arguments. -Like I but without the replacement. Provided mostly for completeness. +=item * B -=item C +Runs the regex against the string and returns the matching value(s). -L +This method requires a single argument. -=item C +=item * B -L +Just like L. This method returns the chopped character. -=item C +This method does not accept any arguments. + +=item * B + +Just like L. This method returns the number of characters +removed. + +This method does not accept any arguments. + +=item * B 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 =head1 BUGS -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. +See L for details on reporting bugs. =head1 AUTHOR