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