File Coverage

blib/lib/SWISH/API/Remote/Result.pm
Criterion Covered Total %
statement 33 36 91.6
branch 4 6 66.6
condition 2 5 40.0
subroutine 8 9 88.8
pod 2 4 50.0
total 49 60 81.6


line stmt bran cond sub pod time code
1             package SWISH::API::Remote::Result;
2 3     3   20 use SWISH::API::Remote::FunctionGenerator;
  3         5  
  3         81  
3 3     3   2878 use URI::Escape;
  3         5295  
  3         472  
4 3     3   26 use fields qw( properties );
  3         5  
  3         29  
5 3     3   205 use strict;
  3         4  
  3         111  
6 3     3   17 use warnings;
  3         5  
  3         1441  
7              
8             ############################################
9             sub new {
10 11     11 0 13 my $proto = shift;
11 11   33     40 my $class = ref($proto) || $proto;
12 11         18 my $self = {};
13 11         25 bless( $self, $class );
14 11         32 $self->{properties} = {}; # empty hash
15 11         35 return $self;
16             }
17              
18             ############################################
19             sub New_From_Query_String {
20 11     11 0 15 my ( $qs, $resultsprops ) = @_;
21 11         33 my $newobj = new SWISH::API::Remote::Result;
22 11         40 my @parts = split ( /&/, $qs );
23 11         17 for my $p (@parts) {
24 45         83 my ( $n, $v ) = map { uri_unescape($_) } split ( /=/, $p, 2 ); # split, THEN unescape
  90         362  
25 45 100       506 $resultsprops->[$n] = "Unknown$n" unless defined( $resultsprops->[$n] );
26             #warn "Property number $n ( $resultsprops->[$n] ) : value $v\n";
27 45 50       94 if (defined($n)) {
28 45   50     161 $newobj->{properties}{ $resultsprops->[$n] } = $v || "";
29             }
30             }
31              
32             #print Data::Dumper::Dumper($newobj);
33 11         36 return $newobj;
34             }
35              
36             ############################################
37             sub Property {
38 2     2 1 5 my ( $self, $prop ) = @_;
39             #print "Looking up property $prop\n";
40 2 50       16 return exists( $self->{properties} ) ? $self->{properties}{$prop} : "";
41             }
42              
43             ############################################
44             sub Properties {
45 0     0 1   my $self = shift;
46 0           return sort(keys( %{ $self->{properties} } )); # we sort so the order is consistent
  0            
47             }
48              
49             1;
50              
51             __END__