2 package Moose::AttributeHelpers::String;
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
9 extends 'Moose::Meta::Attribute';
10 with 'Moose::AttributeHelpers::Trait::String';
14 # register the alias ...
15 package # hide me from search.cpan.org
16 Moose::Meta::Attribute::Custom::String;
17 sub register_implementation { 'Moose::AttributeHelpers::String' }
27 Moose::AttributeHelpers::String
33 use Moose::AttributeHelpers;
36 metaclass => 'String',
39 default => sub { '' },
42 replace => "replace_text",
46 my $page = MyHomePage->new();
47 $page->add_text("foo"); # same as $page->text($page->text . "foo");
51 This module provides a simple string attribute, to which mutating string
52 operations can be applied more easily (no need to make an lvalue attribute
53 metaclass or use temporary variables). Additional methods are provided for
56 If your attribute definition does not include any of I<is>, I<isa>,
57 I<default> or I<provides> but does use the C<String> metaclass,
58 then this module applies defaults as in the L</SYNOPSIS>
59 above. This allows for a very basic counter definition:
61 has 'foo' => (metaclass => 'String');
70 =item B<method_provider>
72 =item B<has_method_provider>
76 =item B<process_options_for_handles>
78 Run before its superclass method.
80 =item B<check_handles_values>
82 Run after its superclass method.
86 =head1 PROVIDED METHODS
88 It is important to note that all those methods do in place
89 modification of the value stored in the attribute.
95 Increments the value stored in this slot using the magical string autoincrement
96 operator. Note that Perl doesn't provide analogeous behavior in C<-->, so
97 C<dec> is not available.
99 =item I<append> C<$string>
101 Append a string, like C<.=>.
103 =item I<prepend> C<$string>
107 =item I<replace> C<$pattern> C<$replacement>
109 Performs a regexp substitution (L<perlop/s>). There is no way to provide the
110 C<g> flag, but code references will be accepted for the replacement, causing
111 the regex to be modified with a single C<e>. C</smxi> can be applied using the
114 =item I<match> C<$pattern>
116 Like I<replace> but without the replacement. Provided mostly for completeness.
128 Sets the string to the empty string (not the value passed to C<default>).
134 All complex software has bugs lurking in it, and this module is no
135 exception. If you find a bug please either email me, or add the bug
140 Stevan Little E<lt>stevan@iinteractive.comE<gt>
142 =head1 COPYRIGHT AND LICENSE
144 Copyright 2007-2009 by Infinity Interactive, Inc.
146 L<http://www.iinteractive.com>
148 This library is free software; you can redistribute it and/or modify
149 it under the same terms as Perl itself.