Core/Statement.pm untested

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 82 CC 6 SCAR 29.5
CC
6
Cov
0%
getLabel
42.0
new
2.0
getSubject
2.0
CRAP 19.1
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::Statement;
35  
36 use strict;
37  
38 require Exporter;
39  
40 use Carp;
41  
42 sub new {
43 my ($pkg,$subject, $predicate, $object)=@_;
44 $pkg = ref $pkg || $pkg;
45 my $self={};
46  
47 $self->{_subject} = $subject;
48 $self->{_predicate} = $predicate;
49 $self->{_object} = $object;
50 bless $self,$pkg;
51 }
52 sub getSubject {
53 my $self = shift;
54 return $self->{_subject};
55 }
56 sub getPredicate {
57 my $self = shift;
58 return $self->{_predicate};
59 }
60 sub getObject {
61 my $self = shift;
62 return $self->{_object};
63 }
64 sub getLabel {
65 my $self = shift;
66 my $rval;
67 my $subjectLabel = $self->getSubject()->getURI();
68 unless ($subjectLabel =~ /^_:/) {
69 $subjectLabel = '<' .$subjectLabel.'> ';
70 }
71 $rval = $subjectLabel;
72 $rval .= '<' . $self->getPredicate()->getURI() . '> ';
73 if ($self->getObject()->isLiteral()) {
74 my $literal = $self->getObject()->getValue();
75 $literal =~ s/\\/\\\\/g;
76 $literal =~ s/\n/\\n/g;
77 $literal =~ s/\r/\\r/g;
78 $literal =~ s/\t/\\t/g;
79 $literal =~ s/"/\\"/g;
80 $rval .= '"' . $literal . '"';
81 if (my $lang=$self->getObject()->getLang()) {
82 $rval .= "\@$lang"
83 }
84 if (my $datatype=$self->getObject()->getDatatype()) {
85 $rval .= "^^<$datatype>"
86 }
87 } else {
88 my $objectLabel = $self->getObject()->getURI();
89 unless ($objectLabel =~ /^_:/) {
90 $objectLabel = '<' .$objectLabel.'> ';
91 }
92 $rval .= $objectLabel;
93 }
94 ;
95 $rval .= "." ;
96 return $rval;
97 }
98 sub clone {
99 my $self = shift;
100 return $self->new($self->getSubject->clone,
101 $self->getPredicate->clone,
102 $self->getObject->clone);
103 }
104 1;
105 __END__