in reply to Passing a reference to a subroutine in a constructor
After making '/' a '\', it works for me:
my $collection = Collection->new({ 'sorter' => Sort::mysorter }); $collection->doit; package Collection; sub new { my ($class, $options) = @_; $self->{sorter} = \&{$options->{sorter}}; bless {}, $class; } sub doit { print "iam doit\n"; $self->{sorter}->($mystuffToSort); } package Sort; sub mysorter { print "iam mysorter\n"; }
On the other hand, I'm not sure what you meant by "out of the scope of the calling package".
All code given here is UNTESTED unless otherwise stated.
--Bob Niederman, http://bob-n.com
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Passing a reference to a subroutine in a constructor
by DrSax (Sexton) on Aug 22, 2003 at 19:09 UTC | |
by liz (Monsignor) on Aug 22, 2003 at 19:22 UTC | |
by DrSax (Sexton) on Aug 22, 2003 at 20:21 UTC | |
by liz (Monsignor) on Aug 22, 2003 at 20:39 UTC |