Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 29, 2013
1 parent 7e172e7 commit 089936f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
7 changes: 2 additions & 5 deletions lib/Mojo/Loader.pm
Expand Up @@ -50,12 +50,10 @@ sub search {
sub _all {
my $class = shift;

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

# Ignore everything before __DATA__ (Windows will seek to start of file)
$data =~ s/^.*\n__DATA__\r?\n/\n/s;
Expand All @@ -64,8 +62,7 @@ sub _all {
$data =~ s/\n__END__\r?\n.*$/\n/s;

# Split files
my @files = split /^@@\s*(.+?)\s*\r?\n/m, $data;
shift @files;
(undef, my @files) = split /^@@\s*(.+?)\s*\r?\n/m, $data;
# Find data
my $all = $CACHE{$class} = {};
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojo/URL.pm
Expand Up @@ -176,8 +176,7 @@ sub to_rel {
my @base_parts = @{$base_path->parts};
pop @base_parts unless $base_path->trailing_slash;
while (@parts && @base_parts && $parts[0] eq $base_parts[0]) {
shift @parts;
shift @base_parts;
shift @$_ for \@parts, \@base_parts;
}
my $path = $rel->path(Mojo::Path->new)->path;
$path->leading_slash(1) if $rel->authority;
Expand Down
10 changes: 5 additions & 5 deletions t/mojolicious/exception_lite_app.t
Expand Up @@ -132,17 +132,17 @@ $t->post_ok('/does_not_exist')->status_is(404)
->content_like(qr!/does_not_exist!);

# Dead template
$t->get_ok('/dead_template')->status_is(500)->content_like(qr/1\./)
->content_like(qr/dead template!/);
$t->get_ok('/dead_template')->status_is(500)->content_like(qr/dead template!/)
->content_like(qr/line 1/);
like $log, qr/dead template!/, 'right result';

# Dead partial template
$t->get_ok('/dead_included_template')->status_is(500)->content_like(qr/1\./)
->content_like(qr/dead template!/);
$t->get_ok('/dead_included_template')->status_is(500)
->content_like(qr/dead template!/)->content_like(qr/line 1/);

# Dead template with layout
$t->get_ok('/dead_template_with_layout')->status_is(500)
->content_like(qr/2\./)->content_like(qr/dead template with layout!/);
->content_like(qr/dead template with layout!/)->content_like(qr/line 2/);
like $log, qr/dead template with layout!/, 'right result';

# Dead action
Expand Down

0 comments on commit 089936f

Please sign in to comment.