CC: | |
Subject: | App::CLI->commands is broken for packages with :: in their name |
Date: | Tue, 03 Aug 2010 02:24:21 -0400 |
To: | bug-App-CLI [...] rt.cpan.org |
From: | "Richard Roe" <richardroe [...] excite.com> |
The commands function in App::CLI doesn't work for packages with :: in their name, which would be most real world packages, so I'm not sure how this hasn't come up before.
Your test uses MyApp so that's fine, but try copying it to MyOtherApp::Depth or something and you'll get the following:
Can't locate object method "files" via package "MyOtherApp/Depth" (perhaps you forgot to load "MyOtherApp/Depth"?) at lib/App/CLI.pm line 125.
You can see that it substituted / for :: in the $class variable and so it no longer works as a class. Here is a patch:
--- lib/App/CLI.pm 2009-02-25 14:06:16.000000000 -0700
+++ lib/App/CLI.pm 2010-08-02 23:13:34.000000000 -0600
@@ -119,8 +119,8 @@
sub commands {
my $class = shift;
- $class =~ s{::}{/}g;
- my $dir = $INC{$class.'.pm'};
+ (my $file = $class) =~ s{::}{/}g;
+ my $dir = $INC{$file.'.pm'};
$dir =~ s/\.pm$//;
return sort map { ($_) = m{^\Q$dir\E/(.*)\.pm}; lc($_) } $class->files;
}
But really you'd be better off switching to something like Module::Pluggable (part of perl core from 5.8.9) or Module::Find (this one's a little simpler for this purpose IMO) for loading the command modules.
Also, having to read the source code and look at tests to figure out how the module works should be considered a bug. Finish the documentation already, dude! LOLBCOTI