in reply to Re: Dynamically constructed function calls
in thread Dynamically constructed function calls

That doesn't work. $f->can returns a false value, and then you get the message:
Can't use string ("") as a subroutine ref while "strict refs" in use a +t autol.pl line 21.

Update:In the pod for UNIVERSAL.pm, it says:

"can" cannot know whether an object will be able to provide a method through AUTOLOAD, so a return value of undef does not necessarily mean the object will not be able to handle the method call.

Replies are listed 'Best First'.
Re^3: Dynamically constructed function calls
by revdiablo (Prior) on Nov 04, 2004 at 17:47 UTC
    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"; } }