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 helper_type { 'Str' }
22 sub _default_default { q{} }
23 sub _default_is { 'rw' }
25 after '_check_handles_values' => sub {
27 my $handles = $self->handles;
29 unless ( scalar keys %$handles ) {
30 my $method_constructors = $self->method_constructors;
31 my $attr_name = $self->name;
33 foreach my $method ( keys %$method_constructors ) {
34 $handles->{$method} = ( $method . '_' . $attr_name );
41 # register the alias ...
42 package # hide me from search.cpan.org
43 Moose::Meta::Attribute::Custom::Trait::String;
44 sub register_implementation { 'Moose::AttributeHelpers::Trait::String' }
54 Moose::AttributeHelpers::String
60 use Moose::AttributeHelpers;
63 metaclass => 'String',
69 replace_text => 'replace',
73 my $page = MyHomePage->new();
74 $page->add_text("foo"); # same as $page->text($page->text . "foo");
78 This module provides a simple string attribute, to which mutating string
79 operations can be applied more easily (no need to make an lvalue attribute
80 metaclass or use temporary variables). Additional methods are provided for
83 If your attribute definition does not include any of I<is>, I<isa>,
84 I<default> or I<handles> but does use the C<String> metaclass,
85 then this module applies defaults as in the L</SYNOPSIS>
86 above. This allows for a very basic counter definition:
88 has 'foo' => (metaclass => 'String');
97 =item B<method_provider>
99 =item B<has_method_provider>
103 =item B<process_options_for_handles>
105 Run before its superclass method.
107 =item B<check_handles_values>
109 Run after its superclass method.
113 =head1 PROVIDED METHODS
115 It is important to note that all those methods do in place
116 modification of the value stored in the attribute.
122 Increments the value stored in this slot using the magical string autoincrement
123 operator. Note that Perl doesn't provide analogous behavior in C<-->, so
124 C<dec> is not available.
126 =item I<append> C<$string>
128 Append a string, like C<.=>.
130 =item I<prepend> C<$string>
134 =item I<replace> C<$pattern> C<$replacement>
136 Performs a regexp substitution (L<perlop/s>). There is no way to provide the
137 C<g> flag, but code references will be accepted for the replacement, causing
138 the regex to be modified with a single C<e>. C</smxi> can be applied using the
141 =item I<match> C<$pattern>
143 Like I<replace> but without the replacement. Provided mostly for completeness.
155 Sets the string to the empty string (not the value passed to C<default>).
161 All complex software has bugs lurking in it, and this module is no
162 exception. If you find a bug please either email me, or add the bug
167 Stevan Little E<lt>stevan@iinteractive.comE<gt>
169 =head1 COPYRIGHT AND LICENSE
171 Copyright 2007-2009 by Infinity Interactive, Inc.
173 L<http://www.iinteractive.com>
175 This library is free software; you can redistribute it and/or modify
176 it under the same terms as Perl itself.