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 package # hide me from search.cpan.org
41 Moose::Meta::Attribute::Custom::Trait::String;
42 sub register_implementation { 'Moose::AttributeHelpers::Trait::String' }
52 Moose::AttributeHelpers::String
58 use Moose::AttributeHelpers;
61 metaclass => 'String',
67 replace_text => 'replace',
71 my $page = MyHomePage->new();
72 $page->add_text("foo"); # same as $page->text($page->text . "foo");
76 This module provides a simple string attribute, to which mutating string
77 operations can be applied more easily (no need to make an lvalue attribute
78 metaclass or use temporary variables). Additional methods are provided for
81 If your attribute definition does not include any of I<is>, I<isa>,
82 I<default> or I<handles> but does use the C<String> metaclass,
83 then this module applies defaults as in the L</SYNOPSIS>
84 above. This allows for a very basic counter definition:
86 has 'foo' => (metaclass => 'String');
95 =item B<method_provider>
97 =item B<has_method_provider>
101 =head1 PROVIDED METHODS
103 It is important to note that all those methods do in place
104 modification of the value stored in the attribute.
110 Increments the value stored in this slot using the magical string autoincrement
111 operator. Note that Perl doesn't provide analogous behavior in C<-->, so
112 C<dec> is not available.
114 =item I<append> C<$string>
116 Append a string, like C<.=>.
118 =item I<prepend> C<$string>
122 =item I<replace> C<$pattern> C<$replacement>
124 Performs a regexp substitution (L<perlop/s>). There is no way to provide the
125 C<g> flag, but code references will be accepted for the replacement, causing
126 the regex to be modified with a single C<e>. C</smxi> can be applied using the
129 =item I<match> C<$pattern>
131 Like I<replace> but without the replacement. Provided mostly for completeness.
143 Sets the string to the empty string (not the value passed to C<default>).
149 All complex software has bugs lurking in it, and this module is no
150 exception. If you find a bug please either email me, or add the bug
155 Stevan Little E<lt>stevan@iinteractive.comE<gt>
157 =head1 COPYRIGHT AND LICENSE
159 Copyright 2007-2009 by Infinity Interactive, Inc.
161 L<http://www.iinteractive.com>
163 This library is free software; you can redistribute it and/or modify
164 it under the same terms as Perl itself.