Use dzil Authority plugin - remove $AUTHORITY from code
[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 with 'Moose::Meta::Attribute::Native::Trait';
5
6 sub _default_default { q{} }
7 sub _default_is { 'rw' }
8 sub _helper_type { 'Str' }
9
10 no Moose::Role;
11
12 1;
13
14 # ABSTRACT: Helper trait for Str attributes
15
16 __END__
17
18 =pod
19
20 =head1 SYNOPSIS
21
22   package MyHomePage;
23   use Moose;
24
25   has 'text' => (
26       traits  => ['String'],
27       is      => 'rw',
28       isa     => 'Str',
29       default => q{},
30       handles => {
31           add_text     => 'append',
32           replace_text => 'replace',
33       },
34   );
35
36   my $page = MyHomePage->new();
37   $page->add_text("foo");    # same as $page->text($page->text . "foo");
38
39 =head1 DESCRIPTION
40
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>.
47
48 =head1 PROVIDED METHODS
49
50 =over 4
51
52 =item * B<inc>
53
54 Increments the value stored in this slot using the magical string autoincrement
55 operator. Note that Perl doesn't provide analogous behavior in C<-->, so
56 C<dec> is not available. This method returns the new value.
57
58 This method does not accept any arguments.
59
60 =item * B<append($string)>
61
62 Appends to the string, like C<.=>, and returns the new value.
63
64 This method requires a single argument.
65
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)>
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
77 C<qr> operator. This method returns the new value.
78
79 This method requires two arguments.
80
81 =item * B<match($pattern)>
82
83 Runs the regex against the string and returns the matching value(s).
84
85 This method requires a single argument.
86
87 =item * B<chop>
88
89 Just like L<perlfunc/chop>. This method returns the chopped character.
90
91 This method does not accept any arguments.
92
93 =item * B<chomp>
94
95 Just like L<perlfunc/chomp>. This method returns the number of characters
96 removed.
97
98 This method does not accept any arguments.
99
100 =item * B<clear>
101
102 Sets the string to the empty string (not the value passed to C<default>).
103
104 This method does not have a defined return value.
105
106 This method does not accept any arguments.
107
108 =item * B<length>
109
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.
116
117 This method requires at least one argument, and accepts no more than three.
118
119 =back
120
121 =head1 BUGS
122
123 See L<Moose/BUGS> for details on reporting bugs.
124
125 =cut