bump version to 0.22
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / MethodProvider / String.pm
index 4e4ee82..028c3b1 100644 (file)
@@ -2,10 +2,11 @@
 package MooseX::AttributeHelpers::MethodProvider::String;
 use Moose::Role;
 
-our $VERSION   = '0.01';
+our $VERSION   = '0.22';
+$VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
-sub append : method { 
+sub append : method {
     my ($attr, $reader, $writer) = @_;
 
     return sub { $writer->( $_[0],  $reader->($_[0]) . $_[1] ) };
@@ -67,10 +68,41 @@ sub inc : method {
 }
 
 sub clear : method {
-    my ($attr, $reader, $writer ) = @_;
+    my ($attr, $reader, $writer) = @_;
     return sub { $writer->( $_[0], '' ) }
 }
 
+sub length : method {
+    my ($attr, $reader, $writer) = @_;
+    return sub {
+        my $v = $reader->($_[0]);
+        return CORE::length($v);
+    };
+}
+
+sub substr : method {
+    my ($attr, $reader, $writer) = @_;
+    return sub {
+        my $self = shift;
+        my $v = $reader->($self);
+
+        my $offset      = defined $_[0] ? shift : 0;
+        my $length      = defined $_[0] ? shift : CORE::length($v);
+        my $replacement = defined $_[0] ? shift : undef;
+
+        my $ret;
+        if (defined $replacement) {
+            $ret = CORE::substr($v, $offset, $length, $replacement);
+            $writer->($self, $v);
+        }
+        else {
+            $ret = CORE::substr($v, $offset, $length);
+        }
+
+        return $ret;
+    };
+}
+
 1;
 
 __END__
@@ -80,10 +112,10 @@ __END__
 =head1 NAME
 
 MooseX::AttributeHelpers::MethodProvider::String
-  
+
 =head1 DESCRIPTION
 
-This is a role which provides the method generators for 
+This is a role which provides the method generators for
 L<MooseX::AttributeHelpers::String>.
 
 =head1 METHODS
@@ -114,11 +146,15 @@ L<MooseX::AttributeHelpers::String>.
 
 =item B<clear>
 
+=item B<length>
+
+=item B<substr>
+
 =back
 
 =head1 BUGS
 
-All complex software has bugs lurking in it, and this module is no 
+All complex software has bugs lurking in it, and this module is no
 exception. If you find a bug please either email me, or add the bug
 to cpan-RT.
 
@@ -128,7 +164,7 @@ Stevan Little E<lt>stevan@iinteractive.comE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2007-2008 by Infinity Interactive, Inc.
+Copyright 2007-2009 by Infinity Interactive, Inc.
 
 L<http://www.iinteractive.com>