Core/Enumerator/Postgres.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 75 CC 4 SCAR 15.1
CC
4
Cov
0%
getNext
12.0
close
6.0
new
2.0
CRAP 4.5
1 #
2 # The contents of this file are subject to the Mozilla Public
3 # License Version 1.1 (the "License"); you may not use this file
4 # except in compliance with the License. You may obtain a copy of
5 # the License at http://www.mozilla.org/MPL/
6 #
7 # Software distributed under the License is distributed on an "AS
8 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 # implied. See the License for the specific language governing
10 # rights and limitations under the License.
11 #
12 # The Original Code is the RDF::Core module
13 #
14 # The Initial Developer of the Original Code is Ginger Alliance Ltd.
15 # Portions created by Ginger Alliance are
16 # Copyright (C) 2001 Ginger Alliance Ltd.
17 # All Rights Reserved.
18 #
19 # Contributor(s):
20 #
21 # Alternatively, the contents of this file may be used under the
22 # terms of the GNU General Public License Version 2 or later (the
23 # "GPL"), in which case the provisions of the GPL are applicable
24 # instead of those above. If you wish to allow use of your
25 # version of this file only under the terms of the GPL and not to
26 # allow others to use your version of this file under the MPL,
27 # indicate your decision by deleting the provisions above and
28 # replace them with the notice and other provisions required by
29 # the GPL. If you do not delete the provisions above, a recipient
30 # may use your version of this file under either the MPL or the
31 # GPL.
32 #
33  
34 package RDF::Core::Enumerator::Postgres;
35  
36 use strict;
37 require Exporter;
38  
39 use Carp;
40 use DBI;
41  
42 require RDF::Core::Resource;
43 require RDF::Core::Literal;
44 require RDF::Core::Statement;
45  
46 our @ISA = qw(RDF::Core::Enumerator);
47  
48 sub new {
49 my ($class, %params) = @_;
50 $class = ref $class || $class;
51 my $self = {
52 cursor => $params{Cursor},
53 };
54 bless $self, $class;
55 return $self;
56 }
57  
58 sub getFirst {
59 my $self = shift;
60 carp 'Warning: RDF::Core::Enumerator->getFirst() could not be implemented for database cursor. This method returns getNext.';
61 return $self->getNext;
62 }
63  
64 sub getNext {
65 my $self = shift;
66 my $rval;
67 my @row = $self->{cursor}->fetchrow_array;
68 if (@row) {
69 my $subject = new RDF::Core::Resource($row[0],$row[1]);
70 my $predicate = new RDF::Core::Resource($row[2],$row[3]);
71 my $object;
72 if ($row[4]) {
73 $object = new RDF::Core::Resource($row[4],$row[5]);
74 } else {
75 $object = new RDF::Core::Literal($row[6], $row[7], $row[8]);
76 };
77 $rval = new RDF::Core::Statement($subject, $predicate, $object);
78 }
79 return $rval;
80 }
81  
82 sub close {
83 my $self = shift;
84 $self->{cursor}->finish() if $self->{cursor};
85 }
86  
87 sub DESTROY {
88 my $self = shift;
89 $self->close();
90 }
91  
92 1;
93 __END__