Re: popt in Gnome2::Program



* Peter Oliver <p d oliver mavit freeserve co uk> [2004-09-15 10:35]:
So, is there neat solution to this?

    if ( grep { s/^-h$/--help/; m/^-(-help|\?)$/ } @ARGV ) {
        system $0, '--podhelp';
    }

That does a lot of superfluous work. You could use something like

    @ARGV = map { /^-(?:h|-help)$/ ? "--podhelp" : $_ } @ARGV;

or even simply

    @ARGV = qw( --podhelp ) if grep /^-(?:h|-help)$/, @ARGV;

Of course, you could also just do

    pod2usage( -verbose => 1 ) if grep /^-(?:h|-help)$/, @ARGV;

But none of these solutions will respect a -- terminator and will
not misrecognize a -h or --help passed as the value of an option.
To handle all edge cases correctly you can do

    Getopt::Long;:Configure( qw( pass_through ) );
    GetOptions( help => sub { pod2usage( -verbose => 1 ); } );
    Getopt::Long;:Configure( qw( no_pass_through ) );

Regards,
-- 
Aristotle
"If you can't laugh at yourself, you don't take life seriously enough."



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]