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