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