in reply to Can I add methods to an existing object?
Here an example that adds a new "bubba" method to a "Hubba"-class after an instance already has been created:
use strict;
package Hubba;
sub new {
my($pck)=@_;
bless {}, $pck;
}
# no bubba-method defined here
package main;
# create new instance
my $h = new Hubba;
# add entry to symbol-table
*Hubba::bubba = sub { print "bubba" };
# call new method via old instance
$h->bubba;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can I add methods to an existing object?
by mr_mischief (Monsignor) on Apr 02, 2009 at 21:12 UTC | |
by morgon (Priest) on Apr 03, 2009 at 11:47 UTC | |
by mr_mischief (Monsignor) on Apr 03, 2009 at 14:14 UTC |