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