From: <hon...@gm...> - 2013-12-27 19:09:29
|
The Supplement handler is only capable of returning a slurped string. I've looked at all the grabbers which use Supplement and the first thing they all do is split the lines out of the string (and ignore comments etc). Now I know it's only a few lines of code but I have counted at least 3 different variations in the grabbers, so it would be good to standardize the task. So I propose a GetSupplementLines() method which returns a ref to an array rather than a unstructured string. It does mean that the array is traversed twice but I think that's only a small overhead, and it makes the grabber's code cleaner by not having to worry about comments etc.. --- S:/CVS/xmltv/lib/Supplement.pm.in Tue Jun 21 03:35:07 2011 +++ S:/CVS/!temp/Supplement.pm.in Fri Dec 27 18:51:34 2013 @@ -9,7 +9,7 @@ @ISA = qw(Exporter); @EXPORT = qw( ); %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], - @EXPORT_OK = qw/GetSupplement SetSupplementRoot/; + @EXPORT_OK = qw/GetSupplement GetSupplementLines SetSupplementRoot/; } our @EXPORT_OK; @@ -148,6 +148,33 @@ } return $result; +} + +=item GetSupplementLines + +Load a supplement file and return it as an array. Any comments or blank lines +will be removed. Takes two parameters: directory and filename. + + my $content = GetSupplementLines( 'tv_grab_uk_rt', 'channel_ids' ); + +GetSupplementLines will always return an array with the content. If it fails +to get the content, it prints an error-message and aborts the program. + +=cut + +sub GetSupplementLines { + my $supplement_string = GetSupplement( @_ ); + my @supplement_array; + my @supplement_lines = split( /\n+/, $supplement_string ); + foreach ( @supplement_lines ) { + tr/\r//d; # strip CRs + s/#.*//; # strip comment + next if m/^\s*$/; # ignore blank lines + s/^\s+|\s+$//g; # remove leading & trailing spaces/tabs + push @supplement_array, $_; + } + return \@supplement_array; } sub GetSupplementUrl { |