in reply to Re: object swizzling?
in thread object swizzling?

I guess that will work. I just have to make sure that my proxy is of the same underlying type (HASH, ARRAY, SCALAR) as the real object.
Of course if you want a proxy that just "intercepts" some method calls and forwards most of the rest, you could just inherit from the class you're trying to proxy.

In the lazy-load case I want to ensure that the real object is loaded before forwarding, so it's not that simple.

Replies are listed 'Best First'.
Re^3: object swizzling?
by Anonymous Monk on May 06, 2009 at 12:54 UTC
    In the lazy-load case I want to ensure that the real object is loaded before forwarding, so it's not that simple.
    You can call the super class's constructor first:
    package 'Bar'; use base 'Foo'; sub new { my $class = shift; my $parent_class_object = SUPER->new(); ... }
    And then store it, or use it, or rebless it, or whatever.