Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: find module name from the module archive (in @INC) (updated)by LanX (Saint) |
on Dec 09, 2016 at 19:04 UTC ( [id://1177558]=note: print w/replies, xml ) | Need Help?? |
hmm just a quick remark: Calling use will also execute the import function which might do unexpected things. You might prefer require (or even do ) which are just part of use. (mnemonic use > require > do > eval with > read as "extends") Furthermore you should probably check the error code to avoid false negatives. There are many reasons why a code execution might fail. Saying so, a function to check @INC without eval-ing the located code would be safer°. (especially if you don't want to activate the whole dependency chain with consecutive use calls)
Cheers Rolf
update°) The page for require has sample code showing how @INC is searched, just skip the part after do($realfilename); to avoid compilation and add the logic for ref($prefix) if needed. (alternatively see also these modules)
You might want to use this as a first step and doing your eval only if it's not found in a second step (in order to play safe). Like this you will only execute module code if the parsing mechanism fails (which shouldn't be ever the case and deserves a warning)
NB: This approach answers the question "Can a module be found in @INC" which is slightly different to "Is a
In Section
Seekers of Perl Wisdom
|
|