BerntB has asked for the wisdom of the Perl Monks concerning the following question:
I have some persistent objects dumped into a database. To make certain that the object's package is loaded when reading in the object, I use this:
This works but I wonder about efficiency. Two questions:return if $class->can('new'); eval "use $class"; croak("Err etc") if $@;
- Is can() effective? It is run every time I reload an object.
- Can I load without doing eval of a string? (Not that important, since it is only run once/package.)
I found an alternative to can a while ago by searching the usual suspects (Google, my books, monks). To see if the package is loaded, check for a package's symbol table:
return if defined %{$class . "::"};
This symbol table test didn't work consistently for me? Should it -- did I do something wrong?
Yes, I am optimizing the wrong details. I haven't kludged around with the symbol tables much and is fishing a bit for discussion and pointers. :)
Maybe I should just get some more books, but I am looking for work right now. :-)
Back to
Seekers of Perl Wisdom