File: Nodes.pm

package info (click to toggle)
libpod-pom-perl 0.02-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 192 kB
  • ctags: 117
  • sloc: perl: 1,277; makefile: 50
file content (263 lines) | stat: -rw-r--r-- 6,063 bytes parent folder | download
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#============================================================= -*-Perl-*-
#
# Pod::POM::Nodes
#
# DESCRIPTION
#   Module implementing specific nodes in a Pod::POM, subclassed from
#   Pod::POM::Node.
#
# AUTHOR
#   Andy Wardley   <abw@kfs.org>
#
# COPYRIGHT
#   Copyright (C) 2000, 2001 Andy Wardley.  All Rights Reserved.
#
#   This module is free software; you can redistribute it and/or
#   modify it under the same terms as Perl itself.
#
# REVISION
#   $Id: Nodes.pm,v 1.1.1.1 2000/11/17 17:31:53 abw Exp $
#
#========================================================================

package Pod::POM::Nodes;

require 5.004;

use strict;
use Pod::POM::Node;
use vars qw( $VERSION $DEBUG $ERROR );

$VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/);
$DEBUG   = 0 unless defined $DEBUG;


#------------------------------------------------------------------------
package Pod::POM::Node::Pod;
use base qw( Pod::POM::Node );
use vars qw( @ACCEPT $ERROR );

@ACCEPT = qw( head1 head2 over begin for text verbatim code );


#------------------------------------------------------------------------
package Pod::POM::Node::Head1;
use base qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $ERROR );

%ATTRIBS =   ( title => undef );
@ACCEPT  = qw( head2 over begin for text verbatim code );

sub new {
    my ($class, $pom, $title) = @_;
    $title = $pom->parse_sequence($title)
	|| return $class->error($pom->error())
	    if length $title;
    $class->SUPER::new($pom, $title);
}


#------------------------------------------------------------------------
package Pod::POM::Node::Head2;
use base qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $ERROR );

%ATTRIBS =   ( title => undef );
@ACCEPT  = qw( over begin for text verbatim code );

sub new {
    my ($class, $pom, $title) = @_;
    $title = $pom->parse_sequence($title)
	|| return $class->error($pom->error())
	    if length $title;
    $class->SUPER::new($pom, $title);
}


#------------------------------------------------------------------------
package Pod::POM::Node::Over;
use base qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $EXPECT $ERROR );

%ATTRIBS =   ( indent => 4 );
@ACCEPT  = qw( over item begin for text verbatim code );
$EXPECT  = 'back';


#------------------------------------------------------------------------
package Pod::POM::Node::Item;
use base qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $ERROR );

%ATTRIBS =   ( title => '*' );
@ACCEPT  = qw( over begin for text verbatim code );

sub new {
    my ($class, $pom, $title) = @_;
    $title = $pom->parse_sequence($title)
	|| return $class->error($pom->error())
	    if length $title;
    $class->SUPER::new($pom, $title);
}


#------------------------------------------------------------------------
package Pod::POM::Node::Begin;
use base qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $EXPECT $ERROR );

%ATTRIBS =   ( format => undef );
@ACCEPT  = qw( text verbatim code );
$EXPECT  = 'end';


#------------------------------------------------------------------------
package Pod::POM::Node::For;
use base qw( Pod::POM::Node );
use vars qw( %ATTRIBS $ERROR );

%ATTRIBS = ( format => undef, text => '' );

sub new {
    my $class = shift;
    my $pom   = shift;
    my $text  = shift;
    $class->SUPER::new($pom, split(/\s+/, $text, 2));
}


#------------------------------------------------------------------------
package Pod::POM::Node::Verbatim;
use base qw( Pod::POM::Node );
use vars qw( %ATTRIBS $ERROR );

%ATTRIBS = ( text => '' );

sub present {
    my ($self, $view) = @_;
    $view ||= $Pod::POM::DEFAULT_VIEW;
    $view->view_verbatim($self->{ text });
}


#------------------------------------------------------------------------
package Pod::POM::Node::Code;
use base qw( Pod::POM::Node );
use vars qw( %ATTRIBS $ERROR );

%ATTRIBS = ( text => '' );

sub present {
    my ($self, $view) = @_;
    $view ||= $Pod::POM::DEFAULT_VIEW;
    $view->view_code($self->{ text });
}


#------------------------------------------------------------------------
package Pod::POM::Node::Text;
use Pod::POM::Constants qw( :all );
use base qw( Pod::POM::Node );
use vars qw( %ATTRIBS $ERROR );

%ATTRIBS = ( text => '' );

sub new {
    my $class = shift;
    my $pom   = shift;
    my $text  = shift;
    $text = $pom->parse_sequence($text)
	|| return $class->error($pom->error())
	    if length $text;
    $class->SUPER::new($pom, $text);
}

sub add {
    return IGNORE;
}

sub present {
    my ($self, $view) = @_;
    my $text = $self->{ text };
    $view ||= $Pod::POM::DEFAULT_VIEW;

    $text = $text->present($view) 
	if ref $text && length $text;

    $view->view_textblock($text);
}

#------------------------------------------------------------------------
package Pod::POM::Node::Sequence;

use Pod::POM::Constants qw( :all );
use base qw( Pod::POM::Node );
use vars qw( %NAME );

%NAME = (
    C => 'code',
    B => 'bold',
    I => 'italic',
    L => 'link',
    S => 'space',
    F => 'file',
    X => 'index',
    Z => 'zero',
    E => 'entity',
);
    
sub new {
    my ($class, $self) = @_;
    local $" = '][';
    bless \$self, $class;
}

sub add {
    return IGNORE;
}

sub present {
    my ($self, $view) = @_;
    my ($cmd, $method, $result);
    $view ||= $Pod::POM::DEFAULT_VIEW;

    if (ref $$self eq 'ARRAY') {
	$self = $$self;
	my $text = join('', 
			map { ref $_ ? $_->present($view) 
				     : $view->view_seq_text($_) } 
			@{ $self->[CONTENT] });

	if ($cmd = $self->[CMD]) {
	    my $method = $NAME{ $cmd } || $cmd;
	    $method = "view_seq_$method";
	    return $view->$method($text);
	}
	else {
	    return $text;
	}
    }
    return $$self;
}


#------------------------------------------------------------------------
package Pod::POM::Node::Content;

use Pod::POM::Constants qw( :all );
use base qw( Pod::POM::Node );

sub new {
    my $class = shift;
    bless [ @_ ], $class;
}

sub present {
    my ($self, $view) = @_;
    $view ||= $Pod::POM::DEFAULT_VIEW;
    join('', map { ref $_ ? $_->present($view) : $_ } @$self);
}


1;