blib/lib/HTML/ExtractText/Extra.pm

filter: Statementstmt 100% 45 / 45 Branchbran 77.7% 14 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 94.7% 72 / 76 CC 12 SCAR 14.3
CC
12
Cov
94%
_extract
8.1
new
3.0
whitespace
2.0
CRAP 4.2
↑ Summary
1 package HTML::ExtractText::Extra;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '1.001004'; # VERSION
7  
8 2 ▶use parent 'HTML::ExtractText';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Devel::TakeHashArgs;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 ▶sub new {
Subroutine new: called CC=3 SCAR=11.1
Pod documented
14 6 my $class = shift;
15  
16 6 ▶ get_args_as_hash( \@_, \ my %args,
Branch: 1 branch
BranchTrueFalseTotal
get_args_as_hash(\@_, \my %args, {"whitespace", 1, "nbsp", 1}) or croak($@) 6 0 6
17 { # these are optional with defaults
18 whitespace => 1,
19 nbsp => 1,
20 },
21 ) or croak $@;
22  
23 6 my $self = $class->SUPER::new;
24  
25 6 $self->$_( $args{$_} ) for keys %args;
26  
27 6 return $self;
28 }
29  
30 7 ▶sub _extract {
Subroutine _extract: called CC=8 SCAR=20.9
31 7 my ( $self, $dom, $selector, $what ) = @_;
32  
33 7 my $want = $what->{ $selector };
34 7 my $find = $want;
35  
36 7 ▶ if ( ref $want eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $want eq "ARRAY") 4 3 7
37 4 $find = $want->[0];
38 }
39  
40 7 ▶ my @results = $dom->find( $find )->map(sub{ $self->_process })->each;
Subroutine __ANON__: called CC=1 SCAR=0.0
41  
42 7 for ( @results ) {
43 9 ▶ $self->nbsp and tr/\x{00A0}/ /;
Branch: 1 branch
BranchTrueFalseTotal
$self->nbsp and tr/\240/ / 9 0 9
44 9 ▶ $self->whitespace and s/^\s+|\s+$//g;
Branch: 1 branch
BranchTrueFalseTotal
$self->whitespace and s/^\s+|\s+$//g 9 0 9
45 9 ▶ if ( ref $want eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $want eq "ARRAY") 4 5 9
46 4 ▶ if ( ref $want->[1] eq 'Regexp' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $want->[1] eq 'Regexp') { } 2 2 4
elsif (ref $want->[1] eq 'CODE') { } 2 0 2
47 2 s/$want->[1]//g;
48 }
49 elsif ( ref $want->[1] eq 'CODE' ) {
50 2 $_ = $want->[1]->( $_ );
51 }
52 }
53 }
54  
55 7 return @results;
56 }
57  
58 19 ▶sub whitespace {
Subroutine whitespace: called CC=2 SCAR=6.9
Pod documented
59 19 my $self = shift;
60 19 ▶ if ( @_ ) { $self->[0]->{WHITESPACE} = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 7 12 19
61 19 return $self->[0]->{WHITESPACE};
62 }
63  
64 19 ▶sub nbsp {
Subroutine nbsp: called CC=2 SCAR=6.9
Pod documented
65 19 my $self = shift;
66 19 ▶ if ( @_ ) { $self->[0]->{nbsp} = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 7 12 19
67 19 return $self->[0]->{nbsp};
68 }
69  
70 2 q|
71 I called the janitor the other day to see what he could do about my
72 dingy linoleum floor. He said he would have been happy to loan me a
73 polisher, but that he hadn't the slightest idea what he had done with
74 it. I told him not to worry about it--that as a programmer
75 it wasn't the first time I had experienced a buffer
76 allocation failure due to a memory error.
77 |;
78  
79 __END__
↑ Summary