Navigation Menu

Skip to content

Commit

Permalink
improved not found page to highlight custom route names
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 22, 2012
1 parent bdd39f4 commit 4e7318a
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 25 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,5 +1,5 @@

3.0 2012-06-22
3.0 2012-06-23
- Code name "Rainbow", this is a major release.
- Removed Mojolicious::Plugin::I18N so it can be maintained as a separate
distribution.
Expand All @@ -17,6 +17,7 @@
- Added accept_interval attribute to Mojo::IOLoop.
- Added support for new HTTP status code.
- Modernized ".perltidyrc".
- Improved not found page to highlight custom route names.
- Improved to method in Mojolicious::Routes::Route to give easier access to
default parameters.
- Improved message parser performance slightly.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Home.pm
Expand Up @@ -39,7 +39,7 @@ sub detect {
# Load
my $file = class_to_path $class;
unless ($INC{$file}) {
if (my $e = Mojo::Loader->load($class)) { die $e if ref $e }
if (my $e = Mojo::Loader->new->load($class)) { die $e if ref $e }
}

# Detect
Expand Down
17 changes: 10 additions & 7 deletions lib/Mojo/Loader.pm
Expand Up @@ -65,11 +65,11 @@ sub _all {
my $class = shift;

# Refresh or use cached data
my $d = do { no strict 'refs'; \*{"$class\::DATA"} };
return $CACHE{$class} || {} unless fileno $d;
seek $d, 0, 0;
my $content = join '', <$d>;
close $d;
my $handle = do { no strict 'refs'; \*{"$class\::DATA"} };
return $CACHE{$class} || {} unless fileno $handle;
seek $handle, 0, 0;
my $content = join '', <$handle>;
close $handle;

# Ignore everything before __DATA__ (windows will seek to start of file)
$content =~ s/^.*\n__DATA__\r?\n/\n/s;
Expand Down Expand Up @@ -106,9 +106,12 @@ Mojo::Loader - Loader
my $loader = Mojo::Loader->new;
for my $module (@{$loader->search('Some::Namespace')}) {
# And load them safely
# Load them safely
my $e = $loader->load($module);
warn qq{Loading "$module" failed: $e} if ref $e;
warn qq{Loading "$module" failed: $e} and next if ref $e;
# And extract files from the DATA section
say $loader->data($module, 'some_file.txt');
}
=head1 DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Reactor.pm
Expand Up @@ -7,7 +7,7 @@ use Mojo::Loader;

sub detect {
my $try = $ENV{MOJO_REACTOR} || 'Mojo::Reactor::EV';
return Mojo::Loader->load($try) ? 'Mojo::Reactor::Poll' : $try;
return Mojo::Loader->new->load($try) ? 'Mojo::Reactor::Poll' : $try;
}

sub io { croak 'Method "io" not implemented by subclass' }
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server.pm
Expand Up @@ -13,7 +13,7 @@ has app => sub {

# Load and initialize application
my $class = $ENV{MOJO_APP} ||= 'Mojo::HelloWorld';
if (my $e = Mojo::Loader->load($class)) { die $e if ref $e }
if (my $e = Mojo::Loader->new->load($class)) { die $e if ref $e }
return $ENV{MOJO_APP} = $class->new;
};

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Command.pm
Expand Up @@ -60,7 +60,7 @@ sub rel_file { catfile(getcwd(), split /\//, pop) }

sub render_data {
my $self = shift;
Mojo::Template->new->render(Mojo::Loader->data(ref $self, shift), @_);
Mojo::Template->new->render(Mojo::Loader->new->data(ref $self, shift), @_);
}

sub render_to_file {
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojolicious/Command/inflate.pm
Expand Up @@ -13,8 +13,9 @@ sub run {

# Find all embedded files
my %all;
my $app = $self->app;
%all = (%{Mojo::Loader->data($_)}, %all)
my $app = $self->app;
my $loader = Mojo::Loader->new;
%all = (%{$loader->data($_)}, %all)
for @{$app->renderer->classes}, @{$app->static->classes};

# Turn them into real files
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojolicious/Commands.pm
Expand Up @@ -83,8 +83,9 @@ sub run {

# Try all namespaces
my (@commands, %seen);
my $loader = Mojo::Loader->new;
for my $namespace (@{$self->namespaces}) {
for my $module (@{Mojo::Loader->search($namespace)}) {
for my $module (@{$loader->search($namespace)}) {
next unless my $command = _command($module);
$command =~ s/^$namespace\:\://;
push @commands, [$command => $module] unless $seen{$command}++;
Expand Down Expand Up @@ -126,7 +127,7 @@ sub start_app {
sub _command {
my ($module, $fatal) = @_;
return $module->isa('Mojolicious::Command') ? $module : undef
unless my $e = Mojo::Loader->load($module);
unless my $e = Mojo::Loader->new->load($module);
$fatal && ref $e ? die $e : return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugins.pm
Expand Up @@ -60,7 +60,7 @@ sub _load {
my ($self, $module) = @_;

# Load
if (my $e = Mojo::Loader->load($module)) { ref $e ? die $e : return }
if (my $e = Mojo::Loader->new->load($module)) { ref $e ? die $e : return }

# Module is a plugin
return $module->isa('Mojolicious::Plugin') ? 1 : undef;
Expand Down
9 changes: 5 additions & 4 deletions lib/Mojolicious/Renderer.pm
Expand Up @@ -62,15 +62,16 @@ sub get_data_template {
my ($self, $options, $template) = @_;

# Index DATA templates
my $loader = Mojo::Loader->new;
unless ($self->{index}) {
my $index = $self->{index} = {};
for my $class (reverse @{$self->classes}) {
$index->{$_} = $class for keys %{Mojo::Loader->data($class)};
$index->{$_} = $class for keys %{$loader->data($class)};
}
}

# Find template
return Mojo::Loader->data($self->{index}{$template}, $template);
return $loader->data($self->{index}{$template}, $template);
}

sub render {
Expand Down Expand Up @@ -188,8 +189,8 @@ sub _detect_handler {

# DATA templates
unless ($self->{data}) {
my @templates
= map { sort keys %{Mojo::Loader->data($_)} } @{$self->classes};
my $loader = Mojo::Loader->new;
my @templates = map { sort keys %{$loader->data($_)} } @{$self->classes};
s/\.(\w+)$// and $self->{data}{$_} ||= $1 for @templates;
}
return $self->{data}{$file} if exists $self->{data}{$file};
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Routes.pm
Expand Up @@ -155,7 +155,7 @@ sub _load {

# Load unless already loaded or application
return 1 if $self->{loaded}{$app} || ref $app;
if (my $e = Mojo::Loader->load($app)) {
if (my $e = Mojo::Loader->new->load($app)) {

# Doesn't exist
$c->app->log->debug(qq{Controller "$app" does not exist.}) and return
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojolicious/Static.pm
Expand Up @@ -122,15 +122,16 @@ sub _get_data_file {
return if $rel =~ /\.\w+\.\w+$/;

# Index DATA files
my $loader = Mojo::Loader->new;
unless ($self->{index}) {
my $index = $self->{index} = {};
for my $class (reverse @{$self->classes}) {
$index->{$_} = $class for keys %{Mojo::Loader->data($class)};
$index->{$_} = $class for keys %{$loader->data($class)};
}
}

# Find file
return Mojo::Loader->data($self->{index}{$rel}, $rel);
return $loader->data($self->{index}{$rel}, $rel);
}

sub _get_file {
Expand Down
5 changes: 4 additions & 1 deletion lib/Mojolicious/templates/not_found.development.html.ep
Expand Up @@ -96,7 +96,10 @@
<td>
<pre><%= uc(join ',', @{$node->via || []}) || '*' %></pre>
</td>
<td><pre><%= $node->name %></pre></td>
<td>
% my $name = $node->name;
<pre><%= $node->has_custom_name ? qq{"$name"} : $name %></pre>
</td>
</tr>
% $depth++;
%= $walk->($_, $depth) for @{$node->children};
Expand Down

0 comments on commit 4e7318a

Please sign in to comment.