Skip to content

Commit

Permalink
more defensive regular expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 7, 2014
1 parent 7357d14 commit 04470cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Home.pm
Expand Up @@ -21,7 +21,7 @@ sub detect {
if (my $class = @_ ? shift : 'Mojo::HelloWorld') {
my $file = class_to_path $class;
if (my $path = $INC{$file}) {
$path =~ s/$file$//;
$path =~ s/\Q$file\E$//;
my @home = splitdir $path;

# Remove "lib" and "blib"
Expand Down
14 changes: 6 additions & 8 deletions lib/Mojolicious/Commands.pm
Expand Up @@ -68,21 +68,19 @@ sub run {
return 1 if $ENV{HARNESS_ACTIVE};

# Find all available commands
my (@commands, %seen);
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 =~ s/^${ns}:://;
push @commands, [$command => $module] unless $seen{$command}++;
$command =~ s/^\Q$ns\E:://;
next if $seen{$command}++;
push @rows, [" $command", $module->new->description];
}
}
@rows = sort { $a->[0] cmp $b->[0] } @rows;

# Print list of all available commands
my $rows = [];
push @$rows, [' ' . $_->[0], $_->[1]->new->description]
for sort { $a->[0] cmp $b->[0] } @commands;
return print $self->message, tablify($rows), $self->hint;
print $self->message, tablify(\@rows), $self->hint;
}

sub start_app {
Expand Down

0 comments on commit 04470cf

Please sign in to comment.