in reply to Re^2: Dynamically constructed function calls
in thread Dynamically constructed function calls
That doesn't work.
It doesn't work with UNIVERSAL::can, but it could work with an overloaded can:
{ package Foo; my %meth = ( foo => sub { print "Foo?\n" }, bar => sub { print "Bar!\n" }, ); sub baz { print "Baz.\n"; } sub can { $meth{$_[1]} || __PACKAGE__->UNIVERSAL::can($_[1]) } sub AUTOLOAD { use vars '$AUTOLOAD'; (my $methname = $AUTOLOAD) =~ s/.*:://; $meth{$methname}->(@_); } } for (qw(foo bar baz qux)) { if (my $cr = Foo->can($_)) { $cr->(); } else { print "Cannot $_\n"; } }
|
|---|