WebSource/Map.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 55 CC 2 SCAR 12.0
CC
2
Cov
0%
handle
6.0
_init_
2.0
BEGIN
2.0
CRAP 3.3
1 package WebSource::Map;
2 use strict;
3 use Carp;
4  
5 use WebSource::Module;
6 our @ISA = ('WebSource::Module');
7  
8 =head1 NAME
9  
10 WebSource::Map - Maps data nodes to meta data
11  
12 =head1 DESCRIPTION
13  
14 Allows to select data from the input an set them as meta data for the output
15 results.
16  
17  
18 =head1 SYNOPSIS
19  
20 B<In wsd file...>
21  
22 <ws:filter name="somename" type="tests">
23 <map-to name="meta-name" select="<xpath-expr>" />
24 ...
25 </ws:filter>
26  
27  
28 =head1 METHODS
29  
30 =cut
31  
32 sub _init_ {
33 my $self = shift;
34 $self->SUPER::_init_;
35 $self->{wsdnode} or croak("No description node given");
36 }
37  
38 sub handle {
39 my $self = shift;
40 my $env = shift;
41 $self->log(3,"Testing");
42 $env->type eq "object/dom-node" or return 0; # only works for dom-nodes
43 my @nodes = $self->{wsdnode}->findnodes("map-to");
44 my $data = $env->data;
45 my $match = 0;
46 my $res = 0;
47 $self->log(3,"Found ",scalar(@nodes)," map-to nodes");
48 while(!$match && @nodes) {
49 my $n = shift @nodes;
50 my $mode = $n->getAttribute("mode");
51 my $value;
52 if($mode eq "xml") {
53 my @nodes = $data->findnodes($n->getAttribute("select"));
54 foreach my $node (@nodes) {
55 $value .= $node->toString();
56 }
57 } else {
58 $value = $data->findvalue($n->getAttribute("select"));
59 }
60 my $name = $n->getAttribute("name");
61 $self->log(3,"Setting meta-name ",$name," to ", $value);
62 $env->{$name} = $value;
63 }
64 return $env;
65 }
66  
67 =head1 SEE ALSO
68  
69 B<WebSource>, B<WebSource::Module>
70  
71 =cut
72  
73 1;