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