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