line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#============================================================================ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Text::MetaText::Directive |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# DESCRIPTION |
6
|
|
|
|
|
|
|
# A very simple MetaText directive class which is used as the default |
7
|
|
|
|
|
|
|
# class (and is a suitable base class) for Directive objects created by |
8
|
|
|
|
|
|
|
# the MetaText Factory object. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# AUTHOR |
11
|
|
|
|
|
|
|
# Andy Wardley |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# COPYRIGHT |
14
|
|
|
|
|
|
|
# Copyright (C) 1996-1998 Andy Wardley. All Rights Reserved. |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or |
17
|
|
|
|
|
|
|
# modify it under the terms of the Perl Artistic Licence. |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# $Id: Directive.pm,v 0.4 1998/09/01 12:59:37 abw Exp abw $ |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
#============================================================================ |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
package Text::MetaText::Directive; |
26
|
|
|
|
|
|
|
|
27
|
9
|
|
|
9
|
|
50
|
use strict; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
324
|
|
28
|
9
|
|
|
9
|
|
46
|
use vars qw( $VERSION $ERROR ); |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
4818
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
require 5.004; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#======================================================================== |
35
|
|
|
|
|
|
|
# ----- CONFIGURATION ----- |
36
|
|
|
|
|
|
|
#======================================================================== |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 0.4 $ =~ /(\d+)\.(\d+)/); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#======================================================================== |
43
|
|
|
|
|
|
|
# ----- PUBLIC METHODS ----- |
44
|
|
|
|
|
|
|
#======================================================================== |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#======================================================================== |
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
# new(\%cfg) |
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
# Module constructor. A reference to a hash array is passed which is |
51
|
|
|
|
|
|
|
# simply blessed into the relevant class and returned. This is an |
52
|
|
|
|
|
|
|
# extremely simplistic construction process which relies on a well- |
53
|
|
|
|
|
|
|
# defined relationship with the Factory class. Derived classes may |
54
|
|
|
|
|
|
|
# easily extend the functionality of the constructor at this point. |
55
|
|
|
|
|
|
|
# |
56
|
|
|
|
|
|
|
# Returns a reference to a newly created Text::MetaText::Directive. |
57
|
|
|
|
|
|
|
# Derived classes should return a reference to a sub-class of |
58
|
|
|
|
|
|
|
# Text::MetaText::Directive or undef on error. If an error condition |
59
|
|
|
|
|
|
|
# occurs, it should be reported using the private $self->_error() |
60
|
|
|
|
|
|
|
# method. This makes the error message available to the calling |
61
|
|
|
|
|
|
|
# factory object via the error() package function. |
62
|
|
|
|
|
|
|
# |
63
|
|
|
|
|
|
|
#======================================================================== |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub new { |
66
|
230
|
|
|
230
|
0
|
297
|
my $class = shift; |
67
|
230
|
|
|
|
|
270
|
my $self = shift; |
68
|
230
|
|
|
|
|
1209
|
my %params = ( |
69
|
|
|
|
|
|
|
HAS_CONDITION => [ qw( IF UNLESS ) ], |
70
|
|
|
|
|
|
|
HAS_POSTPROC => [ qw( FORMAT FILTER ) ], |
71
|
|
|
|
|
|
|
); |
72
|
230
|
|
|
|
|
325
|
my ($key, $value); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# check a parameter hash was supplied |
76
|
230
|
50
|
|
|
|
489
|
unless (defined $self) { |
77
|
0
|
|
|
|
|
0
|
$self->_error("Directive constructor expects a parameter hash"); |
78
|
0
|
|
|
|
|
0
|
return undef; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# bless the hashref into the required class |
82
|
230
|
|
|
|
|
517
|
bless $self, $class; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# the only thing we do to the new Directive is to examine its internals |
85
|
|
|
|
|
|
|
# and see which optimisation flags we need to set |
86
|
230
|
|
|
|
|
689
|
while (($key, $value) = each %params) { |
87
|
460
|
|
|
|
|
18271
|
foreach (@$value) { |
88
|
871
|
100
|
|
|
|
3144
|
$self->{ $key } = 1, last |
89
|
|
|
|
|
|
|
if defined $self->{ $_ }; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
230
|
|
|
|
|
10679
|
$self; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
#======================================================================== |
99
|
|
|
|
|
|
|
# |
100
|
|
|
|
|
|
|
# error() |
101
|
|
|
|
|
|
|
# |
102
|
|
|
|
|
|
|
# Returns the value of the $ERROR package variable which may be undef |
103
|
|
|
|
|
|
|
# to indicate no current error condition. May be called as a package |
104
|
|
|
|
|
|
|
# function or an object method |
105
|
|
|
|
|
|
|
# |
106
|
|
|
|
|
|
|
#======================================================================== |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub error { |
109
|
0
|
|
|
0
|
0
|
|
return $ERROR; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#======================================================================== |
115
|
|
|
|
|
|
|
# ----- PRIVATE METHODS ----- |
116
|
|
|
|
|
|
|
#======================================================================== |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
#======================================================================== |
119
|
|
|
|
|
|
|
# |
120
|
|
|
|
|
|
|
# sub _error($errmsg, @params) |
121
|
|
|
|
|
|
|
# |
122
|
|
|
|
|
|
|
# Formats the error message format, $errmsg, and any additional parameters, |
123
|
|
|
|
|
|
|
# @params with sprintf and sets $ERROR package variable with the resulting |
124
|
|
|
|
|
|
|
# string. The package variable, $ERROR, is used rather than an object |
125
|
|
|
|
|
|
|
# member because the error reporting may have to deal with constructor |
126
|
|
|
|
|
|
|
# failures where no object is returned. May be called as a package |
127
|
|
|
|
|
|
|
# function or an object method. |
128
|
|
|
|
|
|
|
# |
129
|
|
|
|
|
|
|
#======================================================================== |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub _error { |
132
|
0
|
|
|
0
|
|
|
my $self = shift; |
133
|
0
|
0
|
|
|
|
|
my $msg = ref($self) ? shift : $self; |
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
$ERROR = defined($msg) |
136
|
|
|
|
|
|
|
? sprintf($msg, @_) |
137
|
|
|
|
|
|
|
: undef; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 NAME |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Text::MetaText::Directive - MetaText Directive object class. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 SYNOPSIS |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
use Text::MetaText::Directive; |
152
|
|
|
|
|
|
|
my $directive = Text::MetaText::Directive->new(\%params); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 DESCRIPTION |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Objects of the Text::MetaText::Directive class are instantiated by the |
157
|
|
|
|
|
|
|
Text::MetaText::Factory class from within the Text::MetaText module. |
158
|
|
|
|
|
|
|
The Factory and Directive classes can be sub-classed to create a more |
159
|
|
|
|
|
|
|
specific processing system. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 AUTHOR |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Andy Wardley Eabw@kfs.orgE |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
See also: |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
http://www.kfs.org/~abw/ |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 REVISION |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$Revision: 0.4 $ |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 COPYRIGHT |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Copyright (c) 1996-1998 Andy Wardley. All Rights Reserved. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
178
|
|
|
|
|
|
|
under the terms of the Perl Artistic License. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 SEE ALSO |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
For more information, see the main Text::MetaText documentation: |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
perldoc Text::MetaText |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
For more information about the author and other Perl development work: |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
http://www.kfs.org/~abw/ |
189
|
|
|
|
|
|
|
http://www.kfs.org/~abw/perl/ |
190
|
|
|
|
|
|
|
http://www.cre.canon.co.uk/perl/ |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
For more information about Perl in general: |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
http://www.perl.com/ |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|