Skip Menu |

This queue is for tickets about the Pod-POM-Web CPAN distribution.

Report information
The Basics
Id: 67588
Status: resolved
Priority: 0/
Queue: Pod-POM-Web

People
Owner: Nobody in particular
Requestors: dolmen [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



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/
I have fixed the code to make it work with strictures. It is hosted and versionned on GitHub: https://gist.github.com/944389
Le Mar 19 Avr 2011 13:15:40, DOLMEN a écrit : Show quoted text
> 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
Salut Olivier, Very nice idea; implemented in v1.16 just published to CPAN. I also generalized it to Pod::POM::Web::Indexer. Thanks for the patch; however I did not apply it, I preferred to use Getopt::Long instead. Note that the example "-e server 8081 --option value" does not work, because the option gets parsed by perl itself, instead of being passed to Pod::POM::Web; so we have to write "-e sever 8081 -- --option value" Meilleures salutations, Laurent Dami