in reply to Re^2: Using AUTOLOAD to create class methods
in thread Using AUTOLOAD to create class methods
There's no way you can do it perfectly reliably without AUTOLOAD because of Perl's poor introspection. And, as you note, if you miss a method you have a bug. You can either publish which methods you support (thus turning the bug into a "feature") or have your AUTOLOAD handle it. You might want to just check can (which returns a code ref). The following untested bit might help:
if (my $sub = $self->{DBI}->can($op)) { no strict 'refs'; *$op = $sub; }
You'd have to customize that for your needs, but it has the benefit of installing the subroutine directly into your namespace so you only take the AUTOLOAD hit on the first call.
Cheers,
Ovid
New address of my CGI Course.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Using AUTOLOAD to create class methods
by diotalevi (Canon) on Nov 03, 2005 at 23:40 UTC | |
by Ovid (Cardinal) on Nov 04, 2005 at 05:37 UTC | |
by tilly (Archbishop) on Nov 04, 2005 at 06:38 UTC | |
by ikegami (Patriarch) on Nov 15, 2005 at 17:34 UTC | |
by tilly (Archbishop) on Nov 16, 2005 at 04:51 UTC |