1 package MooseX::AttributeHelpers::MethodProvider::String;
2 use MooseX::AttributeHelpers::MethodProvider;
5 our $AUTHORITY = 'cpan:STEVAN';
7 add_method_provider String => (
11 my ($attr, $reader, $writer) = @_;
12 return sub { $writer->( $_[0], $reader->($_[0]) . $_[1] ) };
16 my ($attr, $reader, $writer) = @_;
17 return sub { $writer->( $_[0], $_[1] . $reader->($_[0]) ) };
21 my ($attr, $reader, $writer) = @_;
23 my ( $self, $regex, $replacement ) = @_;
24 my $v = $reader->($_[0]);
26 if ( (ref($replacement)||'') eq 'CODE' ) {
27 $v =~ s/$regex/$replacement->()/e;
29 $v =~ s/$regex/$replacement/;
32 $writer->( $_[0], $v);
37 my ($attr, $reader, $writer) = @_;
38 return sub { $reader->($_[0]) =~ $_[1] };
42 my ($attr, $reader, $writer) = @_;
44 my $v = $reader->($_[0]);
46 $writer->( $_[0], $v);
51 my ($attr, $reader, $writer) = @_;
53 my $v = $reader->($_[0]);
55 $writer->( $_[0], $v);
60 my ($attr, $reader, $writer) = @_;
62 my $v = $reader->($_[0]);
64 $writer->( $_[0], $v);
69 my ($attr, $reader, $writer ) = @_;
70 return sub { $writer->( $_[0], '' ) }
83 MooseX::AttributeHelpers::MethodProvider::String
87 This is a role which provides the method generators for
88 L<MooseX::AttributeHelpers::String>.
90 =head1 PROVIDED METHODS
92 It should be noted that all methods modify attribute values in place.
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.
102 =item I<append> C<$string>
104 Append a string, like C<.=>.
106 =item I<prepend> C<$string>
110 =item I<replace> C<$pattern> C<$replacement>
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
117 =item I<match> C<$pattern>
119 Like I<replace> but without the replacement. Provided mostly for completeness.
131 Sets the string to the empty string (not the value passed to C<default>).
137 All complex software has bugs lurking in it, and this module is no
138 exception. If you find a bug please either email me, or add the bug
143 Stevan Little E<lt>stevan@iinteractive.comE<gt>
145 =head1 COPYRIGHT AND LICENSE
147 Copyright 2007-2008 by Infinity Interactive, Inc.
149 L<http://www.iinteractive.com>
151 This library is free software; you can redistribute it and/or modify
152 it under the same terms as Perl itself.