1use Test::More;
2use strict;
3use Pod::POM;
4use Pod::POM::View::HTML::Filter;
5
6$Pod::POM::DEFAULT_VIEW = Pod::POM::View::HTML::Filter->new;
7
8my @tests = map { [ split /^---.*?^/ms ] } split /^===.*?^/ms, << 'TESTS';
9=begin filter foo
10
11bar foo bar
12baz
13
14=end
15---
16<html><body bgcolor="#ffffff">
17bar bar bar
18baz
19</body></html>
20===
21=begin filter foo
22
23    foo bar baz
24
25=end filter foo
26---
27<html><body bgcolor="#ffffff">
28<pre>    bar bar baz</pre>
29</body></html>
30===
31this line is considered code by Pod::POM
32
33=for filter=foo
34bar foo bar
35
36para
37---
38<html><body bgcolor="#ffffff">
39bar bar bar
40<p>para</p>
41</body></html>
42===
43=pod
44
45para
46
47=for filter=foo
48bar bar foo
49foo bar bar
50
51para
52---
53<html><body bgcolor="#ffffff">
54<p>para</p>
55bar bar bar
56bar bar bar
57<p>para</p>
58</body></html>
59===
60=begin filter options a b c
61
62The options are:
63
64=end
65---
66<html><body bgcolor="#ffffff">
67[The options are:]<a b c>
68</body></html>
69===
70=begin filter verb
71
72    verbatim block
73
74verbatim textblock
75
76=end
77---
78<html><body bgcolor="#ffffff">
79<pre>    verbatim block
80
81verbatim textblock</pre>
82</body></html>
83TESTS
84
85plan tests => scalar @tests + 2;
86
87# add a new language
88Pod::POM::View::HTML::Filter->add(
89    foo     => { code => sub { my $s = shift; $s =~ s/foo/bar/g; $s } },
90    options => { code => sub { "[$_[0]]<$_[1]>" } },
91    verb    => { code => sub { $_[0] }, verbatim => 1 },
92);
93
94my $parser = Pod::POM->new;
95for ( @tests ) {
96    my $pom = $parser->parse_text( $_->[0] ) || diag $parser->error;
97    is( "$pom", $_->[1], "Correct output" );
98}
99
100# check what happens if $pom->present is called twice in a row
101my $pom = $parser->parse_text( << 'EOT' ) || diag $parser->error;
102=begin filter foo
103
104    foo bar baz
105
106=end filter foo
107EOT
108my $expected = << 'EOT';
109<html><body bgcolor="#ffffff">
110<pre>    bar bar baz</pre>
111</body></html>
112EOT
113
114is( "$pom", $expected, "Correct output the first time" );
115is( "$pom", $expected, "Correct output the second time around" );
116
117