Subject: | [PATCH] import magic for simpler command-line interface |
Here is a patch for a simplification of the command-line interface: it
not required anymore to type the package name twice.
perl -MPod::POM::Web -e server
perl -MPod::POM::Web -e server 8081
perl -MPod::POM::Web -e "server(8081, { })"
perl -MPod::POM::Web -e server 8081 --option value
The current interface is not modified.
This is implemented by importing a 'server' function in the main::
package if the module is loaded from the perl command-line. That
function parses @ARGV if no arguments are given to it.
The function is compiled only if it is used.
sub import
{
@caller = caller(0);
if ("$caller[0]/$caller[1]" eq 'main/-e') {
eval q~
*{'main::server'} = sub {
if (!@_ && @ARGV) {
# Convert @ARGV to Pod::POM::Web->server arguments
# Signature: $port, \%options
my ($port, %args) = @ARGV;
%args = map { my $a = $_; s/^--//; ($_, $args{$a}) }
keys %args;
@_ = ($port, \%args);
}
Pod::POM::Web->server(@_);
};
~;
}
}
--
Olivier Mengué - http://search.cpan.org/~dolmen/ http://github.com/dolmen/