nysus has asked for the wisdom of the Perl Monks concerning the following question:

I'm using the MooseX::App::Cmd::Command in one of my modules.

When I try to use the following:

with qw( MooseX::Getopt::Usage );

...I get the following error:

Attribute (usage) does not pass the type constraint because: Validatio +n failed for 'Object' with value undef at constructor DzilCommands::C +ommand::create_commands::new (defined at /Users/me/perl5/perlbrew/per +ls/perl-5.24.1/lib/site_perl/5.24.1/DzilCommands/Command/create_comma +nds.pm line 115) line 100

I can get the error to go away by adding this attribute:

has 'usage' => ( default => sub { Getopt::Long::Descriptive::U +sage->new }, is => 'ro');

...but then when I got to print help, nothing shows up. Any guidance on how to use MooseX::Getopt::Usage with MooseX::App::Cmd::Command is greatly appreciated. Thank you!

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: Using "with 'MooseX::Getopt::Usage' throwing error with MooseX::App::Cmd::Command
by choroba (Cardinal) on Feb 05, 2018 at 17:18 UTC
    I fear you didn't provide enough information.

    The following works for me:

    #!/usr/bin/perl use warnings; use strict; use feature qw{ say }; { package My; use Moose; extends 'MooseX::App::Cmd::Command'; with qw{ MooseX::Getopt::Usage }; has test => ( traits => [qw[ Getopt ]], isa => 'Bool', is => 'rw', cmd_aliases => 't', documentation => 'test me', ); sub execute { my ($self, $opt, $args) = @_; say $self->test; } __PACKAGE__->meta->make_immutable; } my $app = 'My'->new_with_options;

    When I call

    script.pl --usage

    I get the usage back. When, on the other hand, I try with

    script.pl --test

    It fails with

    Required option missing: app
    I have no idea where it's coming from, as the documentation of neither MooseX::App::Cmd::Command, MooseX::Getopt::Usage, MooseX::App::Cmd, nor App::Cmd mentions it.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      You're right. I did oversimplify. I'm using this in conjunction with MooseX::App::Cmd. So the $app never gets called with the new_with_options method. Instead, everything is handled by MooseX::App::Cmd.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks