in reply to Re: searching for an object reference
in thread searching for an object reference
If you run this, you'll see the following output:package Log; sub new { my ($class) = shift; bless {}, $class; } sub write { print "write old\n"; } sub open { print "open old\n"; } sub close { print "close old\n"; } 1; package NewLog; sub import { for my $sub (qw(new write open)) { no strict 'refs'; *{'Log::'.$sub} = *{'NewLog::'.$sub}; } } sub new { my ($class) = shift; bless {}, $class; } sub write { print "write new\n"; } sub open { print "open new\n"; } 1; use Log; use NewLog; my $log = new Log; $log->open; $log->write; $log->close;
Note that open and write are overridden, and close is not. This incurs less overhead if you've got a lot of Log objects, or if your objects using them are very deeply nested.open new write new close old
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: searching for an object reference
by Mostly Harmless (Initiate) on Jul 06, 2005 at 07:38 UTC |