line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoMojo::Formatter::Pod; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
18921
|
use parent qw/MojoMojo::Formatter/; |
|
27
|
|
|
|
|
283
|
|
|
27
|
|
|
|
|
236
|
|
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
|
|
|
|
|
|
|
{ |
9
|
27
|
|
|
27
|
|
16223
|
use Pod::Simple::HTML; |
|
27
|
|
|
|
|
881947
|
|
|
27
|
|
|
|
|
343
|
|
10
|
27
|
|
|
27
|
|
1124
|
no warnings 'redefine'; |
|
27
|
|
|
|
|
73
|
|
|
27
|
|
|
|
|
1629
|
|
11
|
27
|
|
|
|
|
8774
|
*{"Pod::Simple::HTML::version_tag_comment"} = sub { |
12
|
4
|
|
|
4
|
|
1232
|
my $self = shift; |
13
|
4
|
|
|
|
|
32
|
return; |
14
|
|
|
|
|
|
|
} |
15
|
27
|
|
|
27
|
|
193
|
} |
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
|
|
|
1116
|
1
|
3118
|
sub format_content_order { 10 } |
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
|
|
|
|
|
|
|
sub format_content { |
45
|
125
|
|
|
125
|
1
|
952
|
my ( $class, $content, $c ) = @_; |
46
|
|
|
|
|
|
|
|
47
|
125
|
|
|
|
|
626
|
my @lines = split /\n/, $$content; |
48
|
125
|
|
|
|
|
299
|
my $pod; |
49
|
125
|
|
|
|
|
319
|
$$content = ""; |
50
|
125
|
|
|
|
|
654
|
my $start_re=$class->gen_re(qr/pod/); |
51
|
125
|
|
|
|
|
825
|
my $end_re=$class->gen_re(qr/end/); |
52
|
125
|
|
|
|
|
482
|
foreach my $line (@lines) { |
53
|
657
|
100
|
|
|
|
1275
|
if ($pod) { |
54
|
21
|
100
|
|
|
|
96
|
if ( $line =~ m/^(.*)$end_re(.*)$/ ) { |
55
|
3
|
|
|
|
|
22
|
$$content .= MojoMojo::Formatter::Pod->to_pod( $pod.$1, $c->req->base ).$2; |
56
|
3
|
|
|
|
|
38
|
$pod = ""; |
57
|
|
|
|
|
|
|
} |
58
|
18
|
|
|
|
|
37
|
else { $pod .= $line . "\n"; } |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
636
|
100
|
|
|
|
2215
|
if ( $line =~ m/^(.*)$start_re(.*)$/ ) { |
62
|
3
|
|
|
|
|
12
|
$$content .= $1; |
63
|
3
|
|
|
|
|
10
|
$pod = " ".$2; # make it true :) |
64
|
|
|
|
|
|
|
} |
65
|
633
|
|
|
|
|
1744
|
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
|
|
|
|
|
|
|
sub to_pod { |
77
|
4
|
|
|
4
|
1
|
5471
|
my ( $class, $pod, $base ) = @_; |
78
|
4
|
|
|
|
|
10
|
my $result; |
79
|
4
|
|
|
|
|
25
|
my $parser = MojoMojo::Formatter::Pod::Simple::HTML->new($base); |
80
|
4
|
|
|
|
|
33
|
$parser->output_string( \$result ); |
81
|
4
|
|
|
|
|
4599
|
eval { $parser->parse_string_document($pod); }; |
|
4
|
|
|
|
|
39
|
|
82
|
4
|
50
|
33
|
|
|
6749
|
return "<pre>\n$source\n$@\n</pre>\n" |
83
|
|
|
|
|
|
|
if $@ or not $result; |
84
|
4
|
|
|
|
|
80
|
$result =~ s/.*<body.*?>(.*)<\/body>.*/$1/s; |
85
|
4
|
|
|
|
|
153
|
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
|
|
|
27
|
|
224
|
use parent 'Pod::Simple::HTML'; |
|
27
|
|
|
|
|
62
|
|
|
27
|
|
|
|
|
239
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 Pod::Simple::HTML::new |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Extended for setting C<base>. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub new { |
101
|
4
|
|
|
4
|
|
12
|
my ( $class, $base ) = @_; |
102
|
4
|
|
|
|
|
50
|
my $self = $class->SUPER::new; |
103
|
4
|
|
|
|
|
13
|
$self->{_base} = $base; |
104
|
4
|
|
|
|
|
11
|
return $self; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 Pod::Simple::HTML::do_link |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Set links based on base |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub do_link { |
114
|
1
|
|
|
1
|
|
5660
|
my ( $self, $token ) = @_; |
115
|
1
|
|
|
|
|
5
|
my $link = $token->attr('to'); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
#FIXME: This doesn't look right: |
118
|
1
|
50
|
|
|
|
25
|
return $self->SUPER::do_link($token) unless $link =~ /^$token+$/; |
119
|
0
|
|
|
|
|
|
my $section = $token->attr('section'); |
120
|
0
|
0
|
0
|
|
|
|
$section = "#$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
|
|
|
|
|
|
|
1; |