line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dallycot::Value::URI; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JSMITH'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: A URI value that can be dereferenced |
5
|
|
|
|
|
|
|
|
6
|
23
|
|
|
23
|
|
17770
|
use strict; |
|
23
|
|
|
|
|
37
|
|
|
23
|
|
|
|
|
820
|
|
7
|
23
|
|
|
23
|
|
131
|
use warnings; |
|
23
|
|
|
|
|
31
|
|
|
23
|
|
|
|
|
609
|
|
8
|
|
|
|
|
|
|
|
9
|
23
|
|
|
23
|
|
91
|
use utf8; |
|
23
|
|
|
|
|
30
|
|
|
23
|
|
|
|
|
123
|
|
10
|
23
|
|
|
23
|
|
438
|
use parent 'Dallycot::Value::Any'; |
|
23
|
|
|
|
|
40
|
|
|
23
|
|
|
|
|
124
|
|
11
|
|
|
|
|
|
|
|
12
|
23
|
|
|
23
|
|
9338
|
use Dallycot::Registry; |
|
23
|
|
|
|
|
82
|
|
|
23
|
|
|
|
|
1741
|
|
13
|
23
|
|
|
23
|
|
247
|
use Promises qw(deferred); |
|
23
|
|
|
|
|
31
|
|
|
23
|
|
|
|
|
181
|
|
14
|
23
|
|
|
23
|
|
6221
|
use Scalar::Util qw(blessed); |
|
23
|
|
|
|
|
38
|
|
|
23
|
|
|
|
|
1472
|
|
15
|
23
|
|
|
23
|
|
16609
|
use URI; |
|
23
|
|
|
|
|
82296
|
|
|
23
|
|
|
|
|
830
|
|
16
|
|
|
|
|
|
|
|
17
|
23
|
|
|
23
|
|
163
|
use experimental qw(switch); |
|
23
|
|
|
|
|
34
|
|
|
23
|
|
|
|
|
189
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
33
|
|
|
33
|
0
|
91
|
my ( $class, $uri ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
33
|
|
33
|
|
|
198
|
$class = ref $class || $class; |
23
|
|
|
|
|
|
|
|
24
|
33
|
|
|
|
|
239
|
$uri = URI->new($uri)->canonical; |
25
|
|
|
|
|
|
|
|
26
|
33
|
|
|
|
|
144262
|
return bless [$uri] => $class; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub to_rdf { |
30
|
0
|
|
|
0
|
0
|
|
my( $self, $model ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
return RDF::Trine::Node::Resource->new($self->[0]->as_string); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub calculate_length { |
36
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
return Dallycot::Value::Numeric->new( length $self->[0]->as_string ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub value_at { |
42
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $index ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $d = deferred; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if($index > length($self -> [0] -> as_string)) { |
47
|
0
|
|
|
|
|
|
$d -> resolve($engine -> UNDEFINED); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
0
|
|
|
|
|
|
$d->resolve( |
51
|
|
|
|
|
|
|
bless [ substr( $self->[0]->as_string, $index - 1, 1 ), 'en' ] => 'Dallycot::Value::String' ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return $d->promise; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub id { |
58
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return "<" . $self->[0]->as_string . ">"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub as_text { |
64
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return $self->id; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub is_lambda { |
70
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my ( $lib, $method ) = $self->_get_library_and_method; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
return unless defined $lib; |
75
|
|
|
|
|
|
|
return $lib->get_assignment($method)->then( |
76
|
|
|
|
|
|
|
sub { |
77
|
0
|
|
|
0
|
|
|
my ($def) = @_; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
return unless blessed($def); |
80
|
0
|
0
|
|
|
|
|
return 1 if $def->isa(__PACKAGE__); |
81
|
0
|
|
|
|
|
|
return $def->is_lambda; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
0
|
0
|
|
sub is_defined { return 1 } |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
0
|
0
|
|
sub is_empty {return} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub min_arity { |
91
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my ( $lib, $method ) = $self->_get_library_and_method; |
94
|
0
|
0
|
|
|
|
|
if ($lib) { |
95
|
0
|
|
|
|
|
|
return $lib->min_arity($method); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
0
|
|
|
|
|
|
return 0; # TODO: fix once we fetch remote libraries |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $registry = Dallycot::Registry->instance; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _get_library_and_method { |
105
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my $uri = $self->[0]->as_string; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
my ( $namespace, $method ) = split( /#/, $uri, 2 ); |
110
|
0
|
0
|
|
|
|
|
if ( !defined $method ) { |
111
|
0
|
0
|
|
|
|
|
if ( $self->[0] =~ m{^(.*/)(.+?)$}x ) { |
112
|
0
|
|
|
|
|
|
$namespace = $1; |
113
|
0
|
|
|
|
|
|
$method = $2; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
else { |
116
|
0
|
|
|
|
|
|
$namespace = $self->[0]; |
117
|
0
|
|
|
|
|
|
$method = ''; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
else { |
121
|
0
|
|
|
|
|
|
$namespace .= '#'; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
if ( $registry->has_namespace($namespace) ) { |
125
|
0
|
|
|
|
|
|
return ( $registry->namespaces->{$namespace}, $method ); |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
return; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub apply { |
131
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $options, @bindings ) = @_; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
my ( $lib, $method ) = $self->_get_library_and_method; |
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
if ($lib) { |
136
|
0
|
|
|
|
|
|
return $lib->apply( $method, $engine, $options, @bindings ); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
else { # TODO: fetch resource and see if it's a lambda |
139
|
0
|
|
|
|
|
|
my $d = deferred; |
140
|
0
|
|
|
|
|
|
$d->reject( $self->[0] . " is not a lambda" ); |
141
|
0
|
|
|
|
|
|
return $d->promise; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub resolve { |
146
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
my $d = deferred; |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
my $url = $self->[0]; |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
my $resolver = Dallycot::Resolver->instance; |
153
|
|
|
|
|
|
|
$resolver->get($url->as_string)->done( |
154
|
|
|
|
|
|
|
sub { |
155
|
0
|
|
|
0
|
|
|
$d->resolve(@_); |
156
|
|
|
|
|
|
|
}, |
157
|
|
|
|
|
|
|
sub { |
158
|
0
|
|
|
0
|
|
|
$d->reject(@_); |
159
|
|
|
|
|
|
|
} |
160
|
0
|
|
|
|
|
|
); |
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
return $d->promise; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub resolve_content { |
166
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
my $d = deferred; |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
my $url = $self->[0]; |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
my $resolver = Dallycot::TextResolver->instance; |
173
|
|
|
|
|
|
|
$resolver->get($url->as_string)->done( |
174
|
|
|
|
|
|
|
sub { |
175
|
0
|
|
|
0
|
|
|
$d->resolve(@_); |
176
|
|
|
|
|
|
|
}, |
177
|
|
|
|
|
|
|
sub { |
178
|
0
|
|
|
0
|
|
|
$d->reject(@_); |
179
|
|
|
|
|
|
|
} |
180
|
0
|
|
|
|
|
|
); |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
return $d->promise; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub fetch_property { |
186
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $prop ) = @_; |
187
|
|
|
|
|
|
|
|
188
|
0
|
0
|
|
|
|
|
if ( @$self < 2 ) { |
189
|
0
|
|
|
|
|
|
print STDERR "Getting " . ($self->[0])."\n"; |
190
|
0
|
|
|
|
|
|
push @$self, Dallycot::Resolver->instance->get( |
191
|
|
|
|
|
|
|
"".($self -> [0]) |
192
|
|
|
|
|
|
|
); |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
$self -> [1] -> then(sub { |
196
|
0
|
|
|
0
|
|
|
my($tstore) = @_; |
197
|
0
|
|
|
|
|
|
$tstore -> fetch_property( $engine, $prop ); |
198
|
0
|
|
|
|
|
|
}); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
1; |