1 package Moose::Meta::Attribute::Native::Trait::String;
5 $VERSION = eval $VERSION;
6 our $AUTHORITY = 'cpan:STEVAN';
8 use Moose::Meta::Attribute::Native::MethodProvider::String;
10 with 'Moose::Meta::Attribute::Native::Trait';
12 has 'method_provider' => (
15 predicate => 'has_method_provider',
16 default => 'Moose::Meta::Attribute::Native::MethodProvider::String',
19 sub _default_default { q{} }
20 sub _default_is { 'rw' }
21 sub _helper_type { 'Str' }
23 after '_check_handles_values' => sub {
25 my $handles = $self->handles;
27 unless ( scalar keys %$handles ) {
28 my $method_constructors = $self->method_constructors;
29 my $attr_name = $self->name;
31 foreach my $method ( keys %$method_constructors ) {
32 $handles->{$method} = ( $method . '_' . $attr_name );
47 Moose::Meta::Attribute::Native::Trait::String
53 use Moose::AttributeHelpers;
56 metaclass => 'String',
62 replace_text => 'replace',
66 my $page = MyHomePage->new();
67 $page->add_text("foo"); # same as $page->text($page->text . "foo");
71 This module provides a simple string attribute, to which mutating string
72 operations can be applied more easily (no need to make an lvalue attribute
73 metaclass or use temporary variables). Additional methods are provided for
76 If your attribute definition does not include any of I<is>, I<isa>,
77 I<default> or I<handles> but does use the C<String> metaclass,
78 then this module applies defaults as in the L</SYNOPSIS>
79 above. This allows for a very basic counter definition:
81 has 'foo' => (metaclass => 'String');
84 =head1 PROVIDED METHODS
86 These methods are implemented in
87 L<Moose::Meta::Attribute::Native::MethodProvider::STring>. It is important to
88 note that all those methods do in place modification of the value stored in
95 Increments the value stored in this slot using the magical string autoincrement
96 operator. Note that Perl doesn't provide analogous 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>).
138 =item B<method_provider>
140 =item B<has_method_provider>
146 All complex software has bugs lurking in it, and this module is no
147 exception. If you find a bug please either email me, or add the bug
152 Stevan Little E<lt>stevan@iinteractive.comE<gt>
154 =head1 COPYRIGHT AND LICENSE
156 Copyright 2007-2009 by Infinity Interactive, Inc.
158 L<http://www.iinteractive.com>
160 This library is free software; you can redistribute it and/or modify
161 it under the same terms as Perl itself.