-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChapter.pm
146 lines (128 loc) · 3.26 KB
/
Chapter.pm
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
=head1 NAME
Remark::Chapter - Description
=head1 SYNOPSIS
use Remark::Chapter;
blah;
=head1 DESCRIPTION
Describe the module.
=head1 AUTHOR
attila <[email protected]>
=head1 COPYRIGHT AND LICENSE
(C) 2002-2003 by attila <[email protected]>. all rights reserved.
=head1 VERSION
$Id: Chapter.pm,v 1.1 2003/07/20 01:55:50 attila Exp $
Time-stamp: <2003-07-16 20:03:15 EDT>
=cut
package Remark::Chapter;
use strict;
use Carp;
require Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUGGING $TESTING);
$VERSION = q{0.1.0};
@ISA = qw(Exporter);
@EXPORT_OK = qw();
@EXPORT = @EXPORT_OK;
$DEBUGGING = 0;
$TESTING = 0;
use Remark::Utils;
=head1 DETAILED DOCUMENTATION
This class exports the following interface:
=head2 new [args=>vals]
=cut
sub add_par {
my $self = shift(@_);
my $par = shift(@_);
print STDERR "[C<",$self->{name},"> add_par $par]\n"
if ($self->{context}->{VERBOSE} > 1);
return unless $par;
push(@{$self->{contents}}, $par);
$self->{nwords} += $par->{nwords};
$self->{nparagraphs}++;
print STDERR "[S<",$self->{name},"> added ",$par->{nwords}," (",
scalar(@{$self->{contents}}),")]\n"
if ($self->{context}->{VERBOSE} > 1);
return $self;
}
##
sub add_sect {
my $self = shift(@_);
my $sect = shift(@_);
return unless $sect;
push(@{$self->{contents}}, $sect);
$self->{nwords} += $sect->{nwords};
$self->{nparagraphs} += scalar(@{$sect->{paragraphs}});
return $self;
}
##
sub output_docbook {
my $self = shift(@_);
my $level = shift(@_);
my $ostream = shift(@_);
my $ispref = shift(@_);
return if ($self->{context}->{NoPreface} && $ispref);
my($tag,$c1,$c2) = $ispref? ("preface","{","}"): ("chapter","[","]");
my $i = indent($level);
return if (($self->{name} =~ /^unnamed/i) &&
!$self->{context}->{OutputUn});
return if (($self->{name} =~ /side\smaterial/i) &&
!$self->{context}->{SideMaterial});
my $nnamed = 0;
foreach my $sect (@{$self->{contents}}) {
++$nnamed if ($sect->{name} !~ /^unnamed/);
}
return if (!$nnamed && !$self->{context}->{OutputUn});
print $ostream "$i<$tag>\n <title>",$self->{name},"</title>\n";
my $secs = defined($self->{sections})? $self->{sections}: [];
print $ostream "$i <!-- CHAP:",
scalar(@$secs)," sects, ",$self->{nparagraphs}," pars ",
$self->{nwords}," words -->\n";
print STDERR $c1 if $self->{context}->{Dots};
foreach my $sect (@{$self->{contents}}) {
$sect->output_docbook($level+1,$ostream);
}
print $ostream "$i</$tag>\n";
print STDERR $c2 if $self->{context}->{Dots};
}
##
sub mark {
my $self = shift(@_);
foreach my $m (@_) {
$self->{marks}->{$m}++;
}
}
##
sub marked {
my $self = shift(@_);
my $what = shift(@_);
return 0 unless $what;
return defined($self->{marks}->{$what});
}
##
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my %args = @_;
my $name = $args{name} || "unnamed Chapter";
my $self =
bless
{ name => psychochomp($name),
contents => [],
nparagraphs => 0,
nwords => 0,
marks => {},
context => $args{'context'},
}, $class;
return $self;
}
##
1;
__END__
##
# Local variables:
# tab-width: 2
# perl-indent-level: 2
# indent-tabs-mode: nil
# comment-column: 40
# time-stamp-line-limit: 40
# End:
##