Some Perl modules are imported with hash argument, like:
use Test::Simple tests => 1
which is not consistent with documented use
usage variants:
use Module VERSION LIST use Module VERSION use Module LIST use Module use VERSION
Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package.
while in our case, we are using hash instead of list, at least semantically - of course,
use Test::Simple qw(tests 1)
is equivalent, but makes no sense for the human outsider, who is expecting the list to be a list of names to import.
How do you explain/defend this deviation? Is it the recommended syntactic sugar to allow a module to be imported with parameters?
First, you should reread the documentation you quoted.
Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package.
It's not just for importing a list of subs.
How do you explain/defend this deviation?
You mentioned three deviations.
The belief that =>
indicates a hash.
This stems from the misconception that there's such a thing as a hash initializer. Explain that Perl doesn't have initializers, that =
denotes an ordinary assignment even when the LHS of it is %hash
or my %hash
. Hashes and arrays are types of variables, not data.
The belief that the list passed to use Test::Simple
is a list of symbols to import.
I'm not sure how that's a problem. You can refer them to Test::Simple's documentation if it is.
The belief that the list passed to use MODULE
is a list of symbols to import.
There are plenty of counter examples, including commonly used core modules strict, warnings, CGI, CGI::Carp and Test::More.
None of the deviations should be defended. These aren't useful metaphors.