First, I thought of something like this:
*Log::Dispatch::warn = *Log::Dispatch::warning;But I thought, that it doesn't look nice ;) so I changed it to:
*Log::Dispatch::warn = \&Log::Dispatch::warning;But both threw warnings that Log::Dispatch::warn is "used only once: possible typo..."; And then, based upon the answers from morgon and mr_mischief I thought of
sub Log::Dispatch::warn { my $self = shift; $self->warning(@_); }
tested with:
#!/usr/bin/perl -l use strict; use warnings; package foo; sub new { bless {}, shift(); } sub foo { my $self = shift; print "hello @_"; } package main; sub foo::bar { my ( $self ) = shift; $self->foo(@_); } *foo::baz = \&foo::foo; *foo::buzz = *foo::foo; my $o = foo->new(); $o->bar('world'); $o->baz('world'); $o->buzz('world'); __END__
In reply to Re^3: Can I add methods to an existing object?
by linuxer
in thread Can I add methods to an existing object?
by pileofrogs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |