more useful options | |
PerlMonks |
Conditional loading of methodsby bruno (Friar) |
on Dec 09, 2008 at 04:18 UTC ( [id://729074]=perlquestion: print w/replies, xml ) | Need Help?? |
bruno has asked for the wisdom of the Perl Monks concerning the following question:
Oh monks, Here's the issue. I need to load a method conditionally, the condition being that a certain module Foo::Bar is usable. So after asking in the chatterbox, the following snippet arose:
So far so good. It worked for a trivial test subroutine, but not for my real-life example. The thing is, Foo::Bar = PDL. And PDL adds a lot of new syntax. Now, the eval expression is being executed at runtime, but the my_method block has its syntax checked at compile time. So by the time that the syntax of the my_method is checked, PDL hasn't been loaded yet, and the module gives a syntax fatal error when the sub tries to
which is perfectly legal if PDL is loaded. Also, I can't use eval { use Foo::Bar }, because it dies on me if Foo::Bar isn't present. I might be missing something here, but I surely don't know how to solve this. I would really appreciate some enlightenment!
Back to
Seekers of Perl Wisdom
|
|