File Coverage

blib/lib/SWISH.pm
Criterion Covered Total %
statement 12 63 19.0
branch 0 34 0.0
condition 0 8 0.0
subroutine 4 13 30.7
pod 2 2 100.0
total 18 120 15.0


line stmt bran cond sub pod time code
1             package SWISH;
2 1     1   808 use strict;
  1         2  
  1         42  
3              
4 1     1   6 use vars (qw/$VERSION $errstr/);
  1         2  
  1         427  
5              
6             $VERSION = 0.08;
7              
8              
9             sub connect {
10 0     0 1   my $class = shift;
11 0           my $driver = shift;
12              
13              
14 0 0         unless ( $driver ) {
15 0           $errstr = "Must supply Access Method";
16 0           return;
17             }
18              
19 0           eval { require "SWISH/$driver.pm"; };
  0            
20 0 0         if ( $@ ) {
21 0           $errstr = $@;
22 0           return;
23             }
24              
25              
26 0           $driver = "SWISH::$driver";
27              
28 0           my $drh;
29              
30 0           eval { $drh = $driver->new( @_ ); };
  0            
31              
32 0 0         return $drh if ref $drh;
33              
34 0   0       $errstr = $driver->errstr || $@ || "Unknown error calling $driver->new()";
35 0           return;
36             }
37              
38             sub get_header {
39 0     0 1   my ($self, $name, $index) = @_;
40              
41             # Return the entire hash
42 0 0         die "SWISH headers not defined\n" unless ref $self->{_indexheaders};
43 0 0         return $self->{_indexheaders} unless $name;
44              
45             # Return the default headers
46 0 0         unless ( $index ) {
47 0 0         return unless exists $self->{_indexheaders}{lc $name};
48             return wantarray
49 0 0         ? @{$self->{_indexheaders}{lc $name}}
  0            
50             : $self->{_indexheaders}{lc $name}->[0];
51             }
52              
53              
54             # Return for a specific index file
55              
56 0 0         die "Invalid index file name '$index' passed to get_header()\n"
57             unless exists $self->{_indexheaders}{INDEX}{$index};
58              
59 0 0         return unless exists $self->{_indexheaders}{INDEX}{$index}{lc $name};
60             return wantarray
61 0 0         ? @{$self->{_indexheaders}{INDEX}{$index}{lc $name}}
  0            
62             : $self->{_indexheaders}{INDEX}{$index}{lc $name}->[0];
63              
64              
65             }
66              
67              
68              
69             package SWISH::Results;
70 1     1   5 use strict;
  1         6  
  1         36  
71 1     1   5 use vars ( '$AUTOLOAD' );
  1         1  
  1         488  
72              
73              
74              
75             sub new {
76 0     0     my ( $class, $attr ) = @_;
77 0 0         my %attr = %$attr if $attr;
78 0           return bless \%attr, $class;
79             }
80              
81             # Some default methods
82 0     0     sub disconnect {}
83 0     0     sub close {}
84              
85             sub as_string {
86 0     0     my $self = shift;
87 0   0       my $delimiter = shift || ' ';
88              
89 0           my $blank = $delimiter =~ /^\s+$/;
90              
91 0           my @properties = qw/swishrank swishdocpath swishtitle swishdocsize/;
92              
93 0 0         push @properties, @{$self->{_settings}{properties}} if $self->{_settings}{properties};
  0            
94              
95 0 0 0       return join $delimiter, map { $blank && /\s/ ? qq["$_"] : $_ }
  0 0          
96 0           map( { $self->{$_} || '???' } @properties ),
97             "($self->{swishreccount}/$self->{total_hits})" ;
98             }
99              
100              
101 0     0     sub DESTROY {
102             }
103              
104             sub field_names {
105 0     0     my $self = shift;
106 0           return grep { defined $self->{$_} } grep { !/^_/ } keys %$self;
  0            
  0            
107             }
108            
109              
110              
111             sub AUTOLOAD {
112 0     0     my $self = shift;
113              
114 0 0         if ( $AUTOLOAD =~ /.*::(\w+)/ ) {
115 0           my $attribute = $1;
116              
117 0 0         return defined $self->{$attribute} ? $self->{$attribute} : undef;
118             }
119              
120             }
121              
122              
123             1;
124             __END__