Commit | Line | Data |
c466e58f |
1 | package Moose::Meta::Attribute::Native::Trait::String; |
e3c07b19 |
2 | use Moose::Role; |
3 | |
bb8ef151 |
4 | our $VERSION = '1.9900'; |
e3c07b19 |
5 | $VERSION = eval $VERSION; |
6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | |
c466e58f |
8 | with 'Moose::Meta::Attribute::Native::Trait'; |
e3c07b19 |
9 | |
2edb73d9 |
10 | sub _default_default { q{} } |
11 | sub _default_is { 'rw' } |
2e069f5a |
12 | sub _helper_type { 'Str' } |
e3c07b19 |
13 | |
e3c07b19 |
14 | no Moose::Role; |
15 | |
e3c07b19 |
16 | 1; |
17 | |
18 | __END__ |
19 | |
20 | =pod |
21 | |
22 | =head1 NAME |
23 | |
2420461c |
24 | Moose::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 |
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>. |
e3c07b19 |
53 | |
e3c07b19 |
54 | =head1 PROVIDED METHODS |
55 | |
e3c07b19 |
56 | =over 4 |
57 | |
e132fd56 |
58 | =item * B<inc> |
e3c07b19 |
59 | |
60 | Increments the value stored in this slot using the magical string autoincrement |
a6dd8c94 |
61 | operator. Note that Perl doesn't provide analogous behavior in C<-->, so |
e132fd56 |
62 | C<dec> is not available. This method returns the new value. |
e3c07b19 |
63 | |
e132fd56 |
64 | This method does not accept any arguments. |
e3c07b19 |
65 | |
e132fd56 |
66 | =item * B<append($string)> |
e3c07b19 |
67 | |
e132fd56 |
68 | Appends to the string, like C<.=>, and returns the new value. |
e3c07b19 |
69 | |
e132fd56 |
70 | This method requires a single argument. |
e3c07b19 |
71 | |
e132fd56 |
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)> |
e3c07b19 |
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 |
e132fd56 |
83 | C<qr> operator. This method returns the new value. |
e3c07b19 |
84 | |
e132fd56 |
85 | This method requires two arguments. |
e3c07b19 |
86 | |
e132fd56 |
87 | =item * B<match($pattern)> |
e3c07b19 |
88 | |
e132fd56 |
89 | Runs the regex against the string and returns the matching value(s). |
e3c07b19 |
90 | |
e132fd56 |
91 | This method requires a single argument. |
e3c07b19 |
92 | |
e132fd56 |
93 | =item * B<chop> |
e3c07b19 |
94 | |
e132fd56 |
95 | Just like L<perlfunc/chop>. This method returns the chopped character. |
e3c07b19 |
96 | |
e132fd56 |
97 | This method does not accept any arguments. |
e3c07b19 |
98 | |
e132fd56 |
99 | =item * B<chomp> |
100 | |
101 | Just like L<perlfunc/chomp>. This method returns the number of characters |
102 | removed. |
e3c07b19 |
103 | |
e132fd56 |
104 | This method does not accept any arguments. |
eb95da0e |
105 | |
e132fd56 |
106 | =item * B<clear> |
eb95da0e |
107 | |
e132fd56 |
108 | Sets the string to the empty string (not the value passed to C<default>). |
eb95da0e |
109 | |
e132fd56 |
110 | This method does not have a defined return value. |
eb95da0e |
111 | |
e132fd56 |
112 | This method does not accept any arguments. |
e3c07b19 |
113 | |
e132fd56 |
114 | =item * B<length> |
79b647c6 |
115 | |
e132fd56 |
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. |
79b647c6 |
122 | |
e132fd56 |
123 | This method requires at least one argument, and accepts no more than three. |
79b647c6 |
124 | |
79b647c6 |
125 | =back |
126 | |
e3c07b19 |
127 | =head1 BUGS |
128 | |
d4048ef3 |
129 | See L<Moose/BUGS> for details on reporting bugs. |
e3c07b19 |
130 | |
131 | =head1 AUTHOR |
132 | |
133 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
134 | |
135 | =head1 COPYRIGHT AND LICENSE |
136 | |
8e5dd3fb |
137 | Copyright 2007-2010 by Infinity Interactive, Inc. |
e3c07b19 |
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 |