Navigation Menu

Skip to content

Commit

Permalink
fixed handler detection precedence bug in Mojolicious::Renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 28, 2012
1 parent 5552c7e commit a5b9bc3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -3,6 +3,7 @@ This file documents the revision history for Perl extension Mojolicious.
2.70 2012-03-28
- Improved speed of version command by switching to the MetaCPAN API.
- Improved documentation.
- Fixed handler detection precedence bug in Mojolicious::Renderer.
- Fixed small bug in Mojo::Command->get_all_data.
- Fixed small bug in inflate command. (memowe)

Expand Down
29 changes: 13 additions & 16 deletions lib/Mojolicious/Renderer.pm
Expand Up @@ -75,8 +75,15 @@ EOF

sub get_data_template {
my ($self, $options, $template) = @_;
return Mojo::Command->new->get_data($template,
$self->_data_templates->{$template});

# Index and find DATA templates
unless ($self->{index}) {
my $index = $self->{index} = {};
for my $class (reverse @{$self->classes}) {
$index->{$_} = $class for keys %{Mojo::Command->get_all_data($class)};
}
}
return Mojo::Command->new->get_data($template, $self->{index}->{$template});
}

# "Bodies are for hookers and fat people."
Expand Down Expand Up @@ -204,36 +211,26 @@ sub template_path {
return catfile($self->paths->[0], split '/', $name);
}

sub _data_templates {
my $self = shift;

# Index DATA templates
return $self->{data_templates} if $self->{data_templates};
for my $class (reverse @{$self->classes}) {
$self->{data_templates}->{$_} = $class
for keys %{Mojo::Command->new->get_all_data($class)};
}
return $self->{data_templates} ||= {};
}

sub _detect_handler {
my ($self, $options) = @_;

# Templates
return unless my $file = $self->template_name($options);
unless ($self->{templates}) {
$_ =~ s/\.(\w+)$// and $self->{templates}->{$_} ||= $1
for sort map { @{Mojo::Home->new($_)->list_files} } @{$self->paths};
for map { sort @{Mojo::Home->new($_)->list_files} } @{$self->paths};
}
return $self->{templates}->{$file} if exists $self->{templates}->{$file};

# DATA templates
unless ($self->{data}) {
$_ =~ s/\.(\w+)$// and $self->{data}->{$_} ||= $1
for sort keys %{$self->_data_templates};
for map { sort keys %{Mojo::Command->get_all_data($_)} }
@{$self->classes};
}
return $self->{data}->{$file} if exists $self->{data}->{$file};

# Nothing
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Static.pm
Expand Up @@ -149,7 +149,7 @@ sub _get_data_file {
$self->{data_files} = {};
for my $class (reverse @{$self->classes}) {
$self->{data_files}->{$_} = $class
for keys %{Mojo::Command->new->get_all_data($class)};
for keys %{Mojo::Command->get_all_data($class)};
}
}

Expand Down
2 changes: 1 addition & 1 deletion t/mojolicious/lib/MojoliciousTest/Foo.pm
Expand Up @@ -83,7 +83,7 @@ sub withlayout { shift->stash(template => 'withlayout') }
1;
__DATA__
@@ just/some/template.html.ep
@@ just/some/template.html.epl
Development template with high precedence.
@@ some/static/file.txt
Expand Down
File renamed without changes.

0 comments on commit a5b9bc3

Please sign in to comment.