1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
package TPrintable;
use strict;
use warnings;
our $VERSION = '0.31';
use Class::Trait 'base';
use overload (); # we need a method from overload
## overload operator
our %OVERLOADS = ( '""' => "toString" );
## requires
our @REQUIRES = qw(toString);
### methods
# return the unmolested object string
sub stringValue {
my ($self) = @_;
return overload::StrVal($self);
}
1;
__END__
=head1 NAME
TPrintable - Trait for adding stringification abilities to your object
=head1 DESCRIPTION
TPrintable gives your object automatic stringification abilities, as well as
access to your original stringified object value.
=head1 REQUIRES
=over 4
=item B<toString>
This method should return the stringified object.
=back
=head1 OVERLOADS
=over 4
=item B<"">
This operator call the C<toString> method to stringify the object.
=back
=head1 PROVIDES
=over 4
=item B<stringValue>
This returns the normal perl stringified value, bypassing whatever C<toString>
might return.
=back
=head1 AUTHOR
Stevan Little E<lt>stevan@iinteractive.comE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2004, 2005 by Infinity Interactive, Inc.
L<http://www.iinteractive.com>
This library is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
=cut
|