App-Cmd icon indicating copy to clipboard operation
App-Cmd copied to clipboard

Usage is lost if a command uses Moose

Open schwern opened this issue 10 years ago • 2 comments

If a command class uses Moose (or Mouse) the "Usage" output will be lost. Even with "no Moose".

$ perl -Ilib bin/test foo
Error: This will never work
Usage:  at /Users/schwern/perl5/perlbrew/perls/perl-5.18.1-thread/lib/site_perl/5.18.1/App/Cmd/Command.pm line 90.

See https://gist.github.com/schwern/10081851 for test code.

schwern avatar Apr 08 '14 01:04 schwern

The gist, here for posterity:

#!/usr/bin/perl
{
  package App::Cmd::Bug;
  use App::Cmd::Setup -app;
  BEGIN { $INC{"App/Cmd/Bug.pm"} = 1; }
}

{
  package App::Cmd::Bug::Command::foo;

  # Using Moose causes the usage description to break.
  use Moose;
  no Moose;

  use App::Cmd::Bug -command;

  sub validate_args {
    my $self = shift;
    $self->usage_error("This will never work");
    return;
  }
}

use App::Cmd::Bug;
App::Cmd::Bug->run;

rjbs avatar Sep 26 '14 01:09 rjbs

Using Moose gets Moose::Object into @INC before App::Command::Command, which is put there by use App::Cmd::Bug -command, so the "wrong" new run. The only likely solution, here, is documentation.

rjbs avatar Sep 26 '14 01:09 rjbs