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' }
35 Moose::Meta::Attribute::Native::Trait::String - Helper trait for Str attributes
49 replace_text => 'replace',
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<handles> 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 string definition:
68 has 'foo' => (traits => ['String']);
71 =head1 PROVIDED METHODS
77 Increments the value stored in this slot using the magical string autoincrement
78 operator. Note that Perl doesn't provide analogous behavior in C<-->, so
79 C<dec> is not available. This method returns the new value.
81 This method does not accept any arguments.
83 =item * B<append($string)>
85 Appends to the string, like C<.=>, and returns the new value.
87 This method requires a single argument.
89 =item * B<prepend($string)>
91 Prepends to the string and returns the new value.
93 This method requires a single argument.
95 =item * B<replace($pattern, $replacement)>
97 Performs a regexp substitution (L<perlop/s>). There is no way to provide the
98 C<g> flag, but code references will be accepted for the replacement, causing
99 the regex to be modified with a single C<e>. C</smxi> can be applied using the
100 C<qr> operator. This method returns the new value.
102 This method requires two arguments.
104 =item * B<match($pattern)>
106 Runs the regex against the string and returns the matching value(s).
108 This method requires a single argument.
112 Just like L<perlfunc/chop>. This method returns the chopped character.
114 This method does not accept any arguments.
118 Just like L<perlfunc/chomp>. This method returns the number of characters
121 This method does not accept any arguments.
125 Sets the string to the empty string (not the value passed to C<default>).
127 This method does not have a defined return value.
129 This method does not accept any arguments.
133 Just like L<perlfunc/length>, returns the length of the string.
137 This acts just like L<perlfunc/substr>. When called as a writer, it returns
138 the substring that was replaced, just like the Perl builtin.
140 This method requires at least one argument, and accepts no more than three.
146 See L<Moose/BUGS> for details on reporting bugs.
150 Stevan Little E<lt>stevan@iinteractive.comE<gt>
152 =head1 COPYRIGHT AND LICENSE
154 Copyright 2007-2009 by Infinity Interactive, Inc.
156 L<http://www.iinteractive.com>
158 This library is free software; you can redistribute it and/or modify
159 it under the same terms as Perl itself.