| 1 | package MojoMojo::Formatter::Pod; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 27 | ▶ | use parent qw/MojoMojo::Formatter/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | # Pod::Simple::HTML gives warnings for version_tag_comment() | ||||||||||||||||||||||||||||
| 5 | # because $self->VERSION is empty in the sprintf. We don't | ||||||||||||||||||||||||||||
| 6 | # really care about this sub do we? It's been monkey zapped. | ||||||||||||||||||||||||||||
| 7 | BEGIN | ||||||||||||||||||||||||||||
| 8 | 27 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 27 | ▶ | use Pod::Simple::HTML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 27 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 27 | ▶ | *{"Pod::Simple::HTML::version_tag_comment"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 13 | 4 | return; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | 27 | } | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | MojoMojo::Formatter::Pod - format part of content as POD | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | This formatter will format content between {{pod}} and {{end}} as | ||||||||||||||||||||||||||||
| 25 | POD (Plain Old Documentation). | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 METHODS | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head2 format_content_order | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | Format order can be 1-99. The POD formatter runs on 10. | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1116 | ▶ | sub format_content_order { 10 } | ||||||||||||||||||||||||||
|
Subroutine
format_content_order: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head2 format_content | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | calls the formatter. Takes a ref to the content as well as the | ||||||||||||||||||||||||||||
| 40 | context object. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =cut | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 125 | ▶ | sub format_content { | ||||||||||||||||||||||||||
|
Subroutine
format_content: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 125 | my ( $class, $content, $c ) = @_; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 125 | my @lines = split /\n/, $$content; | |||||||||||||||||||||||||||
| 48 | 125 | my $pod; | |||||||||||||||||||||||||||
| 49 | 125 | $$content = ""; | |||||||||||||||||||||||||||
| 50 | 125 | my $start_re=$class->gen_re(qr/pod/); | |||||||||||||||||||||||||||
| 51 | 125 | my $end_re=$class->gen_re(qr/end/); | |||||||||||||||||||||||||||
| 52 | 125 | foreach my $line (@lines) { | |||||||||||||||||||||||||||
| 53 | 655 | ▶ | if ($pod) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 21 | ▶ | if ( $line =~ m/^(.*)$end_re(.*)$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 3 | $$content .= MojoMojo::Formatter::Pod->to_pod( $pod.$1, $c->req->base ).$2; | |||||||||||||||||||||||||||
| 56 | 3 | $pod = ""; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 18 | else { $pod .= $line . "\n"; } | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||
| 61 | 634 | ▶ | if ( $line =~ m/^(.*)$start_re(.*)$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 3 | $$content .= $1; | |||||||||||||||||||||||||||
| 63 | 3 | $pod = " ".$2; # make it true :) | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 631 | else { $$content .= $line . "\n"; } | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head2 to_pod <pod> <base> | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | Takes some POD documentation, a base URL, and renders it as HTML. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 4 | ▶ | sub to_pod { | ||||||||||||||||||||||||||
|
Subroutine
to_pod: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 4 | my ( $class, $pod, $base ) = @_; | |||||||||||||||||||||||||||
| 78 | 4 | my $result; | |||||||||||||||||||||||||||
| 79 | 4 | my $parser = MojoMojo::Formatter::Pod::Simple::HTML->new($base); | |||||||||||||||||||||||||||
| 80 | 4 | $parser->output_string( \$result ); | |||||||||||||||||||||||||||
| 81 | 4 | eval { $parser->parse_string_document($pod); }; | |||||||||||||||||||||||||||
| 82 | 4 | ▶ | return "<pre>\n$source\n$@\n</pre>\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ or not $result
MC/DC0%0/2
$@ or not $result
$@
not $result
Truth table33%1/3
A or not(B)
A= $@B= not $result
| |||||||||||||||||||||||||||||
| 83 | if $@ or not $result; | ||||||||||||||||||||||||||||
| 84 | 4 | $result =~ s/.*<body.*?>(.*)<\/body>.*/$1/s; | |||||||||||||||||||||||||||
| 85 | 4 | return qq{<div class="formatter_pod">\n$result</div>}; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | package MojoMojo::Formatter::Pod::Simple::HTML; | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # base class for doing links | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 27 | ▶ | use parent 'Pod::Simple::HTML'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head2 Pod::Simple::HTML::new | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | Extended for setting C<base>. | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 101 | 4 | my ( $class, $base ) = @_; | |||||||||||||||||||||||||||
| 102 | 4 | my $self = $class->SUPER::new; | |||||||||||||||||||||||||||
| 103 | 4 | $self->{_base} = $base; | |||||||||||||||||||||||||||
| 104 | 4 | return $self; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head2 Pod::Simple::HTML::do_link | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | Set links based on base | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =cut | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 1 | ▶ | sub do_link { | ||||||||||||||||||||||||||
|
Subroutine
do_link: called CC=4 SCAR=22.3
| |||||||||||||||||||||||||||||
| 114 | 1 | my ( $self, $token ) = @_; | |||||||||||||||||||||||||||
| 115 | 1 | my $link = $token->attr('to'); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | #FIXME: This doesn't look right: | ||||||||||||||||||||||||||||
| 118 | 1 | ▶ | return $self->SUPER::do_link($token) unless $link =~ /^$token+$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | my $section = $token->attr('section'); | |||||||||||||||||||||||||||
| 120 | 0 | ▶ | $section = "#$section" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $section and length $section
MC/DC0%0/2
defined $section and length $section
defined $section
length $section
Truth table0%0/3
A and B
A= defined $sectionB= length $section
| |||||||||||||||||||||||||||||
| 121 | if defined $section and length $section; | ||||||||||||||||||||||||||||
| 122 | 0 | $self->{base} . "$link$section"; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | L<MojoMojo>, L<Module::Pluggable::Ordered>, L<POD::Tree::HTML> | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | Marcus Ramberg <mramberg@cpan.org> | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | This library is free software. You can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 136 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 27 | 1; | |||||||||||||||||||||||||||