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;
In reply to Re: Can I add methods to an existing object?
by morgon
in thread Can I add methods to an existing object?
by pileofrogs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |