bump version to 0.89_02 and set release date
[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 $VERSION   = '0.89_02';
5 $VERSION = eval $VERSION;
6 our $AUTHORITY = 'cpan:STEVAN';
7
8 use Moose::Meta::Attribute::Native::MethodProvider::String;
9
10 with 'Moose::Meta::Attribute::Native::Trait';
11
12 has 'method_provider' => (
13     is        => 'ro',
14     isa       => 'ClassName',
15     predicate => 'has_method_provider',
16     default   => 'Moose::Meta::Attribute::Native::MethodProvider::String',
17 );
18
19 sub _default_default { q{} }
20 sub _default_is { 'rw' }
21 sub _helper_type { 'Str' }
22
23 after '_check_handles_values' => sub {
24     my $self    = shift;
25     my $handles = $self->handles;
26
27     unless ( scalar keys %$handles ) {
28         my $method_constructors = $self->method_constructors;
29         my $attr_name           = $self->name;
30
31         foreach my $method ( keys %$method_constructors ) {
32             $handles->{$method} = ( $method . '_' . $attr_name );
33         }
34     }
35 };
36
37 no Moose::Role;
38
39 1;
40
41 __END__
42
43 =pod
44
45 =head1 NAME
46
47 Moose::Meta::Attribute::Native::Trait::String
48
49 =head1 SYNOPSIS
50
51   package MyHomePage;
52   use Moose;
53
54   has 'text' => (
55       traits    => ['String'],
56       is        => 'rw',
57       isa       => 'Str',
58       default   => q{},
59       handles   => {
60           add_text     => 'append',
61           replace_text => 'replace',
62       },
63   );
64
65   my $page = MyHomePage->new();
66   $page->add_text("foo"); # same as $page->text($page->text . "foo");
67
68 =head1 DESCRIPTION
69
70 This module provides a simple string attribute, to which mutating string
71 operations can be applied more easily (no need to make an lvalue attribute
72 metaclass or use temporary variables). Additional methods are provided for
73 completion.
74
75 If your attribute definition does not include any of I<is>, I<isa>,
76 I<default> or I<handles> but does use the C<String> metaclass,
77 then this module applies defaults as in the L</SYNOPSIS>
78 above. This allows for a very basic counter definition:
79
80   has 'foo' => (metaclass => 'String');
81   $obj->append_foo;
82
83 =head1 PROVIDED METHODS
84
85 These methods are implemented in
86 L<Moose::Meta::Attribute::Native::MethodProvider::STring>. It is important to
87 note that all those methods do in place modification of the value stored in
88 the attribute.
89
90 =over 4
91
92 =item B<inc>
93
94 Increments the value stored in this slot using the magical string autoincrement
95 operator. Note that Perl doesn't provide analogous behavior in C<-->, so
96 C<dec> is not available.
97
98 =item B<append($string)>
99
100 Append a string, like C<.=>.
101
102 =item B<prepend($string)>
103
104 Prepend a string.
105
106 =item B<replace($pattern, $replacement)>
107
108 Performs a regexp substitution (L<perlop/s>). There is no way to provide the
109 C<g> flag, but code references will be accepted for the replacement, causing
110 the regex to be modified with a single C<e>. C</smxi> can be applied using the
111 C<qr> operator.
112
113 =item B<match($pattern)>
114
115 Like C<replace> but without the replacement. Provided mostly for completeness.
116
117 =item B<chop>
118
119 L<perlfunc/chop>
120
121 =item B<chomp>
122
123 L<perlfunc/chomp>
124
125 =item B<clear>
126
127 Sets the string to the empty string (not the value passed to C<default>).
128
129 =item B<length>
130
131 L<perlfunc/length>
132
133 =item B<substr>
134
135 L<perlfunc/substr>. We go to some lengths to match the different functionality
136 based on C<substr>'s arity.
137
138 =back
139
140 =head1 METHODS
141
142 =over 4
143
144 =item B<meta>
145
146 =item B<method_provider>
147
148 =item B<has_method_provider>
149
150 =back
151
152 =head1 BUGS
153
154 All complex software has bugs lurking in it, and this module is no
155 exception. If you find a bug please either email me, or add the bug
156 to cpan-RT.
157
158 =head1 AUTHOR
159
160 Stevan Little E<lt>stevan@iinteractive.comE<gt>
161
162 =head1 COPYRIGHT AND LICENSE
163
164 Copyright 2007-2009 by Infinity Interactive, Inc.
165
166 L<http://www.iinteractive.com>
167
168 This library is free software; you can redistribute it and/or modify
169 it under the same terms as Perl itself.
170
171 =cut