NAME
Acme::RightSideOutObject - Turn Class::InsideOut objects back right side out
SYNOPSIS
use Acme::RightSideOutObject;
use My::Class;
# My::Class comes from the L<Class::InsideOut> SYNOPSIS
my $inside_out = My::Class->new or die;
$inside_out->name("Fred");
print $inside_out->greeting(), "\n"; # prints Hello, my name is Fred
my $rightside_out = guts($inside_out);
print '$rightside_out->{name} = ', $rightside_out->{name}, "\n"; # direct hash read
$rightside_out->{name} = 'Dork Face'; # direct hash write
print $inside_out->greeting(), "\n"; # prints Hello, my name is Dork Face
print $rightside_out->greeting(), "\n"; # prints Hello, my name is Dork Face
DESCRIPTION
Exports guts()
which takes a Class::InsideOut object and returns a normal blessed hashref object.
One of the most serious flaws of Class::InsideOut is that it encapsulates data, making it difficult to directly minipulate the object's internal state. Attempting to inspect the reference to an inside out object with Data::Dumper, you'll find this:
$VAR1 = bless( do{\(my $o = undef)}, 'My::Class' );
Fear not! Acme::RightSideOutObject to the rescue!
Acme::RightSideOutObject work exactly like the inside out object it replaces except that it is also a hashref full of the object's instance data. Methods may be called on it.
Options are available, mix and match style:
use Acme::RightSideOutObject 'weaken';
Attempt not to leak so much memory.
use Acme::RightSideOutObject 'debug';
Print information to STDERR about instance data found while righting objects.
EXPORT
guts()
HISTORY
- 0.01
-
Original version; created by h2xs 1.23 with options
-A -C -X -b 5.8.0 -c -n Acme::RightSideOutObject
BUGS
Leaks memory.
Can't subclass inside out objects with right side out code (but obviously has-a style delegation works).
Should support other flavors of inside out objects than just Class::InsideOut.
Doesn't use the exporter.
The inside out object and the per-attribute hashes continue to exist; this only creates a fascade. With some B hackery, we could actually rewrite the code of inside out objects to be right side out and utter destroy the previous inside out-edness.
SEE ALSO
AUTHOR
Scott Walters, <scott@slowass.net>, at the suggestion of Jonathan Rockway, <jrockway@cpan.org>. The real magic is done by Data::Alias.
COPYRIGHT AND LICENSE
Copyright (C) 2009 by Scott Walters
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.9 or, at your option, any later version of Perl 5 you may have available.