in reply to Re: sub by reference - assigning to an object?
in thread sub by reference - assigning to an object?

What if I want to do something like:

my $common = common_class->new(); my $parser = parser_class->new(); ### this is the ugly part $parser->{ 'getDBH' } = \&$common->getDBH;

In my original code this is more like what I was attempting.

Replies are listed 'Best First'.
Re^3: sub by reference - assigning to an object?
by Arunbear (Prior) on Mar 26, 2008 at 17:23 UTC
    If getDBH() doesn't actually depend on $common and it's state you could do
    $parser->{ 'getDBH' } = \&common_class::getDBH;
    otherwise you could store a wrapper to the getDBH() invocation:
    $parser->{ 'getDBH' } = sub { $common->getDBH; };