| 1 | package WebSource; | ||||||||||||||||||||||||||||||||||||
| 2 | 2 | our $REVSTR = '$Revision: 1.13 $'; | |||||||||||||||||||||||||||||||||||
| 3 | 2 | $REVSTR =~ m/Revision: ([^ ]+)/; | |||||||||||||||||||||||||||||||||||
| 4 | 2 | our $REVISION = $1; | |||||||||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION='2.4.5'; | |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use HTTP::Cookies; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use WebSource::Parser; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use WebSource::Envelope; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | 2 | our $NameSpace = 'http://wwwsource.free.fr/ns/websource'; | |||||||||||||||||||||||||||||||||||
| 18 | 2 | our %ModClass = ( | |||||||||||||||||||||||||||||||||||
| 19 | "fetch" => 'WebSource::Fetcher', | ||||||||||||||||||||||||||||||||||||
| 20 | "extract" => 'WebSource::Extract', | ||||||||||||||||||||||||||||||||||||
| 21 | "filter" => 'WebSource::Filter', | ||||||||||||||||||||||||||||||||||||
| 22 | "query" => 'WebSource::Query', | ||||||||||||||||||||||||||||||||||||
| 23 | "format" => 'WebSource::Format', | ||||||||||||||||||||||||||||||||||||
| 24 | "xmlparser" => 'WebSource::XMLParser', | ||||||||||||||||||||||||||||||||||||
| 25 | "cache" => 'WebSource::Cache', | ||||||||||||||||||||||||||||||||||||
| 26 | "soap" => 'WebSource::Soap', | ||||||||||||||||||||||||||||||||||||
| 27 | "database" => 'WebSource::DB', | ||||||||||||||||||||||||||||||||||||
| 28 | "map" => 'WebSource::Map', | ||||||||||||||||||||||||||||||||||||
| 29 | "dummy" => 'WebSource::Module', | ||||||||||||||||||||||||||||||||||||
| 30 | "file" => 'WebSource::File', | ||||||||||||||||||||||||||||||||||||
| 31 | "xmlsender" => 'WebSource::XMLSender', | ||||||||||||||||||||||||||||||||||||
| 32 | "meta-tag" => 'WebSource::MetaTag' | ||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||
| 36 | =head1 NAME | ||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||
| 38 | WebSource - a general data wrapping tool particularly well suited for online data | ||||||||||||||||||||||||||||||||||||
| 39 | (but what data in not online in some way today ;) ) | ||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||
| 41 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||
| 43 | WebSource gives a general and normalized framework way to access | ||||||||||||||||||||||||||||||||||||
| 44 | data made available via the web. An access to subparts of the | ||||||||||||||||||||||||||||||||||||
| 45 | Web is made by defining a task. This task is built by composing | ||||||||||||||||||||||||||||||||||||
| 46 | query building, extraction, fetching and filtering subtasks. | ||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||
| 48 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||
| 50 | $source = WebSource->new(wsd => $description); | ||||||||||||||||||||||||||||||||||||
| 51 | @results = $source->query($query); | ||||||||||||||||||||||||||||||||||||
| 52 | or | ||||||||||||||||||||||||||||||||||||
| 53 | $result = $source->set_query($query); | ||||||||||||||||||||||||||||||||||||
| 54 | while($result = $source->next_result()) { | ||||||||||||||||||||||||||||||||||||
| 55 | ... | ||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||
| 58 | =head1 ABSTRACT | ||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||
| 60 | WebSource originally was a generic wrapper around a Web Source. | ||||||||||||||||||||||||||||||||||||
| 61 | Given an XML description of a source it allows to query the source | ||||||||||||||||||||||||||||||||||||
| 62 | and retreive its results. The format of the query and the result | ||||||||||||||||||||||||||||||||||||
| 63 | remain source dependant however. | ||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||
| 65 | It is now configurable enough allow to do complex tasks on the web : such as | ||||||||||||||||||||||||||||||||||||
| 66 | fetching, extracting, filtering data one the Web. Each complex task is | ||||||||||||||||||||||||||||||||||||
| 67 | described by an XML task description file (WebSource description). This task | ||||||||||||||||||||||||||||||||||||
| 68 | is decomposed into simple subtasks of different flavors. | ||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||
| 70 | Existing subtask flavors are : | ||||||||||||||||||||||||||||||||||||
| 71 | - B<extract> | ||||||||||||||||||||||||||||||||||||
| 72 | I<input> an XML::LibXML::Document | ||||||||||||||||||||||||||||||||||||
| 73 | I<output> an XML::LibXML::Node | ||||||||||||||||||||||||||||||||||||
| 74 | Applys an Xpath on the document and returns the set of nodes | ||||||||||||||||||||||||||||||||||||
| 75 | - B<fetch> | ||||||||||||||||||||||||||||||||||||
| 76 | I<input> a URL (or XML::LibXML::Node containing a url) | ||||||||||||||||||||||||||||||||||||
| 77 | I<output> an XML::LibXML::Document | ||||||||||||||||||||||||||||||||||||
| 78 | - B<format> | ||||||||||||||||||||||||||||||||||||
| 79 | I<input> an XML::Document | ||||||||||||||||||||||||||||||||||||
| 80 | I<output> a string | ||||||||||||||||||||||||||||||||||||
| 81 | - B<filter> | ||||||||||||||||||||||||||||||||||||
| 82 | I<input> anything | ||||||||||||||||||||||||||||||||||||
| 83 | I<output> anything (but not all) | ||||||||||||||||||||||||||||||||||||
| 84 | - B<external> | ||||||||||||||||||||||||||||||||||||
| 85 | This type of subtask uses an external perl module as a task. | ||||||||||||||||||||||||||||||||||||
| 86 | This allows to define highly configurable tasks. | ||||||||||||||||||||||||||||||||||||
| 87 | I<input> depends on external module | ||||||||||||||||||||||||||||||||||||
| 88 | I<output> depends on external module | ||||||||||||||||||||||||||||||||||||
| 89 | - B<meta-tag> | ||||||||||||||||||||||||||||||||||||
| 90 | I<input> anything | ||||||||||||||||||||||||||||||||||||
| 91 | I<output> anything (with updated meta-data) | ||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||
| 93 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||
| 95 | =over 2 | ||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||
| 97 | =item B<< $source = WebSource->new(wsd => $wsd); >> | ||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||
| 99 | Create a new WebSource object working with the given a WebSource description | ||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||
| 101 | The following named paramters can be given : | ||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||
| 103 | =over 2 | ||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||
| 105 | =item C<wsd> | ||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||
| 107 | Use a generic engine with the given source description file | ||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||
| 109 | =item C<max_results> | ||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||
| 111 | Do not output more than max_results | ||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||
| 113 | =back | ||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||
| 115 | =cut | ||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||
| 119 | 0 | my %param = @_; | |||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | $param{wsd} or croak("No WebSource description given"); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 121 | $param{useragent} or $param{useragent} = | ||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | LWP::UserAgent->new( | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 123 | agent => "WebSource/1.0", | ||||||||||||||||||||||||||||||||||||
| 124 | keep_alive => 1, | ||||||||||||||||||||||||||||||||||||
| 125 | timeout => 30, | ||||||||||||||||||||||||||||||||||||
| 126 | requests_redirectable => ['GET', 'HEAD', 'POST'], | ||||||||||||||||||||||||||||||||||||
| 127 | env_proxy => 1, | ||||||||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | $param{cookies} or $param{cookies} = HTTP::Cookies->new; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 130 | 0 | $param{useragent}->cookie_jar($param{cookies}); | |||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | $param{maxreqinterval} or $param{maxreqinterval} = 3; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | $param{maxtries} or $param{maxtries} = 3; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | $param{parser} or $param{parser} = XML::LibXML->new; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 134 | 0 | $param{parser}->expand_xinclude(1); | |||||||||||||||||||||||||||||||||||
| 135 | 0 | $param{result_count} = 0; | |||||||||||||||||||||||||||||||||||
| 136 | 0 | my $self = bless \%param, $class; | |||||||||||||||||||||||||||||||||||
| 137 | 0 | $self->_init; | |||||||||||||||||||||||||||||||||||
| 138 | 0 | return $self; | |||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_init: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 143 | 0 | my $wsd = $self->{wsd}; | |||||||||||||||||||||||||||||||||||
| 144 | 0 | my $doc = $self->load_wsd($wsd); | |||||||||||||||||||||||||||||||||||
| 145 | 0 | $self->{wsddoc} = $doc; | |||||||||||||||||||||||||||||||||||
| 146 | 0 | $self->apply_imports; | |||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub load_wsd { | ||||||||||||||||||||||||||||||||||
|
Subroutine
load_wsd: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 150 | 0 | my ($self, $wsd, $base) = @_; | |||||||||||||||||||||||||||||||||||
| 151 | 0 | my $parser = $self->{parser}; | |||||||||||||||||||||||||||||||||||
| 152 | 0 | my $doc; | |||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if($base) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | if(-f $base) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 155 | 0 | my @path = File::Spec->splitpath(); | |||||||||||||||||||||||||||||||||||
| 156 | 0 | pop @path; | |||||||||||||||||||||||||||||||||||
| 157 | 0 | $base = File::Spec->catpath(@path); | |||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | $wsd = $base ? File::Spec->rel2abs($wsd,$base) : File::Spec->rel2abs($wsd); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||
| 161 | 0 | $self->log(2,"Loading " .$wsd); | |||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | if(-f $wsd) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 163 | 0 | $parser->base_uri("file://" . $wsd); | |||||||||||||||||||||||||||||||||||
| 164 | 0 | $doc = $parser->parse_file($wsd); | |||||||||||||||||||||||||||||||||||
| 165 | 0 | $parser->base_uri(""); | |||||||||||||||||||||||||||||||||||
| 166 | } else { | ||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $resp = $self->{useragent}->get($wsd); | |||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | $resp->is_success or croak "Couldn't download description $wsd"; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 169 | 0 | $parser->base_uri($wsd); | |||||||||||||||||||||||||||||||||||
| 170 | 0 | $doc = $parser->parse_string($resp->content); | |||||||||||||||||||||||||||||||||||
| 171 | 0 | $parser->base_uri(""); | |||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | $doc or croak "Couldn't parse document $wsd"; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 174 | 0 | return $doc; | |||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=28 SCAR=67.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 178 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||
| 180 | 0 | $self->apply_options; | |||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $wsd = $self->{wsd}; | |||||||||||||||||||||||||||||||||||
| 183 | 0 | my $parser = $self->{parser}; | |||||||||||||||||||||||||||||||||||
| 184 | 0 | my $doc = $self->{wsddoc}; | |||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||
| 186 | # | ||||||||||||||||||||||||||||||||||||
| 187 | # Fetch all module descriptions and build the | ||||||||||||||||||||||||||||||||||||
| 188 | # corresponding module | ||||||||||||||||||||||||||||||||||||
| 189 | # | ||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||
| 191 | 0 | my $root = $doc->documentElement; | |||||||||||||||||||||||||||||||||||
| 192 | 0 | my $first; | |||||||||||||||||||||||||||||||||||
| 193 | my $last; | ||||||||||||||||||||||||||||||||||||
| 194 | 0 | my %modules; | |||||||||||||||||||||||||||||||||||
| 195 | 0 | my %forwards; | |||||||||||||||||||||||||||||||||||
| 196 | 0 | my %feedbacks; | |||||||||||||||||||||||||||||||||||
| 197 | 0 | my @nodes = $root->childNodes; | |||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | while (@nodes) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 199 | 0 | my $mnode = shift(@nodes); | |||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | $mnode->nodeType == 1 or next; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | $mnode->namespaceURI eq $NameSpace or next; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 202 | 0 | my $type = $mnode->localname; | |||||||||||||||||||||||||||||||||||
| 203 | 0 | my %params = %$self; | |||||||||||||||||||||||||||||||||||
| 204 | 0 | my $name = $mnode->getAttribute("name"); | |||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | if($mnode->hasAttribute("abort-if-empty")) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 206 | 0 | $params{abortIfEmpty} = ($mnode->getAttribute("abort-if-empty") eq "yes"); | |||||||||||||||||||||||||||||||||||
| 207 | } else { | ||||||||||||||||||||||||||||||||||||
| 208 | 0 | $params{abortIfEmpty} = 0; | |||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if($type eq 'options' || $type eq 'include') { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$type eq "options" or $type eq "include"
MC/DC0%0/2
$type eq "options" or $type eq "include"
$type eq "options"
$type eq "include"
Truth table0%0/3
A or B
A= $type eq "options"B= $type eq "include"
| |||||||||||||||||||||||||||||||||||||
| 211 | # do nothing these are handled seperately | ||||||||||||||||||||||||||||||||||||
| 212 | } elsif($type eq 'init') { | ||||||||||||||||||||||||||||||||||||
| 213 | 0 | my $uri = $mnode->getAttribute("browse"); | |||||||||||||||||||||||||||||||||||
| 214 | 0 | my $resp = $self->{useragent}->get($uri); | |||||||||||||||||||||||||||||||||||
| 215 | 0 | $self->{cookies}->extract_cookies($resp); | |||||||||||||||||||||||||||||||||||
| 216 | ▶ | } elsif($ModClass{$type} || $type eq 'external') { | |||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$WebSource::ModClass{$type} or $type eq "external"
MC/DC0%0/2
$WebSource::ModClass{$type} or $type eq "external"
$WebSource::ModClass{$type}
$type eq "external"
Truth table0%0/3
A or B
A= $WebSource::ModClass{$type}B= $type eq "external"
| |||||||||||||||||||||||||||||||||||||
| 217 | 0 | $self->log(5,"Creating subtask of type ",$type); | |||||||||||||||||||||||||||||||||||
| 218 | 0 | my $class; | |||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if($type eq 'external') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 220 | 0 | $class = $mnode->getAttribute("module"); | |||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | $class or croak("No module declared for external"); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 222 | } else { | ||||||||||||||||||||||||||||||||||||
| 223 | 0 | my $subtype = $mnode->getAttribute("type"); | |||||||||||||||||||||||||||||||||||
| 224 | $class = $subtype ? | ||||||||||||||||||||||||||||||||||||
| 225 | $ModClass{$type} . "::" . $subtype : | ||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | $ModClass{$type}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||
| 228 | 0 | $self->log(5,"Using perl module ",$class); | |||||||||||||||||||||||||||||||||||
| 229 | 0 | eval "require $class"; | |||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if(!$@) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 231 | 0 | $modules{$name} = $class->new( %params, | |||||||||||||||||||||||||||||||||||
| 232 | wsdnode => $mnode, name => $name); | ||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | if($mnode->hasAttribute("forward-to")) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 234 | 0 | $forwards{$name} = $mnode->getAttribute("forward-to"); | |||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if($mnode->hasAttribute("feedback-to")) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 237 | 0 | $feedbacks{$name} = $mnode->getAttribute("feedback-to"); | |||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | $first or $first = $name; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 240 | 0 | $last = $name; | |||||||||||||||||||||||||||||||||||
| 241 | } else { | ||||||||||||||||||||||||||||||||||||
| 242 | 0 | croak("Couldn't load '$class' : $@"); | |||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||
| 244 | } else { | ||||||||||||||||||||||||||||||||||||
| 245 | 0 | $self->log(1,"Module named '$name' is of an unknown type '$type'"); | |||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if(!$first) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 250 | 0 | croak("No modules defined in description file"); | |||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||
| 253 | # | ||||||||||||||||||||||||||||||||||||
| 254 | # Connect the modules to each other | ||||||||||||||||||||||||||||||||||||
| 255 | # | ||||||||||||||||||||||||||||||||||||
| 256 | 0 | foreach my $key (keys(%forwards)) { | |||||||||||||||||||||||||||||||||||
| 257 | 0 | foreach my $other (split(/ /,$forwards{$key})) { | |||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | if($modules{$other}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 259 | 0 | $self->log(5,"Setting $key as producer of $other"); | |||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | $modules{$key} or croak("No module named $key defined"); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 261 | 0 | $modules{$other}->producers($modules{$key}); | |||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||
| 266 | # | ||||||||||||||||||||||||||||||||||||
| 267 | # Configure feed back sending | ||||||||||||||||||||||||||||||||||||
| 268 | # | ||||||||||||||||||||||||||||||||||||
| 269 | 0 | foreach my $key (keys(%feedbacks)) { | |||||||||||||||||||||||||||||||||||
| 270 | 0 | foreach my $other (split(/ /,$feedbacks{$key})) { | |||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if($modules{$other}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 272 | 0 | $self->log(5,"Configuring $key to send feedback to $other"); | |||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | $modules{$key} or croak("No module named $key defined"); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 274 | $modules{$key}->isa('WebSource::Filter') or | ||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | croak($modules{$key}->{name} . " is not a filter"); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 276 | $modules{$other}->can("feedback") or | ||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | croak($modules{$other}->{name} . " doesn't have a feedback method"); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 278 | 0 | $modules{$key}->listeners($modules{$other}); | |||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||
| 284 | # | ||||||||||||||||||||||||||||||||||||
| 285 | # Setup first and last | ||||||||||||||||||||||||||||||||||||
| 286 | # | ||||||||||||||||||||||||||||||||||||
| 287 | 0 | $self->{first} = $modules{$first}; | |||||||||||||||||||||||||||||||||||
| 288 | 0 | $self->{last} = $modules{$last}; | |||||||||||||||||||||||||||||||||||
| 289 | 0 | $self->log(5,"Initial module is $first"); | |||||||||||||||||||||||||||||||||||
| 290 | 0 | $self->log(5,"Final module is $last"); | |||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | sub log { | ||||||||||||||||||||||||||||||||||
|
Subroutine
log: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 296 | 0 | my $level = shift; | |||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if($self->{logger}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 298 | 0 | $self->{logger}->log($level, "[WebSource] ", @_); | |||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||
| 302 | =item B<< $source->push($item); >> | ||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||
| 304 | Pass the initial data to the first subtask | ||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||
| 306 | =cut | ||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | sub push { | ||||||||||||||||||||||||||||||||||
|
Subroutine
push: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 309 | 0 | my ($self) = shift; | |||||||||||||||||||||||||||||||||||
| 310 | 0 | $self->init; | |||||||||||||||||||||||||||||||||||
| 311 | 0 | $self->{first}->push(map { WebSource::Envelope->new(type => "text/string", data => $_) } @_ ); | |||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||
| 314 | =item B<< $source->query($query); >> | ||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||
| 316 | Build a query %hash for the given parameters and push it in | ||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||
| 318 | =cut | ||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | sub query { | ||||||||||||||||||||||||||||||||||
|
Subroutine
query: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 321 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 322 | 0 | $self->init; | |||||||||||||||||||||||||||||||||||
| 323 | 0 | my %query = @_; | |||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | if($query{data}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 325 | 0 | $query{type} = "text/string"; | |||||||||||||||||||||||||||||||||||
| 326 | } else { | ||||||||||||||||||||||||||||||||||||
| 327 | 0 | $query{type} = "empty"; | |||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $env = WebSource::Envelope->new(%query); | |||||||||||||||||||||||||||||||||||
| 330 | 0 | $self->{first}->push($env); | |||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||
| 333 | =item B<< $source->set_max_results($count); >> | ||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||
| 335 | Set the maximum number of results to output to $count | ||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||
| 337 | =cut | ||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | sub set_max_results { | ||||||||||||||||||||||||||||||||||
|
Subroutine
set_max_results: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 340 | 0 | my ($self,$count) = @_; | |||||||||||||||||||||||||||||||||||
| 341 | 0 | $self->{max_results} = $count; | |||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||
| 344 | =item B<< $source->next_result(); >> | ||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||
| 346 | Returns the following result for the task | ||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||
| 348 | =cut | ||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | sub next_result { | ||||||||||||||||||||||||||||||||||
|
Subroutine
next_result: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 351 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if($self->{max_results} && $self->{max_results} <= $self->{cnt_results}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"max_results"} and $self->{"max_results"} <= $self->{"cnt_results"}
MC/DC0%0/2
$self->{"max_results"} and $self->{"max_results"} <= $self->{"cnt_results"}
$self->{"max_results"}
$self->{"max_results"} <= $self->{"cnt_results"}
Truth table0%0/3
A and B
A= $self->{"max_results"}B= $self->{"max_results"} <= $self->{"cnt_results"}
| |||||||||||||||||||||||||||||||||||||
| 353 | 0 | return undef; | |||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||
| 355 | 0 | my $res = $self->{last}->produce; | |||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | $res and ($self->{result_count} += 1); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 357 | 0 | return $res; | |||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||
| 360 | =back | ||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||
| 362 | =item B<< $source->parameters; >> | ||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||
| 364 | Returns a has of the initial tasks parameters | ||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||
| 366 | =cut | ||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | sub parameters { | ||||||||||||||||||||||||||||||||||
|
Subroutine
parameters: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 369 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 370 | 0 | return $self->{first}->parameters; | |||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||
| 373 | =item B<< $source->option_spec; >> | ||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||
| 375 | Returns the spec of the options translated for Getopt::Mixed | ||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||
| 377 | =cut | ||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | sub option_spec { | ||||||||||||||||||||||||||||||||||
|
Subroutine
option_spec: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 380 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 381 | 0 | my $doc = $self->{wsddoc}; | |||||||||||||||||||||||||||||||||||
| 382 | 0 | my $xpc = XML::LibXML::XPathContext->new($doc); | |||||||||||||||||||||||||||||||||||
| 383 | 0 | $xpc->registerNs('ws',$NameSpace); | |||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||
| 385 | 0 | my @spec; | |||||||||||||||||||||||||||||||||||
| 386 | 0 | foreach my $onode ($xpc->findnodes('/ws:source/ws:options/*')) { | |||||||||||||||||||||||||||||||||||
| 387 | 0 | my $name = ""; | |||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if($onode->nodeName() eq "option") { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 389 | 0 | warn("Using option element under ws:options is deprecated. Directly use the options name as element name."); | |||||||||||||||||||||||||||||||||||
| 390 | 0 | $name = $onode->getAttribute("name"); | |||||||||||||||||||||||||||||||||||
| 391 | } else { | ||||||||||||||||||||||||||||||||||||
| 392 | 0 | $name = $onode->nodeName(); | |||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||
| 394 | 0 | my $shortcut = $onode->getAttribute("shortcut"); | |||||||||||||||||||||||||||||||||||
| 395 | 0 | my $type = $onode->getAttribute("type"); | |||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | if($name) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 397 | 0 | my $str = $name; | |||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | if($type eq "string") { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 399 | 0 | $str .= "=s"; | |||||||||||||||||||||||||||||||||||
| 400 | } elsif($type eq "integer") { | ||||||||||||||||||||||||||||||||||||
| 401 | 0 | $str .= "=i"; | |||||||||||||||||||||||||||||||||||
| 402 | } elsif($type eq "float") { | ||||||||||||||||||||||||||||||||||||
| 403 | 0 | $str .= "=f"; | |||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | if($shortcut) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 406 | 0 | $str .= " " . $shortcut . ">" . $name; | |||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||
| 408 | 0 | CORE::push(@spec,($str)); | |||||||||||||||||||||||||||||||||||
| 409 | 0 | $self->log(3,"generated option spec '$str'\n"); | |||||||||||||||||||||||||||||||||||
| 410 | } else { | ||||||||||||||||||||||||||||||||||||
| 411 | 0 | $self->log(1,"unamed option detected."); | |||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||
| 414 | 0 | return @spec; | |||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||
| 417 | =item B<< $source->set_option($opt,$val) >> | ||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||
| 419 | Sets source specific option $opt to value $val | ||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||
| 421 | =cut | ||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | sub set_option { | ||||||||||||||||||||||||||||||||||
|
Subroutine
set_option: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 424 | 0 | my ($self,$opt,$val) = @_; | |||||||||||||||||||||||||||||||||||
| 425 | 0 | $self->log(2,"Setting option $opt to value $val"); | |||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||
| 427 | 0 | my $xpc = XML::LibXML::XPathContext->new($self->{wsddoc}); | |||||||||||||||||||||||||||||||||||
| 428 | 0 | $xpc->registerNs('ws',$NameSpace); | |||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | if(my @optnode = $xpc->findnodes("//ws:options")) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | if (my @nodes = $optnode[0]->getChildrenByTagName($opt)) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | if($nodes[0]->hasChildNodes()) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 433 | 0 | $nodes[0]->firstChild()->setData($val); | |||||||||||||||||||||||||||||||||||
| 434 | } else { | ||||||||||||||||||||||||||||||||||||
| 435 | 0 | $nodes[0]->appendText($val); | |||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||
| 437 | } else { | ||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $nn = $self->{wsddoc}->createElement($opt); | |||||||||||||||||||||||||||||||||||
| 439 | 0 | $nn->appendText($val); | |||||||||||||||||||||||||||||||||||
| 440 | 0 | $optnode[0]->appendChild($nn); | |||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||
| 442 | } else { | ||||||||||||||||||||||||||||||||||||
| 443 | 0 | croak("Setting option while ws:options node is absent"); | |||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||
| 448 | =item B<< $source->apply_imports >> | ||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||
| 450 | Handles node of type <ws:import href="" /> by inserting nodes from the wsd file referenced by href | ||||||||||||||||||||||||||||||||||||
| 451 | into (imported document) into the current wsd document (target document). | ||||||||||||||||||||||||||||||||||||
| 452 | A node is inserted from the imported document into the target document only if a node with the same | ||||||||||||||||||||||||||||||||||||
| 453 | name does not exist in the target document. | ||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||
| 455 | =cut | ||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | sub apply_imports { | ||||||||||||||||||||||||||||||||||
|
Subroutine
apply_imports: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 458 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||
| 459 | 0 | my $doc = $self->{wsddoc}; | |||||||||||||||||||||||||||||||||||
| 460 | 0 | my $xpc = XML::LibXML::XPathContext->new($doc); | |||||||||||||||||||||||||||||||||||
| 461 | 0 | $xpc->registerNs('ws',$NameSpace); | |||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||
| 463 | 0 | my @import_nodes = $xpc->findnodes("//ws:import"); | |||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | while(@import_nodes) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 465 | 0 | my $im_node = shift @import_nodes; | |||||||||||||||||||||||||||||||||||
| 466 | 0 | my $im_par = $im_node->parentNode; | |||||||||||||||||||||||||||||||||||
| 467 | 0 | my $im_wsd = $im_node->getAttribute("href"); | |||||||||||||||||||||||||||||||||||
| 468 | 0 | $self->log(2,"Processing import of ".$im_wsd); | |||||||||||||||||||||||||||||||||||
| 469 | 0 | my $im_doc = $self->load_wsd($im_wsd,$self->{wsd}); | |||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||
| 471 | 0 | foreach my $el ($im_doc->documentElement->childNodes) { | |||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | $el->nodeType == 1 or next; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 473 | 0 | my $nodeType = $el->localName; | |||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | if($nodeType eq 'options') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 475 | # If options have not been locally redefined import them | ||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | if(!$xpc->exists('//ws:options')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 477 | 0 | $im_par->insertBefore($el,$im_node); | |||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||
| 479 | } else { | ||||||||||||||||||||||||||||||||||||
| 480 | 0 | my $name = $el->getAttribute("name"); | |||||||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | if(!$xpc->exists('//*[@name="' . $name . '"]')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 482 | 0 | $im_par->insertBefore($el,$im_node); | |||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||
| 486 | 0 | $im_par->removeChild($im_node); | |||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||
| 490 | =item B<< $source->apply_options >> | ||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||
| 492 | Handles node of type <ws:attribute name="aname" value="oname" /> by adding | ||||||||||||||||||||||||||||||||||||
| 493 | and attribut name aname with the value of the option named oname | ||||||||||||||||||||||||||||||||||||
| 494 | to the parent node. The ws:attribute node is then removed. | ||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||
| 496 | =cut | ||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | sub apply_options { | ||||||||||||||||||||||||||||||||||
|
Subroutine
apply_options: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 499 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||
| 500 | 0 | my $doc = $self->{wsddoc}; | |||||||||||||||||||||||||||||||||||
| 501 | 0 | my $xpc = XML::LibXML::XPathContext->new($doc); | |||||||||||||||||||||||||||||||||||
| 502 | 0 | $xpc->registerNs('ws',$NameSpace); | |||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||
| 504 | 0 | my @optnode = $xpc->findnodes("//ws:options"); | |||||||||||||||||||||||||||||||||||
| 505 | 0 | foreach my $sa ($xpc->findnodes("//ws:set-attribute")) { | |||||||||||||||||||||||||||||||||||
| 506 | 0 | my $p = $sa->parentNode; | |||||||||||||||||||||||||||||||||||
| 507 | 0 | my $aname = $sa->getAttribute("name"); | |||||||||||||||||||||||||||||||||||
| 508 | 0 | my $oexpr = $sa->getAttribute("value-of"); | |||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | if($oexpr eq "") { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 510 | 0 | $self->log(1,"Warning : Empty value-of attribute on ws:set-attribute"); | |||||||||||||||||||||||||||||||||||
| 511 | } else { | ||||||||||||||||||||||||||||||||||||
| 512 | 0 | my $oval = $optnode[0]->findvalue($oexpr); | |||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | if($oval) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 514 | 0 | $p->setAttribute($aname,$oval); | |||||||||||||||||||||||||||||||||||
| 515 | } else { | ||||||||||||||||||||||||||||||||||||
| 516 | 0 | $self->log(1,"Warning : Expr '$oexpr' has no value"); | |||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||
| 518 | 0 | $p->removeChild($sa); | |||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||
| 521 | 0 | $self->log(6,"After applying options...\n", $doc->toString(1)); | |||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||
| 524 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||
| 526 | ws-query, WebSource::Extract, WebSource::Fetch, WebSource::Filter, etc. | ||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||
| 528 | =cut | ||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||
| 530 | 2 | 1; | |||||||||||||||||||||||||||||||||||