CheckPad/ListParser.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 56 CC 4 SCAR 17.0
CC
4
Cov
0%
text
12.0
start
6.0
_parse
2.0
CRAP 5.5
1 package WWW::CheckPad::ListParser;
2  
3 use strict;
4 use warnings;
5 use WWW::CheckPad::Parser;
6 use HTML::Parser;
7 use base qw(WWW::CheckPad::Parser);
8  
9  
10 sub _parse {
11 my ($self, $content) = @_;
12
13 $self->param('list', []);
14 $self->parse($content);
15 $self->eof;
16 return $self->param('list');
17 }
18  
19  
20 sub start {
21 my ($self, $tagname, $attr, $attr_array,$source) = @_;
22 if ($tagname eq 'li' and
23 $attr->{id} =~ /^item_/) {
24 $self->param('in_list_tag', 1);
25 $self->param('current_item_id', $attr->{id} =~ /item_(.*)/)
26 }
27 else {
28 $self->param('in_list_tag', 0);
29 }
30 }
31  
32 sub text {
33 my ($self, $text) = @_;
34 if ($self->param('in_list_tag')) {
35 ## Remove space and line-breaks.
36 $text =~ s/^[ \n]+//;
37 $text =~ s/[ \n]+$//;
38 if ($text ne '') {
39 my $list = $self->param('list');
40 push @{$list}, {id=>$self->param('current_item_id'), title=>$text};
41 $self->param('list', $list);
42 }
43 }
44 }
45  
46  
47  
48 1;