Recently I filed a bug against MooseX::Getopt while I was trying to get --help
working, but it was a bit incoherent:
https://rt.cpan.org/Ticket/Display.html?id=57683

I figured out how to get this to work by writing my own _getopt_full_usage
method (code below), but am now running into some more "interesting" behaviour
caused by the interaction of MooseX::Runnable with MooseX::Getopt and
MooseX::SimpleConfig.  Hopefully this will make sense to someone.

Let's start with a simple working module...

    package Module;

    use strict;
    use warnings;

    use Moose;
    use MooseX::ClassAttribute;

    with 'MooseX::Getopt' => { excludes => [qw(_getopt_full_usage)] };
    with 'MooseX::Runnable';
    #with 'MooseX::SimpleConfig';       # intentionally commented out for now

    has [qw(help usage)] => (
        is => 'ro', isa => 'Bool',
        documentation => 'Prints this usage documentation.',
    );

    class_has instructions => (
        is => 'ro', isa => 'Str',
        init_arg => undef,  # don't allow in constructor
        default => 'TODO: usage text'
    );

    # called when --help or --usage is used on command line
    sub _getopt_full_usage {
        my ($this, $usage) = @_;
        print $this->instructions, "\n";
        print $usage->text, "\n";
        exit;
    }

    sub run
    {
        my $this = shift;
        print "### in run, with extra args @_\n";
    }

    no Moose;
    __PACKAGE__->meta->make_immutable;
    1;

When run from the command-line in this form, the expected usage information is
printed:

$ mx-run -I. Module --help
TODO: usage text
usage: mx-run [long options...]
        --help      Prints this usage documentation.
        --usage     Prints this usage documentation.

Now, if I uncomment the usage of MooseX::SimpleConfig, I get an error from
deep within Getopt::Long (it seems to be attempting to parse some pod data,
but I can't figure out where it is trying to find it):

$ mx-run -I. Module --help
Can't open mx-run ... Module: No such file or directory at 
/usr/lib/perl5/5.8.8/Getopt/Long.pm line 1427
TODO: usage text
usage: mx-run [long options...]
        --configfile
        --help            Prints this usage documentation.
        --usage           Prints this usage documentation.

To add to the interesting behaviour, if I create a separate script to invoke
the module:

$ cat run.pl
#!/usr/bin/perl

use strict;
use warnings;

use lib '.';
use MooseX::Runnable::Run;

@ARGV = ('--help') unless @ARGV;
run_application 'Module', @ARGV;

# ./run.pl
<no output at all!>


Has anyone gotten all three of these MX modules to work together in harmony?
The examples I provided are fairly simple, but something surely must be missing.



-- 
              "When I see an adult on a bicycle, I do not despair
               for the future of the human race." - H. G. Wells
            .             .            .            .             .
Karen Etheridge, ka...@etheridge.ca       GCS C+++$ USL+++$ P+++$ w--- M++
http://etheridge.ca/                      PS++ PE-- b++ DI++++ e++ h(-)

Reply via email to