File Coverage

blib/lib/MooseX/AttributeHelpers/String.pm
Criterion Covered Total %
statement 7 7 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 10 100.0


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