| 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::Resource; | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | require Exporter; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | our @ISA = qw(RDF::Core::Node); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 2 | require RDF::Core::Node; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 0 | my $pkg = shift; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | $pkg = ref $pkg || $pkg; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $pkg || $pkg
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg
$pkg
Truth table0%0/3
A || B
A= ref $pkgB= $pkg
| |||||||||||||||||||||||||||||
| 49 | 0 | my $self = {}; | |||||||||||||||||||||||||||
| 50 | 0 | my $namespace; | |||||||||||||||||||||||||||
| 51 | my $localValue; | ||||||||||||||||||||||||||||
| 52 | 0 | bless $self,$pkg; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | if (@_ gt 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | #more then one parameters is interpreted as ($namespace,$localValue) pair | ||||||||||||||||||||||||||||
| 55 | 0 | ($namespace,$localValue) = @_; | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | croak "Resource's namespace must be defined" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | unless defined $namespace; | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $localValue = '' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | unless defined $localValue; | ||||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||
| 61 | #one parameter is URI | ||||||||||||||||||||||||||||
| 62 | 0 | my ($URI) = @_; | |||||||||||||||||||||||||||
| 63 | 0 | ▶ | croak "Resource's URI must be defined" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | unless defined $URI; | ||||||||||||||||||||||||||||
| 65 | 0 | $self->_resolveURI($URI,\$namespace,\$localValue); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 0 | $self->{_namespace} = $namespace; | |||||||||||||||||||||||||||
| 68 | 0 | $self->{_localValue} = $localValue; | |||||||||||||||||||||||||||
| 69 | 0 | $self->{_uri} = $namespace.$localValue; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | return $self; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub getNamespace { | ||||||||||||||||||||||||||
|
Subroutine
getNamespace: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 0 | return $_[0]->{_namespace}; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub getLocalValue { | ||||||||||||||||||||||||||
|
Subroutine
getLocalValue: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 0 | return $_[0]->{_localValue}; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub getURI { | ||||||||||||||||||||||||||
|
Subroutine
getURI: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 0 | return $_[0]->{_uri}; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | #Override inherited method | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub getLabel { | ||||||||||||||||||||||||||
|
Subroutine
getLabel: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 0 | return $_[0]->getURI; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 88 | 0 | return $self->new($self->{_namespace}, $self->{_localValue}); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub equals { | ||||||||||||||||||||||||||
|
Subroutine
equals: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 0 | my ($self, $other) = @_; | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | $other = new RDF::Core::Resource($other) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $other and $other->isa("RDF::Core::Node")
MC/DC0%0/2
ref $other and $other->isa("RDF::Core::Node")
ref $other
$other->isa("RDF::Core::Node")
Truth table0%0/3
A and B
A= ref $otherB= $other->isa("RDF::Core::Node")
| |||||||||||||||||||||||||||||
| 94 | unless ref $other && $other->isa("RDF::Core::Node"); | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | return !$self->isLiteral && $self->getURI eq $other->getURI; | ||||||||||||||||||||||||||
|
Condition0%0/3
!$self->isLiteral && $self->getURI eq $other->getURI
MC/DC0%0/2
!$self->isLiteral && $self->getURI eq $other->getURI
!$self->isLiteral
$self->getURI eq $other->getURI
Truth table0%0/3
not(A) && B
A= !$self->isLiteralB= $self->getURI eq $other->getURI
| |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub _resolveURI { | ||||||||||||||||||||||||||
|
Subroutine
_resolveURI: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 99 | 0 | my ($self,$URI,$ns,$lv)=@_; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ($URI=~/(^.*[\/#:])([a-zA-Z_][^\/#:]*$)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | $$ns = $1; | |||||||||||||||||||||||||||
| 102 | 0 | $$lv = $2; | |||||||||||||||||||||||||||
| 103 | } else { | ||||||||||||||||||||||||||||
| 104 | 0 | $$ns = $URI; | |||||||||||||||||||||||||||
| 105 | 0 | $$lv = ''; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 2 | 1; | |||||||||||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||||||||||