1 package Moose::Meta::Attribute::Native::Trait::String;
5 $VERSION = eval $VERSION;
6 our $AUTHORITY = 'cpan:STEVAN';
8 use Moose::Meta::Method::Accessor::Native::String::append;
9 use Moose::Meta::Method::Accessor::Native::String::chomp;
10 use Moose::Meta::Method::Accessor::Native::String::chop;
11 use Moose::Meta::Method::Accessor::Native::String::clear;
12 use Moose::Meta::Method::Accessor::Native::String::inc;
13 use Moose::Meta::Method::Accessor::Native::String::length;
14 use Moose::Meta::Method::Accessor::Native::String::match;
15 use Moose::Meta::Method::Accessor::Native::String::prepend;
16 use Moose::Meta::Method::Accessor::Native::String::replace;
17 use Moose::Meta::Method::Accessor::Native::String::substr;
19 with 'Moose::Meta::Attribute::Native::Trait';
21 sub _default_default { q{} }
22 sub _default_is { 'rw' }
23 sub _helper_type { 'Str' }
25 sub _native_type { 'String' }
37 Moose::Meta::Attribute::Native::Trait::String - Helper trait for Str attributes
51 replace_text => 'replace',
55 my $page = MyHomePage->new();
56 $page->add_text("foo"); # same as $page->text($page->text . "foo");
60 This module provides a simple string attribute, to which mutating string
61 operations can be applied more easily (no need to make an lvalue attribute
62 metaclass or use temporary variables). Additional methods are provided for
65 If your attribute definition does not include any of I<is>, I<isa>,
66 I<default> or I<handles> but does use the C<String> metaclass,
67 then this module applies defaults as in the L</SYNOPSIS>
68 above. This allows for a very basic string definition:
70 has 'foo' => (traits => ['String']);
73 =head1 PROVIDED METHODS
75 These methods are implemented in
76 L<Moose::Meta::Attribute::Native::MethodProvider::String>. It is important to
77 note that all those methods do in place modification of the value stored in
84 Increments the value stored in this slot using the magical string autoincrement
85 operator. Note that Perl doesn't provide analogous behavior in C<-->, so
86 C<dec> is not available.
88 =item B<append($string)>
90 Append a string, like C<.=>.
92 =item B<prepend($string)>
96 =item B<replace($pattern, $replacement)>
98 Performs a regexp substitution (L<perlop/s>). There is no way to provide the
99 C<g> flag, but code references will be accepted for the replacement, causing
100 the regex to be modified with a single C<e>. C</smxi> can be applied using the
103 =item B<match($pattern)>
105 Like C<replace> but without the replacement. Provided mostly for completeness.
117 Sets the string to the empty string (not the value passed to C<default>).
125 L<perlfunc/substr>. We go to some lengths to match the different functionality
126 based on C<substr>'s arity.
136 =item B<method_provider>
138 =item B<has_method_provider>
144 See L<Moose/BUGS> for details on reporting bugs.
148 Stevan Little E<lt>stevan@iinteractive.comE<gt>
150 =head1 COPYRIGHT AND LICENSE
152 Copyright 2007-2009 by Infinity Interactive, Inc.
154 L<http://www.iinteractive.com>
156 This library is free software; you can redistribute it and/or modify
157 it under the same terms as Perl itself.