Skip to content

Commit

Permalink
improved routes command to show which routes are using certain featur…
Browse files Browse the repository at this point in the history
…es with flags
  • Loading branch information
kraih committed Feb 14, 2014
1 parent e2fe11a commit 9b8f60d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,6 +1,8 @@

4.81 2014-02-14
- Added direct array access for child nodes to Mojo::DOM.
- Improved routes command to show which routes are using certain features
with flags.

4.80 2014-02-13
- Merged Mojo::DOM::Node into Mojo::DOM.
Expand Down
11 changes: 9 additions & 2 deletions lib/Mojolicious/Command/routes.pm
Expand Up @@ -26,6 +26,14 @@ sub _walk {
if (my $i = $depth * 2) { $prefix .= ' ' x $i . '+' }
push @$rows, my $row = [$prefix . ($route->pattern->pattern || '/')];

# Flags
my @flags;
push @flags, $route->inline ? 'B' : '.';
push @flags, @{$route->over || []} ? 'C' : '.';
push @flags, (my $partial = $route->partial) ? 'D' : '.';
push @flags, $route->is_websocket ? 'W' : '.';
push @$row, join('', @flags) if $verbose;

# Methods
my $via = $route->via;
push @$row, !$via ? '*' : uc join ',', @$via;
Expand All @@ -41,8 +49,7 @@ sub _walk {
my $format = (regexp_pattern($pattern->format_regex || ''))[0];
my $optional
= !$pattern->constraints->{format} || $pattern->defaults->{format};
$regex .= $optional ? "(?:$format)?" : $format
if $format && !$route->partial;
$regex .= $optional ? "(?:$format)?" : $format if $format && !$partial;
push @$row, $regex if $verbose;

$depth++;
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -772,8 +772,8 @@ to list all available routes together with name and underlying regular
expressions.

$ ./myapp.pl routes -v
/foo/:name GET fooname ^/foo/([^/\.]+))(?:\.([^/]+)$)?
/bar POST bar ^/bar(?:\.([^/]+)$)?
/foo/:name .... GET fooname ^/foo/([^/\.]+))(?:\.([^/]+)$)?
/bar .... POST bar ^/bar(?:\.([^/]+)$)?

=head1 ADVANCED

Expand Down

0 comments on commit 9b8f60d

Please sign in to comment.