NAME

ASCOPE::Class::Text - Aaron's class thingy for text widgets.


SYNOPSIS

 my $text = ASCOPE::Class::Text->new("hello world");
 print $text;
 # prints "hello world"


DESCRIPTION

Aaron's class thingy for text widgets.

Overloads the object's ``'' operator to return the value of the text passed to the object constructor.


ARE YOU SMOKING CRACK, OR SOMETHING?

You might think so.

But something like this comes in handy when you're working with something like Class::DBI's inflate mechanism and want to call a function on the string value of a column/field.

This will fail because Class::DBI/Class::Trigger are expecting an object:

 __PACKAGE__->has_a("ooka_ooka"=>"Spork",
                    "inflate"  => sub { 
                       Spork::foobar($_[0]);
                    });
 # This will cause a fatal error which is pretty
 # annoying but that's another story...

I don't want an object, I just want to automagically ``spork'' the field before returning it to the user.

But if the return value (a scalar) is blessed and it's ``'' operator is overloaded then you can keep the OOP-lords happy and continue to print the return value and get on with it:

 use ASCOPE::Class::Text;
 __PACKAGE__->has_a("ooka_ooka"=>"Spork",
                    "inflate"  => sub {
                        ASCOPE::Class::Text->new(Spork::foobar($_[0])); 
                    });

This, and the other Text::* packages can be handy when you're building a datastructure and want to output as XML at some later date.

A simple example, in a SAX context :

 my @stuff = (
              ASCOPE::Class::Text->new("And then I said"),
              ASCOPE::Class::Text::CDATA->new("<strong>ook ook ook</strong>"),
              ASCOPE::Class::Text->new("& everyone laughed."),
              );
 foreach (@stuff) {
   my $ima = ref($_);
   if ($ima =~ /CDATA$/) {
      $self->SUPER::start_cdata();
      $self->SUPER::characters({Data=>$_});
      $self->SUPER::end_cdata();
   }
   # other conditions, if any...
   else {
      $self->SUPER::characters({Data=>$_});
   }
 }
 # prints:
 # And then I said <![CDATA[<strong>ook ook ook</strong>]]> &amp; everyone laughed.

This is not a silver bullet. You still have check the type of the object. But it is atleast easier, and cleaner, than generating some kind of heinous monster hash for storin meta-data about your data.


PACKAGE METHODS

__PACKAGE__->new($text)

Returns an object. Woot!


OBJECT METHODS

$obj->raw()

Get the raw text passed to the object constructor.

It is not expected that you will have much use for this method. It is used mostly by packages that inherit from ASCOPE::Class::Text.

Returns a string.


VERSION

1.0


DATE

$Date: 2003/03/12 02:33:30 $


AUTHOR

Aaron Straup Cope


SEE ALSO

the ASCOPE::Class::Text::Collection manpage


LICENSE

Copyright (c) 2003, Aaron Straup Cope. All Rights Reserved.

This is free software, you may use it and distribute it under the same terms as Perl itself.