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