bump version to 0.22
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / String.pm
CommitLineData
190b1c02 1
2package MooseX::AttributeHelpers::String;
3use Moose;
4
3ebd23e6 5our $VERSION = '0.22';
38430345 6$VERSION = eval $VERSION;
190b1c02 7our $AUTHORITY = 'cpan:STEVAN';
8
090583df 9extends 'Moose::Meta::Attribute';
10with 'MooseX::AttributeHelpers::Trait::String';
190b1c02 11
12no Moose;
13
14# register the alias ...
15package # hide me from search.cpan.org
16 Moose::Meta::Attribute::Custom::String;
17sub register_implementation { 'MooseX::AttributeHelpers::String' }
18
191;
20
21__END__
22
23=pod
24
25=head1 NAME
26
27MooseX::AttributeHelpers::String
28
29=head1 SYNOPSIS
30
31 package MyHomePage;
32 use Moose;
33 use MooseX::AttributeHelpers;
34
35 has 'text' => (
36 metaclass => 'String',
37 is => 'rw',
38 isa => 'Str',
39 default => sub { '' },
40 provides => {
41 append => "add_text",
42 replace => "replace_text",
43 }
44 );
45
46 my $page = MyHomePage->new();
47 $page->add_text("foo"); # same as $page->text($page->text . "foo");
48
49=head1 DESCRIPTION
50
51This module provides a simple string attribute, to which mutating string
52operations can be applied more easily (no need to make an lvalue attribute
53metaclass or use temporary variables). Additional methods are provided for
54completion.
55
56If your attribute definition does not include any of I<is>, I<isa>,
57I<default> or I<provides> but does use the C<String> metaclass,
58then this module applies defaults as in the L</SYNOPSIS>
59above. This allows for a very basic counter definition:
60
61 has 'foo' => (metaclass => 'String');
62 $obj->append_foo;
63
64=head1 METHODS
65
66=over 4
67
68=item B<meta>
69
70=item B<method_provider>
71
72=item B<has_method_provider>
73
74=item B<helper_type>
75
76=item B<process_options_for_provides>
77
78Run before its superclass method.
79
80=item B<check_provides_values>
81
82Run after its superclass method.
83
84=back
85
86=head1 PROVIDED METHODS
87
88It is important to note that all those methods do in place
89modification of the value stored in the attribute.
90
91=over 4
92
93=item I<inc>
94
95Increments the value stored in this slot using the magical string autoincrement
96operator. Note that Perl doesn't provide analogeous behavior in C<-->, so
97C<dec> is not available.
98
99=item I<append> C<$string>
100
101Append a string, like C<.=>.
102
103=item I<prepend> C<$string>
104
105Prepend a string.
106
107=item I<replace> C<$pattern> C<$replacement>
108
109Performs a regexp substitution (L<perlop/s>). There is no way to provide the
110C<g> flag, but code references will be accepted for the replacement, causing
111the regex to be modified with a single C<e>. C</smxi> can be applied using the
112C<qr> operator.
113
114=item I<match> C<$pattern>
115
116Like I<replace> but without the replacement. Provided mostly for completeness.
117
118=item C<chop>
119
120L<perlfunc/chop>
121
122=item C<chomp>
123
124L<perlfunc/chomp>
125
126=item C<clear>
127
128Sets the string to the empty string (not the value passed to C<default>).
129
130=back
131
132=head1 BUGS
133
134All complex software has bugs lurking in it, and this module is no
135exception. If you find a bug please either email me, or add the bug
136to cpan-RT.
137
138=head1 AUTHOR
139
140Stevan Little E<lt>stevan@iinteractive.comE<gt>
141
142=head1 COPYRIGHT AND LICENSE
143
9c5d164e 144Copyright 2007-2009 by Infinity Interactive, Inc.
190b1c02 145
146L<http://www.iinteractive.com>
147
148This library is free software; you can redistribute it and/or modify
149it under the same terms as Perl itself.
150
151=cut