File Coverage

blib/lib/HTML/ExtractText/Extra.pm
Criterion Covered Total %
statement 37 37 100.0
branch 13 16 81.2
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 61 64 95.3


line stmt bran cond sub pod time code
1             package HTML::ExtractText::Extra;
2              
3 1     1   22739 use strict;
  1         2  
  1         25  
4 1     1   3 use warnings;
  1         2  
  1         30  
5              
6             our $VERSION = '1.001002'; # VERSION
7              
8 1     1   338 use parent 'HTML::ExtractText';
  1         205  
  1         4  
9              
10             sub new {
11 3     3 1 967 my $class = shift;
12 3         15 my $self = $class->SUPER::new( @_ );
13 3         173 $self->whitespace(1);
14 3         5 $self->nbsp(1);
15 3         5 return $self;
16             }
17              
18             sub _extract {
19 3     3   663 my ( $self, $dom, $selector, $what ) = @_;
20              
21 3         4 my $want = $what->{ $selector };
22 3         3 my $find = $want;
23              
24 3 100       8 if ( ref $want eq 'ARRAY' ) {
25 2         3 $find = $want->[0];
26             }
27              
28 3     4   8 my @results = $dom->find( $find )->map(sub{ $self->_process })->each;
  4         790  
29              
30 3         254 for ( @results ) {
31 4 50       5 $self->nbsp and tr/\x{00A0}/ /;
32 4 50       8 $self->whitespace and s/^\s+|\s+$//g;
33 4 100       9 if ( ref $want eq 'ARRAY' ) {
34 2 100       8 if ( ref $want->[1] eq 'Regexp' ) {
    50          
35 1         7 s/$want->[1]//g;
36             }
37             elsif ( ref $want->[1] eq 'CODE' ) {
38 1         3 $_ = $want->[1]->( $_ );
39             }
40             }
41             }
42              
43 3         12 return @results;
44             }
45              
46             sub whitespace {
47 8     8 1 5 my $self = shift;
48 8 100       15 if ( @_ ) { $self->[0]->{WHITESPACE} = shift; }
  3         4  
49 8         21 return $self->[0]->{WHITESPACE};
50             }
51              
52             sub nbsp {
53 8     8 1 8 my $self = shift;
54 8 100       16 if ( @_ ) { $self->[0]->{nbsp} = shift; }
  3         4  
55 8         16 return $self->[0]->{nbsp};
56             }
57              
58             q|
59             I called the janitor the other day to see what he could do about my
60             dingy linoleum floor. He said he would have been happy to loan me a
61             polisher, but that he hadn't the slightest idea what he had done with
62             it. I told him not to worry about it--that as a programmer
63             it wasn't the first time I had experienced a buffer
64             allocation failure due to a memory error.
65             |;
66              
67             __END__