stop using excludes within moose, since it's no longer necessary
[gitmo/Moose.git] / lib / Moose / Meta / Attribute / Native / Trait / String.pm
CommitLineData
c466e58f 1package Moose::Meta::Attribute::Native::Trait::String;
e3c07b19 2use Moose::Role;
3
c466e58f 4with 'Moose::Meta::Attribute::Native::Trait';
e3c07b19 5
2edb73d9 6sub _default_default { q{} }
7sub _default_is { 'rw' }
2e069f5a 8sub _helper_type { 'Str' }
e3c07b19 9
e3c07b19 10no Moose::Role;
11
e3c07b19 121;
13
ad46f524 14# ABSTRACT: Helper trait for Str attributes
15
e3c07b19 16__END__
17
18=pod
19
e3c07b19 20=head1 SYNOPSIS
21
22 package MyHomePage;
23 use Moose;
e3c07b19 24
25 has 'text' => (
e132fd56 26 traits => ['String'],
27 is => 'rw',
28 isa => 'Str',
29 default => q{},
30 handles => {
5f3663b2 31 add_text => 'append',
32 replace_text => 'replace',
9610c1d2 33 },
e3c07b19 34 );
35
36 my $page = MyHomePage->new();
e132fd56 37 $page->add_text("foo"); # same as $page->text($page->text . "foo");
e3c07b19 38
39=head1 DESCRIPTION
40
7795e4de 41This trait provides native delegation methods for strings.
42
43=head1 DEFAULT TYPE
44
45If you don't provide an C<isa> value for your attribute, it will default to
46C<Str>.
e3c07b19 47
e3c07b19 48=head1 PROVIDED METHODS
49
e3c07b19 50=over 4
51
e132fd56 52=item * B<inc>
e3c07b19 53
54Increments the value stored in this slot using the magical string autoincrement
a6dd8c94 55operator. Note that Perl doesn't provide analogous behavior in C<-->, so
e132fd56 56C<dec> is not available. This method returns the new value.
e3c07b19 57
e132fd56 58This method does not accept any arguments.
e3c07b19 59
e132fd56 60=item * B<append($string)>
e3c07b19 61
e132fd56 62Appends to the string, like C<.=>, and returns the new value.
e3c07b19 63
e132fd56 64This method requires a single argument.
e3c07b19 65
e132fd56 66=item * B<prepend($string)>
67
68Prepends to the string and returns the new value.
69
70This method requires a single argument.
71
72=item * B<replace($pattern, $replacement)>
e3c07b19 73
74Performs a regexp substitution (L<perlop/s>). There is no way to provide the
75C<g> flag, but code references will be accepted for the replacement, causing
76the regex to be modified with a single C<e>. C</smxi> can be applied using the
e132fd56 77C<qr> operator. This method returns the new value.
e3c07b19 78
e132fd56 79This method requires two arguments.
e3c07b19 80
e132fd56 81=item * B<match($pattern)>
e3c07b19 82
e132fd56 83Runs the regex against the string and returns the matching value(s).
e3c07b19 84
e132fd56 85This method requires a single argument.
e3c07b19 86
e132fd56 87=item * B<chop>
e3c07b19 88
e132fd56 89Just like L<perlfunc/chop>. This method returns the chopped character.
e3c07b19 90
e132fd56 91This method does not accept any arguments.
e3c07b19 92
e132fd56 93=item * B<chomp>
94
95Just like L<perlfunc/chomp>. This method returns the number of characters
96removed.
e3c07b19 97
e132fd56 98This method does not accept any arguments.
eb95da0e 99
e132fd56 100=item * B<clear>
eb95da0e 101
e132fd56 102Sets the string to the empty string (not the value passed to C<default>).
eb95da0e 103
e132fd56 104This method does not have a defined return value.
eb95da0e 105
e132fd56 106This method does not accept any arguments.
e3c07b19 107
e132fd56 108=item * B<length>
79b647c6 109
e132fd56 110Just like L<perlfunc/length>, returns the length of the string.
111
112=item * B<substr>
113
114This acts just like L<perlfunc/substr>. When called as a writer, it returns
115the substring that was replaced, just like the Perl builtin.
79b647c6 116
e132fd56 117This method requires at least one argument, and accepts no more than three.
79b647c6 118
79b647c6 119=back
120
e3c07b19 121=head1 BUGS
122
d4048ef3 123See L<Moose/BUGS> for details on reporting bugs.
e3c07b19 124
e3c07b19 125=cut