Skip to content

Commit

Permalink
remove list method again
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 19, 2015
1 parent 029a7b6 commit c42a9c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 44 deletions.
1 change: 0 additions & 1 deletion Changes
@@ -1,6 +1,5 @@

5.81 2015-02-20
- Added list method to Mojolicious::Commands.

5.80 2015-02-18
- Deprecated Mojo::IOLoop::accept_interval, Mojo::IOLoop::lock and
Expand Down
39 changes: 14 additions & 25 deletions lib/Mojolicious/Commands.pm
Expand Up @@ -24,22 +24,6 @@ sub detect {
return undef;
}

sub list {
my $self = shift;

my (@rows, %seen);
my $loader = Mojo::Loader->new;
for my $ns (@{$self->namespaces}) {
for my $module (@{$loader->search($ns)}) {
next unless my $command = _command($module);
$command = substr $command, length "${ns}::";
push @rows, [$command, $module->new->description] if !$seen{$command}++;
}
}

return [sort { $a->[0] cmp $b->[0] } @rows];
}

sub run {
my ($self, $name, @args) = @_;

Expand Down Expand Up @@ -73,9 +57,20 @@ sub run {
# Hide list for tests
return 1 if $ENV{HARNESS_ACTIVE};

# List all available commands
my @list = map { [" $_->[0]", $_->[1]] } @{$self->list};
return print $self->message, tablify(\@list), $self->hint;
# Find all available commands
my (@rows, %seen);
my $loader = Mojo::Loader->new;
for my $ns (@{$self->namespaces}) {
for my $module (@{$loader->search($ns)}) {
next unless my $command = _command($module);
$command = substr $command, length "${ns}::";
next if $seen{$command}++;
push @rows, [" $command", $module->new->description];
}
}
@rows = sort { $a->[0] cmp $b->[0] } @rows;

return print $self->message, tablify(\@rows), $self->hint;
}

sub start_app { shift; Mojo::Server->new->build_app(shift)->start(@_) }
Expand Down Expand Up @@ -307,12 +302,6 @@ implements the following new ones.
Try to detect environment or return C<undef> if none could be detected.
=head2 list
my $list = $commands->list;
List available commands in L</"namespaces">.
=head2 run
$commands->run;
Expand Down
18 changes: 0 additions & 18 deletions t/mojolicious/commands.t
Expand Up @@ -85,24 +85,6 @@ is $app->start('test_command'), 'works!', 'right result';
is $ENV{MOJO_MODE}, undef, 'no mode';
}

# List commands
is_deeply $commands->namespaces, ['Mojolicious::Command'], 'right namespaces';
my $list = [
['cgi', 'Start application with CGI'],
['cpanify', 'Upload distribution to CPAN'],
['daemon', 'Start application with HTTP and WebSocket server'],
['eval', 'Run code against application'],
['generate', 'Generate files and directories from templates'],
['get', 'Perform HTTP request'],
['inflate', 'Inflate embedded files to real files'],
['prefork', 'Start application with preforking HTTP and WebSocket server'],
['psgi', 'Start application with PSGI'],
['routes', 'Show available routes'],
['test', 'Run tests'],
['version', 'Show versions of available modules']
];
is_deeply $commands->list, $list, 'right command list';

# mojo
ok $commands->description, 'has a description';
like $commands->message, qr/COMMAND/, 'has a message';
Expand Down

0 comments on commit c42a9c9

Please sign in to comment.