Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 16, 2012
1 parent e23f582 commit b1492d9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/Mojolicious/Commands.pm
Expand Up @@ -131,7 +131,7 @@ sub start_app {

sub _command {
my $module = shift;
if (my $e = Mojo::Loader->load($module)) { return ref $e ? die $e : undef }
if (my $e = Mojo::Loader->load($module)) { ref $e ? die $e : return }
return $module->isa('Mojo::Command') ? $module : undef;
}

Expand Down
14 changes: 5 additions & 9 deletions lib/Mojolicious/Plugin/PODRenderer.pm
Expand Up @@ -68,7 +68,7 @@ sub register {
}
);

# Rewrite code sections for syntax highlighting
# Rewrite code blocks for syntax highlighting
$dom->find('pre')->each(
sub {
my $e = shift;
Expand All @@ -82,16 +82,16 @@ sub register {

# Rewrite headers
my $url = $self->req->url->clone;
my @sections;
my @parts;
$dom->find('h1, h2, h3')->each(
sub {
my $e = shift;
my $anchor = my $text = $e->all_text;
$anchor =~ s/\s+/_/g;
$anchor = url_escape $anchor, 'A-Za-z0-9_';
$anchor =~ s/\%//g;
push @sections, [] if $e->type eq 'h1' || !@sections;
push @{$sections[-1]}, $text, $url->fragment($anchor)->to_abs;
push @parts, [] if $e->type eq 'h1' || !@parts;
push @{$parts[-1]}, $text, $url->fragment($anchor)->to_abs;
$e->replace_content(
$self->link_to(
$text => $url->fragment('toc')->to_abs,
Expand All @@ -108,11 +108,7 @@ sub register {

# Combine everything to a proper response
$self->content_for(perldoc => "$dom");
$self->render(
inline => $PERLDOC,
title => $title,
sections => \@sections
);
$self->render(inline => $PERLDOC, title => $title, parts => \@parts);
$self->res->headers->content_type('text/html;charset="UTF-8"');
}
) unless $conf->{no_perldoc};
Expand Down
5 changes: 1 addition & 4 deletions lib/Mojolicious/Plugins.pm
Expand Up @@ -60,10 +60,7 @@ sub _load {
my ($self, $module) = @_;

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

# Module is a plugin
return $module->isa('Mojolicious::Plugin') ? 1 : undef;
Expand Down
12 changes: 5 additions & 7 deletions lib/Mojolicious/templates/perldoc.html.ep
Expand Up @@ -69,15 +69,13 @@
<div id="perldoc">
<h1><a id="toc">TABLE OF CONTENTS</a></h1>
<ul>
% for my $section (@$sections) {
% for my $part (@$parts) {
<li>
%= $link->(splice @$section, 0, 2)
% if (@$section) {
%= $link->(splice @$part, 0, 2)
% if (@$part) {
<ul>
% while (@$section) {
<li>
%= $link->(splice @$section, 0, 2)
</li>
% while (@$part) {
<li><%= $link->(splice @$part, 0, 2) %></li>
% }
</ul>
% }
Expand Down

0 comments on commit b1492d9

Please sign in to comment.