Acme-RightSideOutObject
view release on metacpan or search on metacpan
abstract: Turn Class::InsideOut objects back right side out
author:
- Scott Walters <knoppix@lightandslowass.net>
license: unknown
distribution_type: module
configure_requires:
ExtUtils::MakeMaker: 0
requires:
Class::InsideOut: 0.1
Data::Alias: 0.1
PadWalker: 0.1
no_index:
directory:
- t
- inc
generated_by: ExtUtils::MakeMaker version 6.48
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
Makefile.PL view on Meta::CPAN
use 5.008000;
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
NAME => 'Acme::RightSideOutObject',
VERSION_FROM => 'lib/Acme/RightSideOutObject.pm', # finds $VERSION
PREREQ_PM => { 'Class::InsideOut' => 0.1, PadWalker => 0.1, 'Data::Alias' => 0.1, }, # e.g., Module::Name => 1.1
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'lib/Acme/RightSideOutObject.pm', # retrieve abstract from module
AUTHOR => 'Scott Walters <knoppix@lightandslowass.net>') : ()),
);
lib/Acme/RightSideOutObject.pm view on Meta::CPAN
our $VERSION = '0.01';
# todo:
# o. recognize different inside-out object systems and handle them appropriately (eg, C::IO uses id($self) for a hash subscript)
# o. weaken?
use strict; no strict 'refs';
use warnings;
use Data::Alias;
use PadWalker;
use B;
use Scalar::Util;
sub import {
*{caller().'::guts'} = sub {
my $their_self = shift;
my $weaken = grep $_ eq 'weaken', @_;
my $debug = grep $_ eq 'debug', @_;
my $id = Class::InsideOut::id($their_self) or die;
my $class = ref $their_self;
my %as_a_hash;
my $self = bless \%as_a_hash, $class;
my $our_id = Class::InsideOut::id($self) or die; # sooo bad
for my $sym (keys %{$class.'::'}) {
$debug and warn "$class\::$sym\n";
my $code = *{$class.'::'.$sym}{CODE} or next;
my $op = B::svref_2object($code) or next;
my $rootop = $op->ROOT or next;
$$rootop or next; # not XS
$op->STASH->NAME eq $class or next; # not imported
my $vars = PadWalker::peek_sub($code) or next; # don't know why this would fail but when it does, I think it dies
for my $var (keys %$vars) {
next unless $var =~ m/^\%/;
next unless exists $vars->{$var};
next unless exists $vars->{$var}->{$id};
$debug and warn " ... $var is $vars->{$var}->{$id}\n";
(my $var_without_sigil) = $var =~ m/^.(.*)/;
alias $as_a_hash{$var_without_sigil} = $vars->{$var}->{$id};
alias $vars->{$var}->{$our_id} = $vars->{$var}->{$id}; # so $self->func works as well as $their_self->func
if($weaken) {
Scalar::Util::weaken($as_a_hash{$var_without_sigil});
( run in 0.558 second using v1.01-cache-2.11-cpan-05444aca049 )