The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

String::Object - A String Object

SYNOPSIS

 my $str0 = String::Object->new('Cheese');
 $str0->{foo} = 'bar';              # Decorate!
 $str0 eq 'Cheese';                 # string operators overloaded

 my $str1 = String::Object->new('Mouse');
 $str1->pluralize;                  # 'Mice'
 $str1->pluralize eq 'Mice';        # TRUE
 
 my $str2 = String::Object->new('my_string');
 $str2->humanize;                   # 'My string'
 $str2->length;                     # 8
 
 my $str3 = String::Object->new('My string');
 $str3->computerize;                # 'my_string'
 $str3->as_namespace;               # 'My::String'
 
 # can be chained:
 $str->humanize->length;
  
 # comparison operators as methods
 $str->eq('equal');
 $str->ne('not equal');
 $str->gt('greater');
 $str->ge('greater or equal');
 $str->lt('less');
 $str->le('less or equal');
 $str->cmp('compares');
 
 # additional methods
 $str->chomp;                       # in place!
 $str->copy;                        # new String::Object
 $str->concat ( $other );           # new String::Object same as `.'
 $str->cassign( $other );           # new String::Object same as `.='
 $str->assign ( $other );           # same as `=' ( but see Assignment GOTCHA ) 

DESCRIPTION

This module implements very simple Strings-as-Objects, as seen in languages such as Ruby or JavaScript. The main reason for creating is was the need for strings which behaved as objects which could be decorated. As such instances are simply blessed Hash references which use overload heavily and implement an OO interface.

Added to this are a few methods for manipulating the string value for inflection (assuming the string is English), and a few simple transformations for camelizing, concatenating with underscore `_' and creating Perl namespaces.

METHODS

See SYNOPSIS.

Assignment GOTCHA

Assignment overloading may not do what you expect. In particular, you cannot assign a literal string to a String::Object instance. The following DOES NOT WORK:

 my $str = String::Object->new('Foo');
 $str = 'Bar';      # $str is now the literal 'Bar' and not a String::Object instance

However, either of these will work:

 my $str = String::Object->new('Foo');
 $str->assign( 'Bar' );
 
 # OR the more verbose:
 my $str = String::Object->new('Foo');
 $str = String::Object->new('Bar');

However, the `.=' operator does what you'd expect.

AUTHOR

Richard Hundt

LICENSE

This library is free software and may be used under the same terms as Perl itself.