WWW/Scraper/Opcode/BODY.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 90 CC 12 SCAR 47.7
CC
12
Cov
0%
scrape
156.0
new
2.0
BEGIN
2.0
CRAP 117.5
1  
2 use strict;
3  
4 package WWW::Scraper::Opcode::BODY;
5 use base qw(WWW::Scraper::Opcode);
6 use vars qw($VERSION);
7  
8 # new() Scraper::Opcode
9 # $cls - Op class
10 # $scaffold - current scaffold
11 # $params - ref to array of parames in the 'OP()' portion of the scaffold.
12 sub new {
13 my ($cls, $scaffold, $params) = @_;
14 my $self = bless {};
15 $self->{'fieldsDiscovered'} = ['background','bgcolor'];
16 return $self;
17 }
18  
19 sub scrape {
20 my ($self, $scraper, $scaffold, $TidyXML, $hit) = @_;
21
22 # This if/else clauses handle the legacy versions of the 'BODY' opcode.
23 my $sub_string = undef;
24 if ( ref($$scaffold[1]) eq 'ARRAY' ) {
25 # This else clause is the only real, new Opcode, version of the 'BODY' opcode.
26 my ($sub_string, $attributes) = $TidyXML->getMarkedTextAndAttributes('BODY');
27 return undef unless $attributes;
28
29 return ($$scaffold[1], $sub_string, $attributes);
30 }
31 elsif ( $$scaffold[1] and $$scaffold[2] ) {
32 ${$TidyXML->asString()} =~ s-$$scaffold[1](.*?)$$scaffold[2]--si; # Strip off the adminstrative clutter at the beginning and end.
33 $sub_string = $1 || '';
34 } elsif ( $$scaffold[1] ) {
35 ${$TidyXML->asString()} =~ s-$$scaffold[1](.*)$-$1-si; # Strip off the adminstrative clutter at the beginning.
36 $sub_string = $1 || '';
37 } elsif ( $$scaffold[2] ) {
38 ${$TidyXML->asString()} =~ s-^(.*?)$$scaffold[2]-$1-si; # Strip off the adminstrative clutter at the end.
39 $sub_string = $1 || '';
40 } else {
41 return undef;
42 }
43
44 # Continuing for the legacy versions of the 'BODY' opcode.
45 if ( $$scaffold[3] && ('ARRAY' ne ref $$scaffold[3]) ) # if next_scaffold is an array ref, then we'll recurse (below)
46 {
47 if ( $sub_string ) {
48 my $binding = $$scaffold[3];
49 my $datParser = $$scaffold[4];
50 $datParser = \&WWW::Scraper::trimTags unless $datParser;
51 if ( $binding eq 'url' )
52 {
53 my $url = new URI::URL(&$datParser($scraper, $hit, $sub_string), $scraper->{_base_url});
54 $url = $url->abs();
55 $hit->plug_url($url);
56 }
57 elsif ( $binding) {
58 my $dat = &$datParser($scraper, $hit, $sub_string);
59 $hit->plug_elem($binding, $dat) if defined $dat;
60 }
61 }
62 }
63  
64 return ($self->_next_scaffold($scaffold), $sub_string, undef);
65 }
66  
67  
68 1;