perl5
perl5 copied to clipboard
[feature] `use` directive taking inline block (syntax)
it's possible to load a module per use keyword:
use namespace::module qw(symbol1 symbol2);
but not multiple modules at once (cf. import in go):
use
{
namespace::module1 => qw(symbol1 symbol2), # import list (qv. @EXPORT_OK as used by Exporter)
namespace::module2 => qw(), # no imports (requiring package specification)
namespace::module3 => undef(), # default symbols (qv. @EXPORT as used by Exporter)
}
it would be nice and neat to organize related modules (including pragmas) together using just one keyword as with the constant pragma optionally taking a block to define constants:
use constant {
SEC => 0,
MIN => 1,
HOUR => 2,
MDAY => 3,
MON => 4,
YEAR => 5,
WDAY => 6,
YDAY => 7,
ISDST => 8,
};
i'm not sure if the implementation could be affected by compile/runtime (phase) issues (and guessing not for constant being a pragma), but i also think teaching use to take a block would make the syntax a bit better.
This doesn't sound like it enables anything that currently isn't possible, it's just new syntax for something that has always been possible.