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