Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
small optimizations
  • Loading branch information
kraih committed May 24, 2013
1 parent da25d93 commit e583b8a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

4.07 2013-05-25
4.07 2013-05-26
- Updated jQuery to version 2.0.1.
- Fixed format handling in routes command.

Expand Down
16 changes: 8 additions & 8 deletions lib/Mojolicious/Command/routes.pm
Expand Up @@ -31,11 +31,11 @@ sub _draw {

# Methods
my $via = $node->[0]->via;
$node->[2] = $via ? uc(join ',', @$via) : '*';
$node->[2] = !$via ? '*' : uc join ',', @$via;

# Name
$node->[3] = $node->[0]->name;
$node->[3] = qq{"$node->[3]"} if $node->[0]->has_custom_name;
my $name = $node->[0]->name;
$node->[3] = $node->[0]->has_custom_name ? qq{"$name"} : $name;

# Check column width
$table[$_] = _max($table[$_], length $node->[$_ + 1]) for 0 .. 2;
Expand All @@ -51,8 +51,8 @@ sub _draw {
my $format = (regexp_pattern($pattern->format_regex || ''))[0];
my $optional
= !$pattern->constraints->{format} || $pattern->defaults->{format};
$format = "(?:$format)?" if $format && $optional;
push @parts, $format ? "$regex$format" : $regex if $verbose;
$regex .= $optional ? "(?:$format)?" : $format if $format;
push @parts, $regex if $verbose;

say encode('UTF-8', join(' ', @parts));
}
Expand All @@ -63,14 +63,14 @@ sub _max { $_[1] > $_[0] ? $_[1] : $_[0] }
sub _padding { $_[0] . ' ' x ($_[1] - length $_[0]) }

sub _walk {
my ($self, $node, $depth, $routes) = @_;
my ($self, $route, $depth, $routes) = @_;

my $prefix = '';
if (my $i = $depth * 2) { $prefix .= ' ' x $i . '+' }
push @$routes, [$node, $prefix . ($node->pattern->pattern || '/')];
push @$routes, [$route, $prefix . ($route->pattern->pattern || '/')];

$depth++;
$self->_walk($_, $depth, $routes) for @{$node->children};
$self->_walk($_, $depth, $routes) for @{$route->children};
$depth--;
}

Expand Down
12 changes: 6 additions & 6 deletions lib/Mojolicious/templates/not_found.development.html.ep
Expand Up @@ -85,23 +85,23 @@
new one?
</p>
% my $walk = begin
% my ($walk, $node, $depth) = @_;
% my ($walk, $route, $depth) = @_;
<tr>
<td>
% my $pattern = $node->pattern->pattern || '/';
% my $pattern = $route->pattern->pattern || '/';
% $pattern = "+$pattern" if $depth;
<pre><%= ' ' x $depth %><%= $pattern %></pre>
</td>
<td>
<pre><%= uc(join ',', @{$node->via || []}) || '*' %></pre>
<pre><%= uc(join ',', @{$route->via || []}) || '*' %></pre>
</td>
<td>
% my $name = $node->name;
<pre><%= $node->has_custom_name ? qq{"$name"} : $name %></pre>
% my $name = $route->name;
<pre><%= $route->has_custom_name ? qq{"$name"} : $name %></pre>
</td>
</tr>
% $depth++;
%= $walk->($walk, $_, $depth) for @{$node->children};
%= $walk->($walk, $_, $depth) for @{$route->children};
% $depth--;
% end
<table>
Expand Down

0 comments on commit e583b8a

Please sign in to comment.