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