File Coverage

lib/LEOCHARRE/HTML/Rip.pm
Criterion Covered Total %
statement 21 21 100.0
branch 4 6 66.6
condition 4 9 44.4
subroutine 4 4 100.0
pod 1 2 50.0
total 34 42 80.9


line stmt bran cond sub pod time code
1             package LEOCHARRE::HTML::Rip;
2 2     2   29631 use strict;
  2         3  
  2         79  
3 2     2   11 use vars qw(@EXPORT_OK %EXPORT_TAGS $VERSION @ISA);
  2         3  
  2         780  
4             $VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)/g;
5             @ISA = qw/Exporter/;
6             @EXPORT_OK = qw(find_tag rip_tag);
7             %EXPORT_TAGS = ( all => \@EXPORT_OK );
8              
9              
10              
11              
12              
13             sub find_tag {
14 12     12 1 14176 my($html,$tag)=@_;
15 12 50 33     92 $html and $tag or die;
16              
17              
18              
19            
20 12         17 my @return;
21 12         12648 while( $html=~/(<$tag[^<>]*>(.*?)<\/$tag>)/sig ){ # this minimal matching works right
22 128         6062 push @return, $1;
23             }
24            
25 12 100 66     85 if( !@return or (scalar @return == 0) ){
26             #maybe it's a single
27 4         320 while( $html=~/(<$tag[^<>]*\/>)/sig ){
28 26         2507 push @return, $1;
29             }
30             }
31            
32              
33 12         117 return @return;
34             }
35              
36              
37             sub rip_tag {
38 7     7 0 859 my($html,$tag) =@_;
39 7 50 33     58 $html and $tag or die;
40 7         31 my @have = find_tag($html,$tag);
41 7         25 for my $what (@have) {
42 98         5339 $html=~s/\Q$what\E//s;
43             }
44 7         213 return $html;
45             }
46              
47              
48             1;
49              
50             __END__