File: view.t

package info (click to toggle)
libpod-pom-perl 2.01-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 800 kB
  • sloc: perl: 2,756; makefile: 7
file content (107 lines) | stat: -rw-r--r-- 1,650 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/perl -w                                         # -*- perl -*-

use strict;
use lib qw( ./lib ../lib );
use Pod::POM;
use Pod::POM::View;
use Pod::POM::Test;

ntests(2);

#------------------------------------------------------------------------
package My::View;
use parent qw( Pod::POM::View::Text );

sub view_head1 {
    my ($self, $head1) = @_;
    my $title = $head1->title->present($self);

    $self->visit('head1');
    my $output = "<h1>$title</h1>\n\n"
	. $head1->content->present($self);
    $self->leave('head1');

    return $output;
}

sub view_head2 {
    my ($self, $head2) = @_;
    my $title = $head2->title->present($self);

    if ($self->visiting('head1')) {
	return "<h2>$title</h2>\n\n"
	    . $head2->content->present($self);
    }
    else {
	return "<h1>$title</h1>\n\n"
	    . $head2->content->present($self);
    }
}

#------------------------------------------------------------------------
package main;
    
my $text;
{   local $/ = undef;
    $text = <DATA>;
}
my ($test, $expect) = split(/\s*-------+\s*/, $text);

my $parser = Pod::POM->new();

my $pom = $parser->parse_text($test);

assert( $pom );

$Pod::POM::DEFAULT_VIEW = 'My::View';

my $result = "$pom";

for ($result, $expect) {
    s/^\s*//;
    s/\s*$//;
}

match($result, $expect);

__DATA__
=head2 TWO

Outer head2

=head1 FIRST

First head1

=head1 SECOND

Second head1

=head2 INNER

Inner head2

=head1 THIRD

Third head1
------------------------------------------------------------------------
<h1>TWO</h1>

Outer head2

<h1>FIRST</h1>

First head1

<h1>SECOND</h1>

Second head1

<h2>INNER</h2>

Inner head2

<h1>THIRD</h1>

Third head1