| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Dallycot::AST::Fetch; | 
| 2 |  |  |  |  |  |  | our $AUTHORITY = 'cpan:JSMITH'; | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | # ABSTRACT: Find the value associated with an identifier | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 23 |  |  | 23 |  | 15249 | use strict; | 
|  | 23 |  |  |  |  | 41 |  | 
|  | 23 |  |  |  |  | 805 |  | 
| 7 | 23 |  |  | 23 |  | 105 | use warnings; | 
|  | 23 |  |  |  |  | 41 |  | 
|  | 23 |  |  |  |  | 609 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 23 |  |  | 23 |  | 88 | use utf8; | 
|  | 23 |  |  |  |  | 33 |  | 
|  | 23 |  |  |  |  | 132 |  | 
| 10 | 23 |  |  | 23 |  | 457 | use parent 'Dallycot::AST'; | 
|  | 23 |  |  |  |  | 35 |  | 
|  | 23 |  |  |  |  | 117 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 23 |  |  | 23 |  | 9260 | use Dallycot::Util qw(maybe_promise); | 
|  | 23 |  |  |  |  | 42 |  | 
|  | 23 |  |  |  |  | 1148 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 23 |  |  | 23 |  | 113 | use Promises       qw(deferred); | 
|  | 23 |  |  |  |  | 33 |  | 
|  | 23 |  |  |  |  | 416 |  | 
| 15 | 23 |  |  | 23 |  | 3789 | use Scalar::Util   qw(blessed); | 
|  | 23 |  |  |  |  | 37 |  | 
|  | 23 |  |  |  |  | 11844 |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub new { | 
| 18 | 0 |  |  | 0 | 0 | 0 | my ( $class, $identifier ) = @_; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 0 |  | 0 |  |  | 0 | $class = ref $class || $class; | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 0 |  |  |  |  | 0 | return bless [$identifier] => $class; | 
| 23 |  |  |  |  |  |  | } | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | sub to_rdf { | 
| 26 | 0 |  |  | 0 | 0 | 0 | my($self, $model) = @_; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 0 |  |  |  |  | 0 | my $label; | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 0 | 0 |  |  |  | 0 | if(@$self > 1) { | 
| 31 |  |  |  |  |  |  | # need namespace resolution | 
| 32 | 0 |  |  |  |  | 0 | my $uri = $model -> uri(join(":", @$self)); | 
| 33 | 0 | 0 |  |  |  | 0 | return $uri if blessed $uri; | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  | else { | 
| 36 | 0 |  |  |  |  | 0 | $label = $self->[0]; | 
| 37 |  |  |  |  |  |  | } | 
| 38 | 0 |  |  |  |  | 0 | my $val = $model -> fetch_symbol($label); | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 0 | 0 |  |  |  | 0 | return $val if blessed $val; | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 0 |  |  |  |  | 0 | my $bnode = $model -> bnode; | 
| 43 | 0 |  |  |  |  | 0 | $model -> add_type($bnode, 'loc:BindingReference'); | 
| 44 | 0 |  |  |  |  | 0 | $model -> add_label($bnode, $label); | 
| 45 | 0 |  |  |  |  | 0 | return $bnode; | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | sub identifiers { | 
| 49 | 2 |  |  | 2 | 0 | 603 | my ($self) = @_; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 2 | 50 |  |  |  | 3 | if ( @{$self} == 1 ) { | 
|  | 2 |  |  |  |  | 12 |  | 
| 52 | 2 |  |  |  |  | 9 | return $self->[0]; | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  | else { | 
| 55 | 0 |  |  |  |  |  | return [ @{$self} ]; | 
|  | 0 |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | sub to_string { | 
| 60 | 0 |  |  | 0 | 0 |  | my ($self) = @_; | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 0 |  |  |  |  |  | return $self->[0]; | 
| 63 |  |  |  |  |  |  | } | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | sub execute { | 
| 66 | 0 |  |  | 0 | 0 |  | my ( $self, $engine ) = @_; | 
| 67 |  |  |  |  |  |  |  | 
| 68 | 0 |  |  |  |  |  | my $registry = Dallycot::Registry->instance; | 
| 69 | 0 | 0 |  |  |  |  | if ( @$self > 1 ) { | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
| 70 | 0 | 0 |  |  |  |  | if ( $engine->has_namespace( $self->[0] ) ) { | 
| 71 | 0 |  |  |  |  |  | my $ns = $engine->get_namespace( $self->[0] ); | 
| 72 | 0 | 0 |  |  |  |  | if ( $registry->has_namespace($ns) ) { | 
| 73 | 0 | 0 |  |  |  |  | if ( $registry->has_assignment( $ns, $self->[1] ) ) { | 
| 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."); | 
|  | 0 |  |  |  |  |  |  | 
| 91 | 0 |  |  |  |  |  | return $d->promise; | 
| 92 |  |  |  |  |  |  | } | 
| 93 |  |  |  |  |  |  | } | 
| 94 |  |  |  |  |  |  | elsif ( $engine->has_assignment( $self->[0] ) ) { | 
| 95 | 0 |  |  |  |  |  | return maybe_promise( $engine->get_assignment( $self->[0] ) ); | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  | elsif ( $registry->has_assignment( $engine->get_namespace_search_path, $self->[0] ) ) { | 
| 98 | 0 |  |  |  |  |  | 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 |  |  |  |  |  |  | 1; |