2 package MooseX::AttributeHelpers::String;
4 use MooseX::AttributeHelpers::Sugar;
6 extends 'MooseX::AttributeHelpers::Base';
9 our $AUTHORITY = 'cpan:STEVAN';
11 define_attribute_helper (
18 method_provider => 'MooseX::AttributeHelpers::MethodProvider::String',
24 no MooseX::AttributeHelpers::Sugar;
34 MooseX::AttributeHelpers::String
40 use MooseX::AttributeHelpers;
43 metaclass => 'String',
46 default => sub { '' },
49 replace => "replace_text",
53 my $page = MyHomePage->new();
54 $page->add_text("foo"); # same as $page->text($page->text . "foo");
58 This module provides a simple string attribute, to which mutating string
59 operations can be applied more easily (no need to make an lvalue attribute
60 metaclass or use temporary variables). Additional methods are provided for
63 If your attribute definition does not include any of I<is>, I<isa>,
64 I<default> or I<provides> but does use the C<String> metaclass,
65 then this module applies defaults as in the L</SYNOPSIS>
66 above. This allows for a very basic attribute definition:
68 has 'foo' => (metaclass => 'String');
79 =head1 PROVIDED METHODS
81 It is important to note that all those methods do in place
82 modification of the value stored in the attribute.
88 Increments the value stored in this slot using the magical string autoincrement
89 operator. Note that Perl doesn't provide analogeous behavior in C<-->, so
90 C<dec> is not available.
92 =item I<append> C<$string>
94 Append a string, like C<.=>.
96 =item I<prepend> C<$string>
100 =item I<replace> C<$pattern> C<$replacement>
102 Performs a regexp substitution (L<perlop/s>). There is no way to provide the
103 C<g> flag, but code references will be accepted for the replacement, causing
104 the regex to be modified with a single C<e>. C</smxi> can be applied using the
107 =item I<match> C<$pattern>
109 Like I<replace> but without the replacement. Provided mostly for completeness.
121 Sets the string to the empty string (not the value passed to C<default>).
127 All complex software has bugs lurking in it, and this module is no
128 exception. If you find a bug please either email me, or add the bug
133 Stevan Little E<lt>stevan@iinteractive.comE<gt>
135 =head1 COPYRIGHT AND LICENSE
137 Copyright 2007-2008 by Infinity Interactive, Inc.
139 L<http://www.iinteractive.com>
141 This library is free software; you can redistribute it and/or modify
142 it under the same terms as Perl itself.