| 1 | package RDF::Trine::Node::Formula; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use parent qw(RDF::Trine::Node::Literal); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use RDF::Trine::Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use RDF::Trine::Pattern; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use RDF::Trine::Parser::Notation3; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | our ($VERSION); | |||||||||||||||||||||||||||
| 15 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 3 | $VERSION = '0.206'; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 8 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 8 | my $class = shift; | |||||||||||||||||||||||||||
| 21 | 8 | my $pattern = shift; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 8 | ▶ | if (blessed($pattern) && $pattern->isa('RDF::Trine::Pattern')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($pattern) and $pattern->isa("RDF::Trine::Pattern")
MC/DC50%1/2
builtin::blessed($pattern) and $pattern->isa("RDF::Trine::Pattern")
builtin::blessed($pattern)
$pattern->isa("RDF::Trine::Pattern")
Truth table66%2/3
A and B
A= builtin::blessed($pattern)B= $pattern->isa("RDF::Trine::Pattern")
| |||||||||||||||||||||||||||||
| 24 | 6 | return bless [$pattern, undef, undef, undef, undef], $class; | |||||||||||||||||||||||||||
| 25 | } else { | ||||||||||||||||||||||||||||
| 26 | 2 | my $p = RDF::Trine::Parser::Notation3->new; | |||||||||||||||||||||||||||
| 27 | 2 | my $base = shift; | |||||||||||||||||||||||||||
| 28 | 2 | my $r = $p->parse_formula($base, $pattern); | |||||||||||||||||||||||||||
| 29 | 2 | return $r; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 14 | ▶ | sub literal_value { | ||||||||||||||||||||||||||
|
Subroutine
literal_value: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 14 | my $self = shift; | |||||||||||||||||||||||||||
| 35 | 14 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 0 | $self->from_literal_notation( shift ); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 14 | return $self->as_literal_notation; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 16 | ▶ | sub pattern { | ||||||||||||||||||||||||||
|
Subroutine
pattern: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 16 | my $self = shift; | |||||||||||||||||||||||||||
| 43 | 16 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | $self->[0] = shift; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 16 | return $self->[0]; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 14 | ▶ | sub forAll { | ||||||||||||||||||||||||||
|
Subroutine
forAll: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 14 | my $self = shift; | |||||||||||||||||||||||||||
| 51 | 14 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | $self->[3] = \@_; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 14 | ▶ | return unless $self->[3]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 14 | return @{ $self->[3] }; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 14 | ▶ | sub forSome { | ||||||||||||||||||||||||||
|
Subroutine
forSome: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 14 | my $self = shift; | |||||||||||||||||||||||||||
| 60 | 14 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | $self->[4] = \@_; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 14 | ▶ | return unless $self->[4]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 14 | return @{ $self->[4] }; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 8 | ▶ | sub literal_value_language { | ||||||||||||||||||||||||||
|
Subroutine
literal_value_language: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 8 | return undef; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 18 | ▶ | sub literal_datatype { | ||||||||||||||||||||||||||
|
Subroutine
literal_datatype: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 18 | return 'http://open.vocab.org/terms/Formula'; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | ▶ | sub as_ntriples { | ||||||||||||||||||||||||||
|
Subroutine
as_ntriples: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 77 | 2 | my $literal = $self->literal_value; | |||||||||||||||||||||||||||
| 78 | 2 | my $escaped = $self->_unicode_escape( $literal ); | |||||||||||||||||||||||||||
| 79 | 2 | $literal = $escaped; | |||||||||||||||||||||||||||
| 80 | 2 | ▶ | if ($self->has_language) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 81 | 0 | my $lang = $self->literal_value_language; | |||||||||||||||||||||||||||
| 82 | 0 | return qq("${literal}"\@${lang}); | |||||||||||||||||||||||||||
| 83 | } elsif ($self->has_datatype) { | ||||||||||||||||||||||||||||
| 84 | 2 | my $dt = $self->literal_datatype; | |||||||||||||||||||||||||||
| 85 | 2 | return qq("${literal}"^^<${dt}>); | |||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||
| 87 | 0 | return qq("${literal}"); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 4 | ▶ | sub has_language { | ||||||||||||||||||||||||||
|
Subroutine
has_language: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 4 | return 0; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 4 | ▶ | sub has_datatype { | ||||||||||||||||||||||||||
|
Subroutine
has_datatype: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 4 | return 1; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 14 | ▶ | sub as_literal_notation { | ||||||||||||||||||||||||||
|
Subroutine
as_literal_notation: called CC=7 SCAR=25.2
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | 14 | my $self = shift; | |||||||||||||||||||||||||||
| 101 | 14 | my $n3 = ''; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 14 | ▶ | if ($self->forAll) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $n3 .= '@forAll ' . join ', ', map {$_->is_variable?$_->as_string:$_->as_ntriples} $self->forAll; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | $n3 .= " .\n"; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 14 | ▶ | if ($self->forSome) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $n3 .= '@forSome ' . join ', ', map {$_->is_variable?$_->as_string:$_->as_ntriples} $self->forSome; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | $n3 .= " .\n"; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 14 | foreach my $st ($self->pattern->triples) { | |||||||||||||||||||||||||||
| 114 | 14 | ▶ | $n3 .= join ' ', map {$_->is_variable?$_->as_string:$_->as_ntriples} $st->nodes; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 14 | $n3 .= " .\n"; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 14 | return $n3; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub from_literal_notation { | ||||||||||||||||||||||||||
|
Subroutine
from_literal_notation: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 123 | 0 | my $new = __PACKAGE__->new(@_); | |||||||||||||||||||||||||||
| 124 | 0 | $self->[0] = $new->pattern->clone; | |||||||||||||||||||||||||||
| 125 | 0 | $self->[3] = [ $new->forAll ]; | |||||||||||||||||||||||||||
| 126 | 0 | $self->[4] = [ $new->forSome ]; | |||||||||||||||||||||||||||
| 127 | 0 | return $self; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub equal { | ||||||||||||||||||||||||||
|
Subroutine
equal: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 131 | 0 | my ($a, $b) = @_; | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | return 0 unless $b->isa(__PACKAGE__); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | return $a->as_literal_notation eq $b->as_literal_notation; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub _compare { | ||||||||||||||||||||||||||
|
Subroutine
_compare: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 137 | 0 | my ($a, $b) = @_; | |||||||||||||||||||||||||||
| 138 | 0 | ▶ | return 1 unless $b->isa(__PACKAGE__); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 0 | return (scalar $a->pattern->triples) <=> (scalar $b->pattern->triples); | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 3 | 1; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | __END__ | ||||||||||||||||||||||||||||