File Coverage

blib/lib/RDF/Core/Model.pm
Criterion Covered Total %
statement 9 57 15.7
branch 0 20 0.0
condition 0 39 0.0
subroutine 3 14 21.4
pod 10 10 100.0
total 22 140 15.7


line stmt bran cond sub pod time code
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::Model;
35              
36 2     2   139612 use strict;
  2         7  
  2         102  
37             require Exporter;
38              
39             require RDF::Core::Resource;
40 2     2   1108 use RDF::Core::Constants qw(:rdf);
  2         6  
  2         621  
41              
42 2     2   12 use Carp;
  2         2  
  2         1837  
43              
44             sub new {
45 0     0 1   my ($pkg,%options) = @_;
46 0   0       $pkg = ref $pkg || $pkg;
47 0           my $self = {};
48 0           $self->{_options} = \%options;
49 0           bless $self, $pkg;
50             }
51             sub setOptions {
52 0     0 1   my ($self,$options) = @_;
53 0           $self->{_options} = $options;
54             }
55             sub getOptions {
56 0     0 1   my $self = shift;
57 0           return $self->{_options};
58             }
59             sub addStmt {
60 0     0 1   my $self = shift;
61 0 0 0       carp "No storage defined"
      0        
62             unless exists $self->{_options}->{Storage} &&
63             defined $self->{_options}->{Storage} &&
64             ref $self->{_options}->{Storage};
65 0           $self->{_options}->{Storage}->addStmt(@_);
66             }
67             sub removeStmt {
68 0     0 1   my $self = shift;
69 0 0 0       carp "No storage defined"
      0        
70             unless exists $self->{_options}->{Storage} &&
71             defined $self->{_options}->{Storage} &&
72             ref $self->{_options}->{Storage};
73 0           $self->{_options}->{Storage}->removeStmt(@_);
74             }
75             sub existsStmt {
76 0     0 1   my $self = shift;
77 0 0 0       carp "No storage defined"
      0        
78             unless exists $self->{_options}->{Storage} &&
79             defined $self->{_options}->{Storage} &&
80             ref $self->{_options}->{Storage};
81 0           $self->{_options}->{Storage}->existsStmt(@_);
82             }
83             sub getStmts {
84 0     0 1   my $self = shift;
85 0 0 0       carp "No storage defined"
      0        
86             unless exists $self->{_options}->{Storage} &&
87             defined $self->{_options}->{Storage} &&
88             ref $self->{_options}->{Storage};
89 0           $self->{_options}->{Storage}->getStmts(@_);
90             }
91             sub countStmts {
92 0     0 1   my $self = shift;
93 0 0 0       carp "No storage defined"
      0        
94             unless exists $self->{_options}->{Storage} &&
95             defined $self->{_options}->{Storage} &&
96             ref $self->{_options}->{Storage};
97 0           $self->{_options}->{Storage}->countStmts(@_);
98             }
99              
100             sub getObjects {
101 0     0 1   my ($self, $subj, $pred) = @_;
102 0 0 0       $subj = new RDF::Core::Resource($subj)
103             unless (ref $subj && $subj->isa("RDF::Core::Resource"));
104 0 0 0       $pred = new RDF::Core::Resource($pred)
105             unless (ref $pred && $pred->isa("RDF::Core::Resource"));
106 0           my $enum = $self->getStmts($subj, $pred, undef);
107 0           my $stmt = $enum->getFirst;
108 0           my $ret = [];
109 0           while ($stmt) {
110 0           push @$ret, $stmt->getObject;
111 0           $stmt = $enum->getNext;
112             }
113 0           return $ret;
114             }
115              
116             sub _rdf_container_sort {
117 0     0     my ($a, $b) = @_;
118 0 0         my $aa = $1 if $a->getPredicate->getURI =~ /.*#_(\d+)/;
119 0 0         my $bb = $1 if $b->getPredicate->getURI =~ /.*#_(\d+)/;
120 0           return $aa <=> $bb;
121             }
122              
123             sub getContainerObjects {
124 0     0 1   my ($self, $cont) = @_;
125 0           my $members = $self->getStmts($cont, undef, undef);
126 0           my $member = $members->getFirst;
127 0           my @arr;
128 0           while ($member) {
129 0 0         push @arr, $member unless $member->getPredicate->equals(RDF_TYPE);
130 0           $member = $members->getNext;
131             }
132            
133 0           return [map {$_->getObject} sort {_rdf_container_sort($a, $b)} @arr];
  0            
  0            
134             }
135              
136             1;
137             __END__