| 1 | package Dallycot::AST::Fetch; | ||||||||||||||||||||
| 2 | 29 | our $AUTHORITY = 'cpan:JSMITH'; | |||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | # ABSTRACT: Find the value associated with an identifier | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 29 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 29 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 29 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 29 | ▶ | use parent 'Dallycot::AST'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 29 | ▶ | use Dallycot::Util qw(maybe_promise); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 29 | ▶ | use Promises qw(deferred); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 29 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | sub new { | ||||||||||||||||||||
| 18 | 125 | ▶ | my ( $class, $identifier ) = @_; | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 125 | ▶ | $class = ref $class || $class; | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 125 | return bless [$identifier] => $class; | |||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | sub to_rdf { | ||||||||||||||||||||
| 26 | 12 | ▶ | my($self, $model) = @_; | ||||||||||||||||||
|
Subroutine
to_rdf: called CC=4 SCAR=14.7
Pod
undocumented
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 12 | my $label; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 12 | ▶ | if(@$self > 1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | # need namespace resolution | ||||||||||||||||||||
| 32 | 0 | my $uri = $model -> uri(join(":", @$self)); | |||||||||||||||||||
| 33 | 0 | ▶ | return $uri if blessed $uri; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | else { | ||||||||||||||||||||
| 36 | 12 | $label = $self->[0]; | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | 12 | my $val = $model -> fetch_symbol($label); | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 12 | ▶ | return $val if blessed $val; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 10 | my $bnode = $model -> bnode; | |||||||||||||||||||
| 43 | 10 | $model -> add_type($bnode, 'loc:BindingReference'); | |||||||||||||||||||
| 44 | 10 | $model -> add_label($bnode, $label); | |||||||||||||||||||
| 45 | 10 | return $bnode; | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | sub identifiers { | ||||||||||||||||||||
| 49 | 3299 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
identifiers: called CC=2 SCAR=7.9
Pod
undocumented
| |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 3299 | ▶ | if ( @{$self} == 1 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 3299 | return $self->[0]; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | else { | ||||||||||||||||||||
| 55 | 0 | return [ @{$self} ]; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | sub to_string { | ||||||||||||||||||||
| 60 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
to_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | return $self->[0]; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | sub execute { | ||||||||||||||||||||
| 66 | 3554 | ▶ | my ( $self, $engine ) = @_; | ||||||||||||||||||
|
Subroutine
execute: called CC=7 SCAR=33.0
Pod
undocumented
| |||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 3554 | my $registry = Dallycot::Registry->instance; | |||||||||||||||||||
| 69 | 3554 | ▶ | if ( @$self > 1 ) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 70 | 0 | ▶ | if ( $engine->has_namespace( $self->[0] ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | 0 | my $ns = $engine->get_namespace( $self->[0] ); | |||||||||||||||||||
| 72 | 0 | ▶ | if ( $registry->has_namespace($ns) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 0 | ▶ | if ( $registry->has_assignment( $ns, $self->[1] ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 0 | return maybe_promise( $registry->get_assignment( $ns, $self->[1] ) ); | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||
| 77 | 0 | my $d = deferred; | |||||||||||||||||||
| 78 | 0 | $d->reject( join( ":", @$self ) . " is undefined." ); | |||||||||||||||||||
| 79 | 0 | return $d->promise; | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | else { | ||||||||||||||||||||
| 83 | 0 | my $d = deferred; | |||||||||||||||||||
| 84 | 0 | $d->reject("The namespace \"$ns\" is unregistered."); | |||||||||||||||||||
| 85 | 0 | return $d->promise; | |||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||
| 89 | 0 | my $d = deferred; | |||||||||||||||||||
| 90 | 0 | $d->reject("The namespace prefix \"@{[$self->[0]]}\" is undefined."); | |||||||||||||||||||
| 91 | 0 | return $d->promise; | |||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | elsif ( $engine->has_assignment( $self->[0] ) ) { | ||||||||||||||||||||
| 95 | 3252 | return maybe_promise( $engine->get_assignment( $self->[0] ) ); | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | elsif ( $registry->has_assignment( $engine->get_namespace_search_path, $self->[0] ) ) { | ||||||||||||||||||||
| 98 | 302 | return maybe_promise( $registry->get_assignment( $engine->get_namespace_search_path, $self->[0] ) ); | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | else { | ||||||||||||||||||||
| 101 | 0 | my $d = deferred; | |||||||||||||||||||
| 102 | 0 | $d->reject( $self->[0] . " is undefined." ); | |||||||||||||||||||
| 103 | 0 | return $d->promise; | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 29 | 1; | |||||||||||||||||||