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