http://qs321.pair.com?node_id=568751

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:
return if $class->can('new'); eval "use $class"; croak("Err etc") if $@;
This works but I wonder about efficiency. Two questions: It would also be nice with a more general method than demanding the existence of a method!

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. :-)