in reply to 'use' inside or outside of package declaration?
I would think that if the package line itself used syntax that did not work in older perls, then the use or feature would certainly have to come first!That’s an interesting point. As of 5.14, you can do this:
package NAMESPACE VERSION;That sets the appropriate version number in that namespace, at compile time, and in a declarative fashion so that the toolchain doesn’t have to run (or simulate running) the code just to ascertain the package’s version number. It is also superior in that it puts the version number right at the top where it belongs, guaranteeing that it won’t drift down in the module as time goes by, as so often seems to occur.
And that’s not all. You can also do this:
package NAMESPACE BLOCKTo create a lexical scope smaller than that of the rest of the file scope for the package declaration to govern. And of course you may combine these:
package NAMESPACE VERSION BLOCKIf you’re going to do this, it does make some sense to put a use 5.014 before that in your code. With all the myriad differences in Perl that have come about in the 5.10, 5.12, and 5.14 releases, I’ve for some time now taken to prominently placing a use 5.012 (or whatever) as the first thing in the file. It’s a way of declaring the version of Perl that I developed and tested the code under, and an indication that I have no intention of backporting and testing and maintaining it on Perls older than that.
|
|---|