From: Ed A. <ep...@us...> - 2002-01-29 13:30:14
|
Update of /cvsroot/xmltv/xmltv In directory usw-pr-cvs1:/tmp/cvs-serv1476 Modified Files: XMLTV.pm Log Message: Factored out going through @Handlers when reading a <programme> element into its own subroutine call_handlers_read(). This is because I plan to use the same method for reading channels. Index: XMLTV.pm =================================================================== RCS file: /cvsroot/xmltv/xmltv/XMLTV.pm,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** XMLTV.pm 2002/01/28 12:42:14 1.16 --- XMLTV.pm 2002/01/29 13:30:10 1.17 *************** *** 87,93 **** } ! t 'going through each child of programme'; ! # Current position in Handlers. We expect to read the subelements # in the correct order as specified by the DTD. # --- 87,117 ---- } ! call_handlers_read($node, \@Handlers, \%programme); ! return \%programme; ! } ! ! # Private. ! # ! # call_handlers_read() ! # ! # Read the subelements of a DOM node according to a list giving a ! # handler subroutine for each subelement. ! # ! # Parameters: ! # DOM node ! # Reference to list of handlers: tuples of ! # [element-name, reader, writer, multiplicity] ! # Reference to hash for storing results ! # ! # Warns if errors, but attempts to contine. ! # ! sub call_handlers_read( $$$ ) { ! my ($node, $handlers, $r) = @_; ! die unless ref($r) eq 'HASH'; ! use vars '%r'; local *r = $r; ! t 'going through each child of node'; ! ! # Current position in handlers. We expect to read the subelements # in the correct order as specified by the DTD. # *************** *** 104,114 **** my $found_pos; foreach my $i (0 .. $handler_pos - 1) { ! if ($name eq $Handlers[$i]->[0]) { warn "element $name not expected here"; next SUBELEMENT; } } ! for (my $i = $handler_pos; $i < @Handlers; $i++) { ! if ($Handlers[$i]->[0] eq $name) { t 'found handler'; $found_pos = $i; --- 128,138 ---- my $found_pos; foreach my $i (0 .. $handler_pos - 1) { ! if ($name eq $handlers->[$i]->[0]) { warn "element $name not expected here"; next SUBELEMENT; } } ! for (my $i = $handler_pos; $i < @$handlers; $i++) { ! if ($handlers->[$i]->[0] eq $name) { t 'found handler'; $found_pos = $i; *************** *** 116,122 **** } else { ! t "doesn't match name $Handlers[$i]->[0]"; my ($handler_name, $r, $w, $multiplicity) ! = @{$Handlers[$i]}; die if not defined $handler_name; die if $handler_name eq ''; --- 140,146 ---- } else { ! t "doesn't match name $handlers->[$i]->[0]"; my ($handler_name, $r, $w, $multiplicity) ! = @{$handlers->[$i]}; die if not defined $handler_name; die if $handler_name eq ''; *************** *** 129,133 **** } elsif ($multiplicity eq '') { ! if (not defined $programme{$handler_name}) { warn "no element $handler_name found"; } --- 153,157 ---- } elsif ($multiplicity eq '') { ! if (not defined $r{$handler_name}) { warn "no element $handler_name found"; } *************** *** 138,145 **** } elsif ($multiplicity eq '+') { ! if (not defined $programme{$handler_name}) { warn "no element $handler_name found"; } ! elsif (not @{$programme{$handler_name}}) { warn "strangely, empty list for $handler_name"; } --- 162,169 ---- } elsif ($multiplicity eq '+') { ! if (not defined $r{$handler_name}) { warn "no element $handler_name found"; } ! elsif (not @{$r{$handler_name}}) { warn "strangely, empty list for $handler_name"; } *************** *** 160,164 **** t 'calling handler'; my ($handler_name, $reader, $writer, $multiplicity) ! = @{$Handlers[$found_pos]}; die if $handler_name ne $name; my $result = $reader->($_); --- 184,188 ---- t 'calling handler'; my ($handler_name, $reader, $writer, $multiplicity) ! = @{$handlers->[$found_pos]}; die if $handler_name ne $name; my $result = $reader->($_); *************** *** 171,179 **** if ($multiplicity eq '?' or $multiplicity eq '') { warn "seen $name twice" ! if defined $programme{$name}; ! $programme{$name} = $result; } elsif ($multiplicity eq '*' or $multiplicity eq '+') { ! push @{$programme{$name}}, $result; } else { --- 195,203 ---- if ($multiplicity eq '?' or $multiplicity eq '') { warn "seen $name twice" ! if defined $r{$name}; ! $r{$name} = $result; } elsif ($multiplicity eq '*' or $multiplicity eq '+') { ! push @{$r{$name}}, $result; } else { *************** *** 181,186 **** } } - - return \%programme; } --- 205,208 ---- |