As a general rule, you should avoid AUTOLOAD like the plague. there are many problems with it (not the least of which is that eval you have going on). However, if you must use AUTOLOAD, you should consider providing a can method. If you don't, the module will lie when asked about its capabilities.
Another way of approaching your problem would be to use a delegation class (simplified for clarity).
package TestModule; require DBI; use Class::Delegator send => [qw/prepare do execute .../], to => '_dbi'; sub _dbi { shift->{DBI} } sub new { my $class = shift; return unless @_; return bless { DBI => DBI->connect(@_) }, $class; }
With this approach you get fine-grained control over the exposed interface and you don't have to wonder about whether your AUTOLOAD is exposing something it shouldn't or if your eval is secure.
Cheers,
Ovid
New address of my CGI Course.
In reply to Re: Using AUTOLOAD to create class methods
by Ovid
in thread Using AUTOLOAD to create class methods
by radiantmatrix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |