SAC/LexicalUnit.pm

filter: Statementstmt 65.8% 27 / 41 Branchbran 8.3% 1 / 12 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 45.4% 5 / 11 Podpod 100% 6 / 6 totaltotal 53.9% 41 / 76 CC 9 SCAR 14.6
CC
9
Cov
53%
new
6.0
DimensionUnitText
6.0
FunctionName
6.0
CRAP 4.3
« SAC/Selector/CharacterData.pm ↑ Summary SAC/Selector/Negative.pm »
1
2 ###
3 # CSS::SAC::LexicalUnit - SAC units
4 # Robin Berjon <robin@knowscape.com>
5 # 24/02/2001
6 ###
7
8 package CSS::SAC::LexicalUnit;
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶$VERSION = $CSS::SAC::VERSION || '0.03';
Condition50%1/2
$CSS::SAC::VERSION || '0.03'
l!l
02
MC/DC0%0/1
$CSS::SAC::VERSION || '0.03'
$CSS::SAC::VERSION
Truth table50%1/2
A
A= $CSS::SAC::VERSION
Aresult
11
00
12
13 #---------------------------------------------------------------------#
14 # build the fields for an array based object
15 #---------------------------------------------------------------------#
16 2 ▶use Class::ArrayObjects define => {
Subroutine BEGIN: called CC=1 SCAR=0.0
17 fields => [qw(
18 _type_
19 _value_
20 _text_
21 )],
22 2 };
23 #---------------------------------------------------------------------#
24
25
26 ### Constants #########################################################
27 # #
28 # #
29
30
31 sub ATTR () { 1 }
32 sub CENTIMETER () { 2 }
33 sub COUNTER_FUNCTION () { 3 }
34 sub COUNTERS_FUNCTION () { 4 }
35 sub DEGREE () { 5 }
36 sub DIMENSION () { 6 }
37 sub EM () { 7 }
38 sub EX () { 8 }
39 sub FUNCTION () { 9 }
40 sub GRADIAN () { 10 }
41 sub HERTZ () { 11 }
42 sub IDENT () { 12 }
43 sub INCH () { 13 }
44 sub INHERIT () { 14 }
45 sub INTEGER () { 15 }
46 sub KILOHERTZ () { 16 }
47 sub MILLIMETER () { 17 }
48 sub MILLISECOND () { 18 }
49 sub OPERATOR_COMMA () { 19 }
50 sub OPERATOR_EXP () { 20 }
51 sub OPERATOR_GE () { 21 }
52 sub OPERATOR_GT () { 22 }
53 sub OPERATOR_LE () { 23 }
54 sub OPERATOR_LT () { 24 }
55 sub OPERATOR_MINUS () { 25 }
56 sub OPERATOR_MOD () { 26 }
57 sub OPERATOR_MULTIPLY () { 27 }
58 sub OPERATOR_PLUS () { 28 }
59 sub OPERATOR_SLASH () { 29 }
60 sub OPERATOR_TILDE () { 30 }
61 sub PERCENTAGE () { 31 }
62 sub PICA () { 32 }
63 sub PIXEL () { 33 }
64 sub POINT () { 34 }
65 sub RADIAN () { 35 }
66 sub REAL () { 36 }
67 sub RECT_FUNCTION () { 37 }
68 sub RGBCOLOR () { 38 }
69 sub SECOND () { 39 }
70 sub STRING_VALUE () { 40 }
71 sub SUB_EXPRESSION () { 41 }
72 sub UNICODERANGE () { 42 }
73 sub URI () { 43 }
74
75
76
77 #---------------------------------------------------------------------#
78 # import()
79 # all import can do is export the constants
80 #---------------------------------------------------------------------#
81 3 ▶sub import {
Subroutine import: called CC=4 SCAR=13.9
82 3 my $class = shift;
83 3 ▶ my $tag = shift || '';
Condition50%1/2
shift() || ''
l!l
30
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
84
85 # check that we have the right tag
86 3 ▶ return unless $tag eq ':constants';
Branch: 1 branch
BranchTrueFalseTotal
unless $tag eq ":constants" 0 3 3
87
88 # define some useful vars
89 3 my $pkg = caller;
90 3 my @constants = qw(
91 ATTR CENTIMETER COUNTER_FUNCTION COUNTERS_FUNCTION
92 DEGREE DIMENSION EM EX FUNCTION GRADIAN HERTZ
93 IDENT INCH INHERIT INTEGER KILOHERTZ MILLIMETER
94 MILLISECOND OPERATOR_COMMA OPERATOR_EXP OPERATOR_GE
95 OPERATOR_GT OPERATOR_LE OPERATOR_LT OPERATOR_MINUS
96 OPERATOR_MOD OPERATOR_MULTIPLY OPERATOR_PLUS
97 OPERATOR_SLASH OPERATOR_TILDE PERCENTAGE PICA PIXEL
98 POINT RADIAN REAL RECT_FUNCTION RGBCOLOR SECOND
99 STRING_VALUE SUB_EXPRESSION UNICODERANGE URI
100 );
101
102 # now lets create the constants in the caller's package
103 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
104 3 for my $c (@constants) {
105 129 my $qname = "${pkg}::$c";
106 129 *$qname = \&{$c};
107 }
108 }
109 #---------------------------------------------------------------------#
110
111
112 # #
113 # #
114 ### Constants #########################################################
115
116
117 ### Constructor #######################################################
118 # #
119 # #
120
121
122 #---------------------------------------------------------------------#
123 # CSS::SAC::LexicalUnit->new($type,$text,$value)
124 # creates a new sac lexical unit object
125 #---------------------------------------------------------------------#
126 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
127 0 ▶ my $class = ref($_[0])?ref(shift):shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
128 0 my $type = shift;
129 0 my $text = shift;
130 0 my $value = shift;
131
132 # define our fields
133 0 my $self = [];
134 0 $self->[_type_] = $type;
135 0 $self->[_text_] = $text;
136 0 $self->[_value_] = $value;
137
138 0 return bless $self, $class;
139 }
140 #---------------------------------------------------------------------#
141
142
143 # #
144 # #
145 ### Constructor #######################################################
146
147
148
149
150 ### Accessors #########################################################
151 # #
152 # #
153
154 # defined aliases
155 2 *CSS::SAC::LexicalUnit::getDimensionUnitText = \&DimensionUnitText;
156 2 *CSS::SAC::LexicalUnit::getFunctionName = \&FunctionName;
157 2 *CSS::SAC::LexicalUnit::getValue = \&Value;
158 2 *CSS::SAC::LexicalUnit::getLexicalUnitType = \&LexicalUnitType;
159
160 #---------------------------------------------------------------------#
161 # my $dut = $lu->DimensionUnitText
162 # $lu->DimensionUnitText($dut)
163 # get/set the text of the dimension unit (eg cm, px, etc...)
164 #---------------------------------------------------------------------#
165 0 ▶sub DimensionUnitText {
Subroutine DimensionUnitText: not called CC=2 SCAR=17.9
Pod documented
166 0 ▶ (@_==2) ? $_[0]->[_text_] = $_[1] :
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 0 0 0
167 $_[0]->[_text_];
168 }
169 #---------------------------------------------------------------------#
170
171
172 #---------------------------------------------------------------------#
173 # my $fn = $lu->FunctionName
174 # $lu->FunctionName($fn)
175 # get/set the name of the function (eg attr, uri, etc...)
176 #---------------------------------------------------------------------#
177 0 ▶sub FunctionName {
Subroutine FunctionName: not called CC=2 SCAR=17.9
Pod documented
178 0 ▶ (@_==2) ? $_[0]->[_text_] = $_[1] :
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 0 0 0
179 $_[0]->[_text_];
180 }
181 #---------------------------------------------------------------------#
182
183
184 #---------------------------------------------------------------------#
185 # my $value = $lu->Value
186 # $lu->Value($value)
187 # get/set the value of the lu (which may be another lu, or a lu list)
188 #---------------------------------------------------------------------#
189 0 ▶sub Value {
Subroutine Value: not called CC=2 SCAR=17.9
Pod documented
190 0 ▶ (@_==2) ? $_[0]->[_value_] = $_[1] :
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 0 0 0
191 $_[0]->[_value_];
192 }
193 #---------------------------------------------------------------------#
194
195
196 #---------------------------------------------------------------------#
197 # my $type = $lu->LexicalUnitType
198 # $lu->LexicalUnitType($type)
199 # get/set the type of the lu
200 #---------------------------------------------------------------------#
201 0 ▶sub LexicalUnitType {
Subroutine LexicalUnitType: not called CC=2 SCAR=17.9
Pod documented
202 0 ▶ (@_==2) ? $_[0]->[_type_] = $_[1] :
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 0 0 0
203 $_[0]->[_type_];
204 }
205 #---------------------------------------------------------------------#
206
207
208 #---------------------------------------------------------------------#
209 # $lu->is_type($lu_constant)
210 # returns true is this lu is of type $lu_constant
211 #---------------------------------------------------------------------#
212 0 ▶sub is_type {
Subroutine is_type: not called CC=1 SCAR=6.9
Pod documented
213 0 return $_[0]->[_type_] == $_[1];
214 }
215 #---------------------------------------------------------------------#
216
217
218 # #
219 # #
220 ### Accessors #########################################################
221
222
223 2 1;
224 =pod
225
226 =head1 NAME
227
228 CSS::SAC::LexicalUnit - SAC units
229
230 =head1 SYNOPSIS
231
232 use CSS::SAC::LexicalUnit qw(:constants);
233 foo if $lu->is_type(LU_TYPE_CONSTANT);
234
235 =head1 DESCRIPTION
236
237 In the SAC spec, LexicalUnit is a linked list, that is, you only ever
238 hold one LexicalUnit, and you ask for the next of for the previous one
239 when you want to move on.
240
241 Such a model seems awkward, though I'm sure it makes sense somehow in
242 Java, likely for a Java-specific reason.
243
244 In the Perl implementation, I have changed this. A LexicalUnit is an
245 object that stands on it's own and has no next/previous objects.
246 Instead, the $handler->property callback gets called with a
247 LexicalUnitList, which is in fact just an array ref of LexicalUnits.
248
249 We also don't differentiate between IntegerValue, FloatValue, and
250 StringValue, it's always Value in Perl. This also applies to
251 Parameters and SubValues. Both are called as Value and return an array
252 ref of LexicalUnits.
253
254 I added the is_type() method, see CSS::SAC::Condition for advantages
255 of that approach.
256
257 =head1 CONSTANTS
258
259 =over 4
260
261 =item * ATTR
262
263 =item * CENTIMETER
264
265 =item * COUNTER_FUNCTION
266
267 =item * COUNTERS_FUNCTION
268
269 =item * DEGREE
270
271 =item * DIMENSION
272
273 =item * EM
274
275 =item * EX
276
277 =item * FUNCTION
278
279 =item * GRADIAN
280
281 =item * HERTZ
282
283 =item * IDENT
284
285 =item * INCH
286
287 =item * INHERIT
288
289 =item * INTEGER
290
291 =item * KILOHERTZ
292
293 =item * MILLIMETER
294
295 =item * MILLISECOND
296
297 =item * OPERATOR_COMMA
298
299 =item * OPERATOR_EXP
300
301 =item * OPERATOR_GE
302
303 =item * OPERATOR_GT
304
305 =item * OPERATOR_LE
306
307 =item * OPERATOR_LT
308
309 =item * OPERATOR_MINUS
310
311 =item * OPERATOR_MOD
312
313 =item * OPERATOR_MULTIPLY
314
315 =item * OPERATOR_PLUS
316
317 =item * OPERATOR_SLASH
318
319 =item * OPERATOR_TILDE
320
321 =item * PERCENTAGE
322
323 =item * PICA
324
325 =item * PIXEL
326
327 =item * POINT
328
329 =item * RADIAN
330
331 =item * REAL
332
333 =item * RECT_FUNCTION
334
335 =item * RGBCOLOR
336
337 =item * SECOND
338
339 =item * STRING_VALUE
340
341 =item * SUB_EXPRESSION
342
343 =item * UNICODERANGE
344
345 =item * URI
346
347 =back
348
349 =head1 METHODS
350
351 =over
352
353 =item * CSS::SAC::LexicalUnit->new($type,$text,$value) or $lu->new($type,$text,$value)
354
355 Creates a new unit. The $type must be one of the type constants, the
356 text depends on the type of unit (unit text, func name, etc...), and
357 the value is the content of the lu.
358
359 =item * $lu->DimensionUnitText([$dut]) or getDimensionUnitText
360
361 get/set the text of the dimension unit (eg cm, px, etc...)
362
363 =item * $lu->FunctionName([$fn]) or getFunctionName
364
365 get/set the name of the function (eg attr, uri, etc...)
366
367 =item * $lu->Value([$value]) or getValue
368
369 get/set the value of the lu (which may be another lu, or a lu list)
370
371 =item * $lu->LexicalUnitType([$type]) or getLexicalUnitType
372
373 get/set the type of the lu
374
375 =item * $lu->is_type($lu_constant)
376
377 returns true is this lu is of type $lu_constant
378
379 =back
380
381 =head1 AUTHOR
382
383 Robin Berjon <robin@knowscape.com>
384
385 This module is licensed under the same terms as Perl itself.
386
387 =cut
388
389
« SAC/Selector/CharacterData.pm ↑ Summary SAC/Selector/Negative.pm »