tobyink / p5-moops

16 stars 4 forks source link

Implement MooseX::App::Cmd command using Moops #20

Open tobyink opened 3 years ago

tobyink commented 3 years ago

Migrated from rt.cpan.org #92676 (status was 'stalled')

Requestors:

Attachments:

From sven.schober@uni-ulm.de on 2014-02-03 12:10:27 :

Hi!

I am trying to implement a MooseX::App::Cmd command using Moops. As long as I keep the code in a single file everything works nicely:

 #!/usr/bin/env perl

 package myapp::Command;
 use Moops;

 class cmd1
 extends MooseX::App::Cmd::Command
 using Moose {
   method description { return "cmd1"; };
   method execute( $opt, $args) {
     print "Hello World\n";
   };
 }

 package main;
 use Moops;
 class myapp extends MooseX::App::Cmd using Moose;

 use Modern::Perl;
 use myapp;
 myapp->run;

But as soon as I move the definition of cmd1 to a file myapp/Command/cmd1.pm perl complains about the module not returning a true value:

 $ perl mycmd
 myapp/Command/cmd1.pm did not return a true value at 

/usr/share/perl5/site_perl/App/Cmd.pm line 203.

The documentation explicitly states the 1; is not needed.

Using true won't help either...

App::Cmd uses Class::Load::load_class() to load the command classes, so maybe there's a problem there?

My Environment:

perl: 5.18.2 Moops: 0.030 MooseX::App::Cmd: 0.27

$ uname -a Linux ylo 3.12.5-1-ARCH #1 SMP PREEMPT Thu Dec 12 12:57:31 CET 2013 x86_64 GNU/Linux

Cheers Sven

-- Dipl.-Inf. Sven Schober Universität Ulm kiz - Abteilung Infrastruktur 89069 Ulm Tel.: +49 731 50 22484

tobyink commented 3 years ago

From perl@toby.ink on 2014-02-03 21:18:52 :

What are the exact contents of myapp/Command/cmd1.pm?

tobyink commented 3 years ago

From sven.schober@uni-ulm.de on 2014-02-04 07:56:54 :

On 03.02.2014 22:18, Toby Inkster via RT wrote:

<URL: https://rt.cpan.org/Ticket/Display.html?id=92676 >

What are the exact contents of myapp/Command/cmd1.pm?

I've attached the file to this message.

Adding a 1; at the end will resolve the issue, but that contradicts the documentation.

tobyink commented 3 years ago

From perl@toby.ink on 2014-08-30 09:51:13 :

I've just checked in a test case that the use true aspect of Moops is working OK, and it seems to pass fine:

https://github.com/tobyink/p5-moops/commit/dd1348278706d032bb649bb73903abdc2b996283

tobyink commented 3 years ago

From perl@toby.ink on 2014-08-30 10:03:35 :

Aha! Confirmed. Your package does indeed not return a true value.

Adding "1;" to the end allows it to load.

Curiously, adding "0;" to the end also allows it to load.

Adding any statement (whether it evaluates to true or false) after the class declaration allows it to load.

It's possible that Moops' parsing magic interferes with whatever magic true.pm uses.

tobyink commented 3 years ago

From perl@toby.ink on 2014-08-30 10:30:56 :

More complex tests, still passing:

https://github.com/tobyink/p5-moops/commit/db6505357d5483381c59bd9c0e8dff14c41fb043

It must be some kind of weird interaction with Class::Load.

tobyink commented 3 years ago

From perl@toby.ink on 2014-08-30 10:39:31 :

It must be some kind of weird interaction with Class::Load

Here's some further evidence pointing in that direction... preloading myapp::Command::cmd1 before Class::Load and App::Cmd have sprung into action, allows things to start working.

$ cat lib/myapp/Command/cmd1.pm package myapp::Command; use Moops;

 class cmd1
 extends MooseX::App::Cmd::Command
 using Moose {
   method description { return "cmd1"; };
   method execute( $opt, $args) {
     print "Hello World\n";
   };
 }

$ cat mycmd package main; use Moops; class myapp extends MooseX::App::Cmd using Moose;

 use Modern::Perl;
 use myapp;
 myapp->run;

$ perl -Ilib mycmd myapp/Command/cmd1.pm did not return a true value at /home/tai/.perlbrew/libs/perl-5.20.0@default/lib/perl5/App/Cmd.pm line 203. $ perl -Ilib -mmyapp::Command::cmd1 mycmd Available commands:

commands: list the application's commands help: display a command's help screen

  cmd1: (unknown)
tobyink commented 3 years ago

From perl@toby.ink on 2014-08-30 10:42:25 :

I'm marking this issue as stalled because I don't completely understand what's causing it, and it's difficult to produce a small test case reproducing it without pulling in all of App::Cmd.

Unless somebody can figure out exactly what's going on, I don't think there's much I can do other than document the issue. A revamp of the Moops documentation is planned at some point in the future, so it may happen then.