2 package MooseX::AttributeHelpers::MethodProvider::String;
6 our $AUTHORITY = 'cpan:STEVAN';
9 my ($attr, $reader, $writer) = @_;
11 return sub { $writer->( $_[0], $reader->($_[0]) . $_[1] ) };
14 sub prepend : method {
15 my ($attr, $reader, $writer) = @_;
17 return sub { $writer->( $_[0], $_[1] . $reader->($_[0]) ) };
20 sub replace : method {
21 my ($attr, $reader, $writer) = @_;
24 my ( $self, $regex, $replacement ) = @_;
25 my $v = $reader->($_[0]);
27 if ( (ref($replacement)||'') eq 'CODE' ) {
28 $v =~ s/$regex/$replacement->()/e;
30 $v =~ s/$regex/$replacement/;
33 $writer->( $_[0], $v);
38 my ($attr, $reader, $writer) = @_;
39 return sub { $reader->($_[0]) =~ $_[1] };
43 my ($attr, $reader, $writer) = @_;
45 my $v = $reader->($_[0]);
47 $writer->( $_[0], $v);
52 my ($attr, $reader, $writer) = @_;
54 my $v = $reader->($_[0]);
56 $writer->( $_[0], $v);
61 my ($attr, $reader, $writer) = @_;
63 my $v = $reader->($_[0]);
65 $writer->( $_[0], $v);
70 my ($attr, $reader, $writer ) = @_;
71 return sub { $writer->( $_[0], '' ) }
82 MooseX::AttributeHelpers::MethodProvider::String
86 This is a role which provides the method generators for
87 L<MooseX::AttributeHelpers::String>.
89 =head1 PROVIDED METHODS
91 It should be noted that all methods modify attribute values in place.
97 Increments the value stored in this slot using the magical string autoincrement
98 operator. Note that Perl doesn't provide analogeous behavior in C<-->, so
99 C<dec> is not available.
101 =item I<append> C<$string>
103 Append a string, like C<.=>.
105 =item I<prepend> C<$string>
109 =item I<replace> C<$pattern> C<$replacement>
111 Performs a regexp substitution (L<perlop/s>). There is no way to provide the
112 C<g> flag, but code references will be accepted for the replacement, causing
113 the regex to be modified with a single C<e>. C</smxi> can be applied using the
116 =item I<match> C<$pattern>
118 Like I<replace> but without the replacement. Provided mostly for completeness.
130 Sets the string to the empty string (not the value passed to C<default>).
136 All complex software has bugs lurking in it, and this module is no
137 exception. If you find a bug please either email me, or add the bug
142 Stevan Little E<lt>stevan@iinteractive.comE<gt>
144 =head1 COPYRIGHT AND LICENSE
146 Copyright 2007-2008 by Infinity Interactive, Inc.
148 L<http://www.iinteractive.com>
150 This library is free software; you can redistribute it and/or modify
151 it under the same terms as Perl itself.