package Data::Perl::String; { $Data::Perl::String::VERSION = '0.001000'; } # ABSTRACT: Wrapping class for Perl scalar strings. use strictures 1; sub new { my $cl = shift; bless(\$_[0], $cl) } sub inc { ${$_[0]}++ } sub append { ${$_[0]} = ${$_[0]} . $_[1] } sub prepend { ${$_[0]} = $_[1] . ${$_[0]} } sub replace { if (ref($_[2]) eq 'CODE') { ${$_[0]} =~ s/$_[1]/$_[2]->()/e; } else { ${$_[0]} =~ s/$_[1]/$_[2]/; } } sub match { ${$_[0]} =~ /$_[1]/; } sub chop { CORE::chop ${$_[0]} } sub chomp { CORE::chomp ${$_[0]} } sub clear { ${$_[0]} = '' } sub length { CORE::length ${$_[0]} } sub substr { ... } 1; =pod =head1 NAME Data::Perl::String - Wrapping class for Perl scalar strings. =head1 VERSION version 0.001000 =head1 SYNOPSIS use Data::Perl qw/string/; my $string = string("foo\n"); $string->chomp; # returns 1, $string == "foo" =head1 DESCRIPTION This class provides a wrapper and methods for interacting with scalar strings. =head1 PROVIDED METHODS =over 4 =item B Constructs a new Data::Perl::String object, optionally initialized to $value if passed in, and returns it. =item * B Increments the value stored in this slot using the magical string autoincrement operator. Note that Perl doesn't provide analogous behavior in C<-->, so C is not available. This method returns the new value. This method does not accept any arguments. =item * B Appends to the string, like C<.=>, and returns the new value. This method requires a single argument. =item * B Prepends to the string and returns the new value. This method requires a single argument. =item * B Performs a regexp substitution (L). There is no way to provide the C flag, but code references will be accepted for the replacement, causing the regex to be modified with a single C. C can be applied using the C operator. This method returns the new value. This method requires two arguments. =item * B Runs the regex against the string and returns the matching value(s). This method requires a single argument. =item * B Just like L. This method returns the chopped character. This method does not accept any arguments. =item * B Just like L. This method returns the number of characters removed. This method does not accept any arguments. =item * B Sets the string to the empty string (not the value passed to C). This method does not have a defined return value. This method does not accept any arguments. =item * B Just like L, returns the length of the string. =item * B This acts just like L. When called as a writer, it returns the substring that was replaced, just like the Perl builtin. This method requires at least one argument, and accepts no more than three. =back =head1 SEE ALSO =over 4 =item * L =item * L =back =head1 AUTHOR Matthew Phillips =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2013 by Matthew Phillips . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut __END__ ==pod