2 package Moose::Meta::Attribute::Native::Trait::String;
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
9 use Moose::Meta::Attribute::Native::MethodProvider::String;
11 with 'Moose::Meta::Attribute::Native::Trait';
13 has 'method_provider' => (
16 predicate => 'has_method_provider',
17 default => 'Moose::Meta::Attribute::Native::MethodProvider::String',
20 sub _default_default { q{} }
21 sub _default_is { 'rw' }
22 sub _helper_type { 'Str' }
24 after '_check_handles_values' => sub {
26 my $handles = $self->handles;
28 unless ( scalar keys %$handles ) {
29 my $method_constructors = $self->method_constructors;
30 my $attr_name = $self->name;
32 foreach my $method ( keys %$method_constructors ) {
33 $handles->{$method} = ( $method . '_' . $attr_name );
48 Moose::Meta::Attribute::Native::Trait::String
54 use Moose::AttributeHelpers;
57 metaclass => 'String',
63 replace_text => 'replace',
67 my $page = MyHomePage->new();
68 $page->add_text("foo"); # same as $page->text($page->text . "foo");
72 This module provides a simple string attribute, to which mutating string
73 operations can be applied more easily (no need to make an lvalue attribute
74 metaclass or use temporary variables). Additional methods are provided for
77 If your attribute definition does not include any of I<is>, I<isa>,
78 I<default> or I<handles> but does use the C<String> metaclass,
79 then this module applies defaults as in the L</SYNOPSIS>
80 above. This allows for a very basic counter definition:
82 has 'foo' => (metaclass => 'String');
91 =item B<method_provider>
93 =item B<has_method_provider>
97 =head1 PROVIDED METHODS
99 It is important to note that all those methods do in place
100 modification of the value stored in the attribute.
106 Increments the value stored in this slot using the magical string autoincrement
107 operator. Note that Perl doesn't provide analogous behavior in C<-->, so
108 C<dec> is not available.
110 =item I<append> C<$string>
112 Append a string, like C<.=>.
114 =item I<prepend> C<$string>
118 =item I<replace> C<$pattern> C<$replacement>
120 Performs a regexp substitution (L<perlop/s>). There is no way to provide the
121 C<g> flag, but code references will be accepted for the replacement, causing
122 the regex to be modified with a single C<e>. C</smxi> can be applied using the
125 =item I<match> C<$pattern>
127 Like I<replace> but without the replacement. Provided mostly for completeness.
139 Sets the string to the empty string (not the value passed to C<default>).
145 All complex software has bugs lurking in it, and this module is no
146 exception. If you find a bug please either email me, or add the bug
151 Stevan Little E<lt>stevan@iinteractive.comE<gt>
153 =head1 COPYRIGHT AND LICENSE
155 Copyright 2007-2009 by Infinity Interactive, Inc.
157 L<http://www.iinteractive.com>
159 This library is free software; you can redistribute it and/or modify
160 it under the same terms as Perl itself.