File Coverage

blib/lib/WQS/SPARQL/Result.pm
Criterion Covered Total %
statement 36 36 100.0
branch 3 6 50.0
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 48 51 94.1


line stmt bran cond sub pod time code
1             package WQS::SPARQL::Result;
2              
3 4     4   308184 use strict;
  4         41  
  4         111  
4 4     4   22 use warnings;
  4         8  
  4         110  
5              
6 4     4   1393 use Class::Utils qw(set_params);
  4         38069  
  4         121  
7 4     4   279 use Error::Pure qw(err);
  4         9  
  4         138  
8 4     4   2196 use URI;
  4         24817  
  4         1057  
9              
10             our $VERSION = 0.01;
11              
12             sub new {
13 3     3 1 1285 my ($class, @params) = @_;
14              
15             # Create object.
16 3         10 my $self = bless {}, $class;
17              
18             # Process parameters.
19 3         12 set_params($self, @params);
20              
21 3         29 return $self;
22             }
23              
24             sub result {
25 2     2 1 520 my ($self, $result_hr, $vars_ar) = @_;
26              
27 2 50       9 if (! defined $vars_ar) {
28 2         6 $vars_ar = $result_hr->{'head'}->{'vars'};
29             }
30              
31 2         3 my @res;
32 2 50       6 if (exists $result_hr->{'results'}->{'bindings'}) {
33 2         4 my @items = @{$result_hr->{'results'}->{'bindings'}};
  2         6  
34 2         5 foreach my $item_hr (@items) {
35 2         4 my $result_hr;
36 2         3 foreach my $var (@{$vars_ar}) {
  2         4  
37              
38             # TODO Implement other values
39              
40             # QID.
41             # TODO Check real QID, could be another uri.
42 2 50       6 if ($item_hr->{$var}->{'type'} eq 'uri') {
43 2         11 my $qid_uri = URI->new($item_hr->{$var}->{'value'});
44 2         7890 my @segs = $qid_uri->path_segments;
45 2         153 $result_hr->{$var} = $segs[-1];
46             }
47             }
48 2         6 push @res, $result_hr;
49             }
50             }
51              
52 2         21 return @res;
53             }
54              
55             1;
56              
57             __END__