2 package MooseX::AttributeHelpers::String;
6 our $AUTHORITY = 'cpan:STEVAN';
8 extends 'Moose::Meta::Attribute';
9 with 'MooseX::AttributeHelpers::Trait::String';
13 # register the alias ...
14 package # hide me from search.cpan.org
15 Moose::Meta::Attribute::Custom::String;
16 sub register_implementation { 'MooseX::AttributeHelpers::String' }
26 MooseX::AttributeHelpers::String
32 use MooseX::AttributeHelpers;
35 metaclass => 'String',
38 default => sub { '' },
41 replace => "replace_text",
45 my $page = MyHomePage->new();
46 $page->add_text("foo"); # same as $page->text($page->text . "foo");
50 This module provides a simple string attribute, to which mutating string
51 operations can be applied more easily (no need to make an lvalue attribute
52 metaclass or use temporary variables). Additional methods are provided for
55 If your attribute definition does not include any of I<is>, I<isa>,
56 I<default> or I<provides> but does use the C<String> metaclass,
57 then this module applies defaults as in the L</SYNOPSIS>
58 above. This allows for a very basic counter definition:
60 has 'foo' => (metaclass => 'String');
69 =item B<method_provider>
71 =item B<has_method_provider>
75 =item B<process_options_for_provides>
77 Run before its superclass method.
79 =item B<check_provides_values>
81 Run after its superclass method.
85 =head1 PROVIDED METHODS
87 It is important to note that all those methods do in place
88 modification of the value stored in the attribute.
94 Increments the value stored in this slot using the magical string autoincrement
95 operator. Note that Perl doesn't provide analogeous behavior in C<-->, so
96 C<dec> is not available.
98 =item I<append> C<$string>
100 Append a string, like C<.=>.
102 =item I<prepend> C<$string>
106 =item I<replace> C<$pattern> C<$replacement>
108 Performs a regexp substitution (L<perlop/s>). There is no way to provide the
109 C<g> flag, but code references will be accepted for the replacement, causing
110 the regex to be modified with a single C<e>. C</smxi> can be applied using the
113 =item I<match> C<$pattern>
115 Like I<replace> but without the replacement. Provided mostly for completeness.
127 Sets the string to the empty string (not the value passed to C<default>).
133 All complex software has bugs lurking in it, and this module is no
134 exception. If you find a bug please either email me, or add the bug
139 Stevan Little E<lt>stevan@iinteractive.comE<gt>
141 =head1 COPYRIGHT AND LICENSE
143 Copyright 2007-2008 by Infinity Interactive, Inc.
145 L<http://www.iinteractive.com>
147 This library is free software; you can redistribute it and/or modify
148 it under the same terms as Perl itself.