File Coverage

blib/lib/SWISH/API/Remote/Results.pm
Criterion Covered Total %
statement 32 57 56.1
branch 2 6 33.3
condition 2 7 28.5
subroutine 8 16 50.0
pod 7 12 58.3
total 51 98 52.0


line stmt bran cond sub pod time code
1             package SWISH::API::Remote::Results;
2 3     3   2588 use SWISH::API::Remote::FunctionGenerator;
  3         8  
  3         91  
3 3     3   20 use strict;
  3         6  
  3         111  
4 3     3   18 use warnings;
  3         7  
  3         289  
5              
6             ############################################
7 3     3   3617 use fields qw( results hits errors debugs iterator stopwords );
  3         5610  
  3         21  
8              
9              
10             ############################################
11             # results is a list of SWISH::API::Remote::Result objects,
12             # hits is an int of the number of hits found by swish-e
13             # errors is a list of lines
14             # debugs is a list of debug lines
15             # iterator is for NextResult() and SeekResult()
16             sub new {
17 1     1 1 2 my $proto = shift;
18 1   33     5 my $class = ref($proto) || $proto;
19 1         3 my $self = {};
20 1         3 bless( $self, $class );
21 1         6 $self->{iterator} = 0;
22 1         3 $self->{results} = [];
23 1         3 $self->{errors} = [];
24 1         3 $self->{hits} = 0;
25 1         2 $self->{stopwords} = '';
26             #$self->{headers} = undef;
27 1         3 return $self;
28             }
29              
30              
31             ############################################
32             sub Error {
33 0     0 1 0 my $self = shift;
34 0         0 return scalar( @{ $self->{errors} } );
  0         0  
35             }
36              
37              
38             ############################################
39             sub ErrorString {
40 0     0 1 0 my $self = shift;
41 0         0 return join ( "\n", @{ $self->{errors} } ) . "\n";
  0         0  
42             }
43              
44              
45             ############################################
46             sub SeekResult {
47 0     0 0 0 my $self = shift;
48 0   0     0 $self->{iterator} = shift || 0;
49             }
50              
51              
52             ############################################
53             sub NextResult {
54 0     0 1 0 my ($self) = @_;
55 0         0 my $ret = undef;
56 0 0       0 if ( $self->{iterator} < @{ $self->{results} } ) {
  0         0  
57 0         0 $ret = $self->{results}[ $self->{iterator} ];
58 0         0 $self->{iterator}++;
59             }
60 0         0 return $ret;
61             }
62              
63              
64             ############################################
65             sub Hits {
66 2     2 1 6 my $self = shift;
67 2 100       5 if (@_) { $self->{hits} = $_[0] }
  1         5  
68 1   50     9 else { return ( $self->{hits} || 0 ) }
69             }
70              
71             ############################################
72             sub Fetched {
73 0     0 1 0 my $self = shift;
74 0 0       0 exists( $self->{results} ) ? scalar( @{ $self->{results} } ) : 0;
  0         0  
75             }
76              
77             ############################################
78             sub AddResult {
79 10     10 0 15 my ( $self, $result ) = @_;
80 10         9 push ( @{ $self->{results} }, $result );
  10         35  
81             }
82              
83             ############################################
84             sub AddError {
85 0     0 0 0 my ( $self, $error ) = @_;
86 0         0 push ( @{ $self->{errors} }, $error );
  0         0  
87             }
88              
89             ############################################
90             sub AddDebug {
91 1     1 0 2 my ( $self, $debug ) = @_;
92 1         2 push ( @{ $self->{debugs} }, $debug );
  1         4  
93             }
94              
95             ############################################
96             # for conformance with SWISH::API
97             # TODO: Code this!!!
98             sub HeaderNames
99             {
100 0     0 1   my $self = shift;
101 0           my (%h);
102 0           return sort keys %h;
103             }
104              
105             ############################################
106             # S::A vers 0.04 syntax , according to peknet
107 0     0 0   sub header_names { return HeaderNames(@_) }
108              
109             ############################################
110             SWISH::API::Remote::FunctionGenerator::makeaccessors(__PACKAGE__,
111             qw ( results errors stopwords ));
112              
113              
114             1;
115             __END__