Posted by Frank Hale on 1999-11-21
How do you go about executing a reference to a method?
I mean I have coded a small module which uses a
callback. I want it to execute the callback method but
I cannot figure out how to call the reference to a
method so the callback gets executed.
Say I have the following code:
# Junk module
package Junk;
use strict;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
# All the configuration stuff
$self->{-callback} = '';
bless ($self, $class);
return $self;
}
sub justdoit {
my $self = shift;
sub { $self->{-callback} };
}
1;
# end Junk module
-- Here is the perl code which uses the module
#!/usr/bin/perl -w
use strict;
use Junk;
my $t = Junk->new( -callback => sub { print "hi" } );
$t->justdoit();
Thanks!
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com
Previous post | Next post | Timeline | Home