lib/NewsClipper/TagParser.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 48 CC 4 SCAR 23.0
CC
4
Cov
0%
start
20.0
parse
2.0
BEGIN
2.0
CRAP 10.0
1 # -*- mode: Perl; -*-
2  
3 # This is a small parser for the newsclipper tags. The main parser is below.
4  
5 package NewsClipper::TagParser;
6  
7 use strict;
8 use HTML::Parser;
9  
10 use vars qw( @ISA $VERSION );
11 @ISA = qw(HTML::Parser);
12  
13 use NewsClipper::Globals;
14  
15 # ------------------------------------------------------------------------------
16  
17 # Stores News Clipper commands as they are parsed
18 my @_commandList;
19  
20 # ------------------------------------------------------------------------------
21  
22 sub parse
23 {
24 my $self = shift;
25 my $text = shift;
26  
27 undef @_commandList;
28  
29 $self->SUPER::parse($text);
30  
31 return @_commandList;
32 }
33  
34 # ------------------------------------------------------------------------------
35  
36 sub start
37 {
38 my $self = shift @_;
39 my $originalText = pop @_;
40  
41 my ($tag, $attributeList) = @_;
42  
43 # Make sure all the attributes are lower case
44 foreach my $attribute (keys %$attributeList)
45 {
46 if (lc($attribute) ne $attribute)
47 {
48 $attributeList->{lc($attribute)} = $attributeList->{$attribute};
49 delete $attributeList->{$attribute};
50 }
51 }
52  
53 $errors{'tagparser'} .=
54 "A News Clipper command must have a \"name\" attribute.\n" and return
55 unless defined $attributeList->{name};
56  
57 if ($tag =~ /(input|filter|output)/)
58 {
59 push @_commandList,[$tag,$attributeList];
60 }
61 else
62 {
63 $errors{'tagparser'} .=
64 "Invalid News Clipper command \"$tag\" seen in input file.\n";
65 }
66 }
67  
68 1;