| 1 | package Dallycot::Compiler; | ||||||||||||||||||||||||||||||||
| 2 | 1 | our $AUTHORITY = 'cpan:JSMITH'; | |||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use RDF::Trine; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use RDF::Query; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Data::UUID; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Storable qw(dclone); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Dallycot::Model; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Dallycot::Registry; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Dallycot::Resolver; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 1 | has root => ( | |||||||||||||||||||||||||||||||
| 16 | is => 'rw' | ||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | has model => ( | ||||||||||||||||||||||||||||||||
| 20 | isa => 'Dallycot::Model', | ||||||||||||||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 22 | default => sub { | ||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | Dallycot::Model -> new | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||||||||||||||
| 25 | 1 | handles => [qw/ | |||||||||||||||||||||||||||||||
| 26 | as_turtle | ||||||||||||||||||||||||||||||||
| 27 | as_ntriples | ||||||||||||||||||||||||||||||||
| 28 | as_tsv | ||||||||||||||||||||||||||||||||
| 29 | as_xml | ||||||||||||||||||||||||||||||||
| 30 | as_dot | ||||||||||||||||||||||||||||||||
| 31 | /] | ||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | has _prefixes => ( | ||||||||||||||||||||||||||||||||
| 35 | isa => 'RDF::Trine::NamespaceMap', | ||||||||||||||||||||||||||||||||
| 36 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 37 | default => sub { | ||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | RDF::Trine::NamespaceMap->new({ | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 39 | 'loc' => 'http://www.dallycot.net/ns/loc/1.0#', | ||||||||||||||||||||||||||||||||
| 40 | 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', | ||||||||||||||||||||||||||||||||
| 41 | 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', | ||||||||||||||||||||||||||||||||
| 42 | 'xsd' => 'http://www.w3.org/2001/XMLSchema#', | ||||||||||||||||||||||||||||||||
| 43 | }) | ||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | 1 | ); | |||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | has prefixes => ( | ||||||||||||||||||||||||||||||||
| 48 | isa => 'RDF::Trine::NamespaceMap', | ||||||||||||||||||||||||||||||||
| 49 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 50 | default => sub { | ||||||||||||||||||||||||||||||||
| 51 | 2 | ▶ | RDF::Trine::NamespaceMap->new | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 52 | }, | ||||||||||||||||||||||||||||||||
| 53 | 1 | lazy => 1, | |||||||||||||||||||||||||||||||
| 54 | predicate => 'has_prefixes' | ||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 1 | has parent => ( | |||||||||||||||||||||||||||||||
| 58 | isa => __PACKAGE__, | ||||||||||||||||||||||||||||||||
| 59 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 60 | predicate => 'has_parent', | ||||||||||||||||||||||||||||||||
| 61 | required => 0 | ||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | has symbols => ( | ||||||||||||||||||||||||||||||||
| 65 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||
| 66 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 67 | 4 | ▶ | default => sub { +{} } | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 68 | 1 | ); | |||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | has namespace_search_path => ( | ||||||||||||||||||||||||||||||||
| 71 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||||||
| 72 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | default => sub { [] } | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 74 | 1 | ); | |||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | sub child_model { | ||||||||||||||||||||||||||||||||
| 77 | 2 | ▶ | my($self, %info) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
child_model: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | return $self -> new( | ||||||||||||||||||||||||||||||||
| 80 | parent => $self, | ||||||||||||||||||||||||||||||||
| 81 | _prefixes => $self -> _prefixes, | ||||||||||||||||||||||||||||||||
| 82 | model => $self -> model, | ||||||||||||||||||||||||||||||||
| 83 | prefixes => dclone($self -> prefixes), | ||||||||||||||||||||||||||||||||
| 84 | 2 | namespace_search_path => [ @{$self -> namespace_search_path} ], | |||||||||||||||||||||||||||||||
| 85 | %info | ||||||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | sub add_search_path { | ||||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | my($self, @paths) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
add_search_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 2 | my $cv = AnyEvent -> condvar; | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | Dallycot::Registry->instance->register_used_namespaces(@paths)->done(sub { | ||||||||||||||||||||||||||||||||
| 95 | 2 | ▶ | push @{$self -> namespace_search_path}, @paths; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 96 | 2 | $cv -> send(); | |||||||||||||||||||||||||||||||
| 97 | }, sub { | ||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $cv -> croak(@_); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 99 | 2 | }); | |||||||||||||||||||||||||||||||
| 100 | 2 | $cv -> recv; | |||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | sub add_symbol { | ||||||||||||||||||||||||||||||||
| 104 | 2 | ▶ | my($self, $symbol, $uri) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
add_symbol: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 2 | ▶ | if($self->symbols->{$symbol}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 107 | 0 | croak "$symbol may only be defined once in a scope\n"; | |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 2 | $self -> symbols -> {$symbol} = $uri; | |||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | sub fetch_symbol { | ||||||||||||||||||||||||||||||||
| 114 | 23 | ▶ | my($self, $symbol) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
fetch_symbol: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 23 | ▶ | return unless defined $symbol; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 117 | 23 | ▶ | if($self->symbols->{$symbol}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 118 | 1 | return $self->symbols->{$symbol}; | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 22 | ▶ | if($self -> has_parent) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 122 | 11 | my $val = $self->parent->fetch_symbol($symbol); | |||||||||||||||||||||||||||||||
| 123 | 11 | ▶ | return $val if $val; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | # now look through search path | ||||||||||||||||||||||||||||||||
| 127 | 22 | my $registry = Dallycot::Registry->instance; | |||||||||||||||||||||||||||||||
| 128 | 22 | ▶ | if($registry->has_assignment( $self -> namespace_search_path, $symbol )) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 129 | 1 | my $uri = $registry->get_assignment_uri( $self -> namespace_search_path, $symbol); | |||||||||||||||||||||||||||||||
| 130 | 1 | ▶ | return RDF::Trine::Node::Resource->new($uri) if $uri; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | sub add_namespace_mapping { | ||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my($self, $ns, $href) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
add_namespace_mapping: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 0 | $self -> prefixes -> add_mapping($ns, $href); | |||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | sub compile { | ||||||||||||||||||||||||||||||||
| 141 | 2 | ▶ | my($self, @exprs) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
compile: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | 2 | my $expr; | |||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | 2 | ▶ | if(@exprs > 1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 146 | 0 | $expr = Dallycot::AST::Sequence->new(@exprs); | |||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||
| 148 | else { | ||||||||||||||||||||||||||||||||
| 149 | 2 | $expr = $exprs[0]; | |||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | 2 | my $root = $expr->to_rdf($self); | |||||||||||||||||||||||||||||||
| 153 | 2 | $self->root($root); | |||||||||||||||||||||||||||||||
| 154 | 2 | return $root; | |||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | sub uri { | ||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my($self, $prefixed) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
uri: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if($self -> has_prefixes) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 162 | 0 | my $uri = $self -> prefixes -> uri($prefixed); | |||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | return $uri if defined $uri; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if($self -> has_parent) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 167 | 0 | return $self -> parent -> uri($prefixed); | |||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | 0 | return $prefixed; | |||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | sub meta_uri { | ||||||||||||||||||||||||||||||||
| 174 | 4 | ▶ | my($self, $prefixed) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
meta_uri: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | 4 | return $self -> _prefixes -> uri($prefixed); | |||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | sub add_type { | ||||||||||||||||||||||||||||||||
| 180 | 28 | ▶ | my($self, $node, $type) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
add_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | 28 | $self -> model -> add_statement( | |||||||||||||||||||||||||||||||
| 183 | RDF::Trine::Statement -> new( | ||||||||||||||||||||||||||||||||
| 184 | $node, | ||||||||||||||||||||||||||||||||
| 185 | $self -> _prefixes -> rdf->type, | ||||||||||||||||||||||||||||||||
| 186 | $self -> _prefixes -> uri($type) | ||||||||||||||||||||||||||||||||
| 187 | ) | ||||||||||||||||||||||||||||||||
| 188 | ); | ||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | sub add_expression { | ||||||||||||||||||||||||||||||||
| 192 | 6 | ▶ | my($self, $node, $expr) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
add_expression: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | 6 | ▶ | return unless defined $expr; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | 6 | ▶ | $expr = $expr -> to_rdf($self) unless $expr -> isa('RDF::Trine::Node'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | 6 | $self -> model -> add_statement( | |||||||||||||||||||||||||||||||
| 199 | RDF::Trine::Statement -> new( | ||||||||||||||||||||||||||||||||
| 200 | $node, | ||||||||||||||||||||||||||||||||
| 201 | $self -> _prefixes -> uri('loc:expression'), | ||||||||||||||||||||||||||||||||
| 202 | $expr | ||||||||||||||||||||||||||||||||
| 203 | ) | ||||||||||||||||||||||||||||||||
| 204 | ); | ||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||
| 207 | sub add_connection { | ||||||||||||||||||||||||||||||||
| 208 | 1 | ▶ | my($self, $node, $prop, $object) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
add_connection: called CC=3 SCAR=13.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | 1 | ▶ | return unless defined $object; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||
| 212 | 1 | ▶ | if($node -> is_literal) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 213 | # mint a node that points to the literal | ||||||||||||||||||||||||||||||||
| 214 | 0 | my $bnode = $self -> bnode; | |||||||||||||||||||||||||||||||
| 215 | 0 | $self -> add_connection($bnode, 'rdf:value', $node); | |||||||||||||||||||||||||||||||
| 216 | 0 | $node = $bnode; | |||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||
| 219 | $self->model -> add_statement( | ||||||||||||||||||||||||||||||||
| 220 | 1 | RDF::Trine::Statement->new( | |||||||||||||||||||||||||||||||
| 221 | $node, | ||||||||||||||||||||||||||||||||
| 222 | $self -> _prefixes -> uri($prop), | ||||||||||||||||||||||||||||||||
| 223 | $object | ||||||||||||||||||||||||||||||||
| 224 | ) | ||||||||||||||||||||||||||||||||
| 225 | ); | ||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||
| 227 | 1 | return $node; | |||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||
| 230 | sub add_label { | ||||||||||||||||||||||||||||||||
| 231 | 13 | ▶ | my($self, $node, $label) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
add_label: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | 13 | ▶ | return unless defined $label; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | 13 | $self->model -> add_statement( | |||||||||||||||||||||||||||||||
| 236 | RDF::Trine::Statement -> new( | ||||||||||||||||||||||||||||||||
| 237 | $node, | ||||||||||||||||||||||||||||||||
| 238 | $self -> _prefixes -> uri('rdfs:label'), | ||||||||||||||||||||||||||||||||
| 239 | RDF::Trine::Node::Literal->new($label, '') | ||||||||||||||||||||||||||||||||
| 240 | ) | ||||||||||||||||||||||||||||||||
| 241 | ); | ||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | sub add_option { | ||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | my($self, $node, $label, $expr) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
add_option: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | return unless defined $label && defined $expr; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $label and defined $expr
MC/DC0%0/2
defined $label and defined $expr
defined $label
defined $expr
Truth table0%0/3
A and B
A= defined $labelB= defined $expr
| |||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||
| 249 | 0 | my $opt_bnode = $self -> bnode; | |||||||||||||||||||||||||||||||
| 250 | 0 | $self->model->add_statement( | |||||||||||||||||||||||||||||||
| 251 | RDF::Trine::Statement -> new( | ||||||||||||||||||||||||||||||||
| 252 | $node, | ||||||||||||||||||||||||||||||||
| 253 | $self->_prefixes->uri('loc:option'), | ||||||||||||||||||||||||||||||||
| 254 | $opt_bnode | ||||||||||||||||||||||||||||||||
| 255 | ) | ||||||||||||||||||||||||||||||||
| 256 | ); | ||||||||||||||||||||||||||||||||
| 257 | 0 | $self -> add_type($opt_bnode, 'loc:Option'); | |||||||||||||||||||||||||||||||
| 258 | 0 | $self -> add_label($opt_bnode, $label); | |||||||||||||||||||||||||||||||
| 259 | 0 | $self -> add_expression($opt_bnode, $expr); | |||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | sub add_list { | ||||||||||||||||||||||||||||||||
| 263 | 11 | ▶ | my($self, $node, $prop, @items) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
add_list: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 264 | 11 | my $list_node = $self -> model -> add_list(@items); | |||||||||||||||||||||||||||||||
| 265 | 11 | $self -> model -> add_statement( | |||||||||||||||||||||||||||||||
| 266 | RDF::Trine::Statement->new( | ||||||||||||||||||||||||||||||||
| 267 | $node, | ||||||||||||||||||||||||||||||||
| 268 | $self -> _prefixes -> uri($prop), | ||||||||||||||||||||||||||||||||
| 269 | $list_node | ||||||||||||||||||||||||||||||||
| 270 | ) | ||||||||||||||||||||||||||||||||
| 271 | ); | ||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | sub add_first { | ||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | my($self, $node, $expr) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
add_first: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | return unless defined $expr; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||
| 279 | 0 | $self -> model -> add_statement( | |||||||||||||||||||||||||||||||
| 280 | RDF::Trine::Statement -> new( | ||||||||||||||||||||||||||||||||
| 281 | $node, | ||||||||||||||||||||||||||||||||
| 282 | $self -> _prefixes -> uri('loc:first'), | ||||||||||||||||||||||||||||||||
| 283 | $expr -> to_rdf($self) | ||||||||||||||||||||||||||||||||
| 284 | ) | ||||||||||||||||||||||||||||||||
| 285 | ); | ||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||
| 288 | sub add_last { | ||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | my($self, $node, $expr) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
add_last: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | return unless defined $expr; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||
| 293 | 0 | $self -> model -> add_statement( | |||||||||||||||||||||||||||||||
| 294 | RDF::Trine::Statement -> new( | ||||||||||||||||||||||||||||||||
| 295 | $node, | ||||||||||||||||||||||||||||||||
| 296 | $self -> _prefixes -> uri('loc:last'), | ||||||||||||||||||||||||||||||||
| 297 | $expr -> to_rdf($self) | ||||||||||||||||||||||||||||||||
| 298 | ) | ||||||||||||||||||||||||||||||||
| 299 | ); | ||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||
| 302 | sub apply { | ||||||||||||||||||||||||||||||||
| 303 | 8 | ▶ | my($self, $expression, $bindings, $options) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
apply: called CC=7 SCAR=20.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||
| 305 | 8 | my $bnode = $self->bnode(); | |||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||
| 307 | 8 | $self -> add_type($bnode, 'loc:Application'); | |||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||
| 309 | # $self -> add_expression($bnode, $expression); | ||||||||||||||||||||||||||||||||
| 310 | 8 | ▶ | $expression = $expression -> to_rdf($self) unless $expression -> isa('RDF::Trine::Node'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 311 | 8 | $self -> model -> add_statement( | |||||||||||||||||||||||||||||||
| 312 | RDF::Trine::Statement->new( | ||||||||||||||||||||||||||||||||
| 313 | $bnode, | ||||||||||||||||||||||||||||||||
| 314 | $self -> _prefixes -> uri('loc:algorithm'), | ||||||||||||||||||||||||||||||||
| 315 | $expression | ||||||||||||||||||||||||||||||||
| 316 | ) | ||||||||||||||||||||||||||||||||
| 317 | ); | ||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||
| 319 | $self -> add_list($bnode, 'loc:target', | ||||||||||||||||||||||||||||||||
| 320 | 8 | ▶ | map { $_ -> isa('RDF::Trine::Node') ? $_ : $_ -> to_rdf($self) } @$bindings | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$bindings and @$bindings
MC/DC0%0/2
$bindings and @$bindings
$bindings
@$bindings
Truth table33%1/3
A and B
A= $bindingsB= @$bindings
| |||||||||||||||||||||||||||||||||
| 321 | ) if $bindings && @$bindings; | ||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||
| 323 | 8 | ▶ | foreach my $opt (keys %{$options||{}}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 324 | 0 | $self -> add_option($bnode, $opt, $options->{$opt}); | |||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||
| 327 | 8 | return $bnode; | |||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||
| 330 | sub integer { | ||||||||||||||||||||||||||||||||
| 331 | 3 | ▶ | my($self, $int) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
integer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||
| 333 | 3 | return RDF::Trine::Node::Literal->new($int, '', $self->_prefixes->uri('xsd:integer')); | |||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||
| 336 | sub string { | ||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | my($self, $value, $lang) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
string: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | if($lang) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 340 | 0 | return RDF::Trine::Node::Literal->new($value, $lang); | |||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||
| 342 | else { | ||||||||||||||||||||||||||||||||
| 343 | 0 | return RDF::Trine::Node::Literal->new($value, '', $self->_prefixes->uri('xsd:string')); | |||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||
| 347 | sub list { | ||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | my($self, @items) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||
| 350 | 0 | my $bnode = $self -> model -> add_list(@items); | |||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||
| 352 | 0 | return $bnode; | |||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||
| 355 | sub list_with_promise { | ||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | my($self, @items) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
list_with_promise: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||
| 358 | 0 | my $promise = pop @items; | |||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||
| 360 | 0 | my $node = $self -> model -> add_list(@items); | |||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||
| 362 | # now to traverse the list to the end and replace the tail with the promise | ||||||||||||||||||||||||||||||||
| 363 | 0 | my $root = $node; | |||||||||||||||||||||||||||||||
| 364 | 0 | my @next; | |||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | while(@next = $self -> model -> objects($root, $self -> meta_uri('rdf:rest'), undef, type => 'node')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | last if $next[0] eq $self -> meta_uri('rdf:nil'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 368 | 0 | $root = $next[0]; | |||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||
| 370 | 0 | return $node; | |||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||
| 373 | 1 | my $uuid_generator = Data::UUID -> new; | |||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||
| 375 | sub bnode { | ||||||||||||||||||||||||||||||||
| 376 | 30 | ▶ | my($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
bnode: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||
| 378 | 30 | return RDF::Trine::Node::Blank -> new($uuid_generator->to_string($uuid_generator->create)); | |||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||
| 381 | 1 | __PACKAGE__ -> meta -> make_immutable; | |||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||
| 383 | 1 | 1; | |||||||||||||||||||||||||||||||