2 package Moose::AttributeHelpers::Trait::String;
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
9 use Moose::AttributeHelpers::MethodProvider::String;
11 with 'Moose::AttributeHelpers::Trait::Base';
13 has 'method_provider' => (
16 predicate => 'has_method_provider',
17 default => 'Moose::AttributeHelpers::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 );
40 # register the alias ...
41 package # hide me from search.cpan.org
42 Moose::Meta::Attribute::Custom::Trait::String;
43 sub register_implementation { 'Moose::AttributeHelpers::Trait::String' }
53 Moose::AttributeHelpers::String
59 use Moose::AttributeHelpers;
62 metaclass => 'String',
68 replace_text => 'replace',
72 my $page = MyHomePage->new();
73 $page->add_text("foo"); # same as $page->text($page->text . "foo");
77 This module provides a simple string attribute, to which mutating string
78 operations can be applied more easily (no need to make an lvalue attribute
79 metaclass or use temporary variables). Additional methods are provided for
82 If your attribute definition does not include any of I<is>, I<isa>,
83 I<default> or I<handles> but does use the C<String> metaclass,
84 then this module applies defaults as in the L</SYNOPSIS>
85 above. This allows for a very basic counter definition:
87 has 'foo' => (metaclass => 'String');
96 =item B<method_provider>
98 =item B<has_method_provider>
102 =head1 PROVIDED METHODS
104 It is important to note that all those methods do in place
105 modification of the value stored in the attribute.
111 Increments the value stored in this slot using the magical string autoincrement
112 operator. Note that Perl doesn't provide analogous behavior in C<-->, so
113 C<dec> is not available.
115 =item I<append> C<$string>
117 Append a string, like C<.=>.
119 =item I<prepend> C<$string>
123 =item I<replace> C<$pattern> C<$replacement>
125 Performs a regexp substitution (L<perlop/s>). There is no way to provide the
126 C<g> flag, but code references will be accepted for the replacement, causing
127 the regex to be modified with a single C<e>. C</smxi> can be applied using the
130 =item I<match> C<$pattern>
132 Like I<replace> but without the replacement. Provided mostly for completeness.
144 Sets the string to the empty string (not the value passed to C<default>).
150 All complex software has bugs lurking in it, and this module is no
151 exception. If you find a bug please either email me, or add the bug
156 Stevan Little E<lt>stevan@iinteractive.comE<gt>
158 =head1 COPYRIGHT AND LICENSE
160 Copyright 2007-2009 by Infinity Interactive, Inc.
162 L<http://www.iinteractive.com>
164 This library is free software; you can redistribute it and/or modify
165 it under the same terms as Perl itself.