On Jul 27, 2005, at 17:21, Jan Eden wrote:
My other problem is that the cookbook quotes (something like) the
following code as an example for storing method names:
my %actions = (
display => $item->display(),
move_picture => $item->move_picture($item->{id}, $item->
{parameters}->{position}),
commit => $item->commit()
);
Are you sure? $item->display() returns whatever the display() method
returns, which might be a coderef, but looks unlikely.
Since you can't get a reference to a method (bound to an instance) as
you do with regular subroutines, the technique normally is to wrap
them in an anonyomus closure like this:
package Foo;
sub new { bless {}, shift }
sub method { print "Moo!" }
package main;
my $foo = Foo->new;
my %actions = (foo => sub { $foo->method(@_) } );
$actions{foo}(); # prints "Moo!"
-- fxn
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>