Skip to content

Commit

Permalink
Mojolicious::Plugin::PODRenderer no longer supports Perl 5.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 26, 2014
1 parent 5fca5d3 commit 0c0311f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
9 changes: 6 additions & 3 deletions lib/Mojolicious/Plugin/PODRenderer.pm
Expand Up @@ -12,6 +12,9 @@ use Pod::Simple::Search;
sub register {
my ($self, $app, $conf) = @_;

# Pod::Simple::XHTML in Perl 5.10.1 was broken
die 'Mojolicious::Plugin::PODRenderer requires Perl 5.12' if $] < 5.012;

my $preprocess = $conf->{preprocess} || 'ep';
$app->renderer->add_handler(
$conf->{name} || 'pod' => sub {
Expand Down Expand Up @@ -61,13 +64,13 @@ sub _html {
my $pod = Pod::Simple::XHTML->new;
for my $e ($dom->find('h1, h2, h3')->each) {

# Anchor
my $text = $e->all_text;
my $anchor = $pod->idify($e->{id} // $text);
# Unique anchor
my $anchor = $pod->idify($e->{id});

# Rewrite
push @parts, [] if $e->type eq 'h1' || !@parts;
my $link = Mojo::URL->new->fragment($anchor);
my $text = $e->all_text;
push @{$parts[-1]}, $text, $link;
my $permalink = $self->link_to('#' => $link, class => 'permalink');
$e->content($permalink . $self->link_to($text => $toc, id => $anchor));
Expand Down
13 changes: 9 additions & 4 deletions t/mojolicious/pod_renderer_lite_app.t
Expand Up @@ -6,6 +6,10 @@ BEGIN {
}

use Test::More;

plan skip_all => 'Mojolicious::Plugin::PODRenderer requires Perl 5.12'
if $] < 5.012;

use Mojolicious::Lite;
use Test::Mojo;

Expand All @@ -30,17 +34,18 @@ get '/empty' => {inline => '', handler => 'pod'};
my $t = Test::Mojo->new;

# Simple POD template
$t->get_ok('/')->status_is(200)->content_like(qr!<h1.*>Test123</h1>!)
$t->get_ok('/')->status_is(200)
->content_like(qr!<h1 id="Test123">Test123</h1>!)
->content_like(qr|<p>It <code>works</code>!</p>|);

# POD helper
$t->post_ok('/')->status_is(200)->content_like(qr!test123<h1.*>A</h1>!)
->content_like(qr!<h1.*>B</h1>!)
$t->post_ok('/')->status_is(200)->content_like(qr!test123<h1 id="A">A</h1>!)
->content_like(qr!<h1 id="B">B</h1>!)
->content_like(qr!\s+<p><code>test</code></p>!)->content_like(qr/Gray/);

# POD filter
$t->post_ok('/block')->status_is(200)
->content_like(qr!test321<h2.*>lalala</h2>!)
->content_like(qr!test321<h2 id="lalala">lalala</h2>!)
->content_like(qr!<p><code>test</code></p>!)->content_like(qr/Gray/);

# Empty
Expand Down
4 changes: 4 additions & 0 deletions t/mojolicious/twinkle_lite_app.t
Expand Up @@ -6,6 +6,10 @@ BEGIN {
}

use Test::More;

plan skip_all => 'Mojolicious::Plugin::PODRenderer requires Perl 5.12'
if $] < 5.012;

use Mojolicious::Lite;
use Mojo::Util;
use Test::Mojo;
Expand Down

0 comments on commit 0c0311f

Please sign in to comment.