Skip to content

Commit ef49551

Browse files
committed
Improve URI::NamespaceMap guessing
1 parent 3475f95 commit ef49551

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

lib/Plack/App/RDF/LinkedData.pm

+7-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ is are longer examples in the distribtion, which is used to run
133133
tests. In the config file, there is a C<store> parameter, which must
134134
contain the L<RDF::Trine::Store> config hashref. It may also have a
135135
C<base_uri> URI and a C<namespace> hashref which may contain prefix -
136-
URI mappings to be used in serializations.
136+
URI mappings to be used in serializations. Certain namespace, namely
137+
RDF, VoID, Hydra, DC Terms and XML Schema are added by the module and
138+
do not need to be declared.
139+
137140
138141
Note that this is a server that can only serve URIs of hosts you
139142
control, it is not a general purpose Linked Data manipulation tool,
@@ -307,6 +310,9 @@ sub prepare_app {
307310
base_uri => $config->{base_uri}
308311
);
309312
$self->{linkeddata}->namespaces(URI::NamespaceMap->new($config->{namespaces})) if ($config->{namespaces});
313+
# Ensure that certain namespaces are always declared
314+
$self->{linkeddata}->guess_namespaces('rdf', 'dct', 'xsd', 'void');
315+
$self->{linkeddata}->add_namespace_mapping(hydra => 'http://www.w3.org/ns/hydra/core#');
310316
}
311317

312318
sub call {

lib/RDF/LinkedData.pm

+4-8
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,7 @@ has last_etag => ( is => 'rw', isa => Str, predicate => 'has_last_etag');
243243
=item namespaces ( $namespace_map )
244244
245245
Gets or sets the namespaces that some serializers use for
246-
pretty-printing. Should be handed a L<URI::NamespaceMap> object. RDF,
247-
VoID, Hydra, DC Terms and XML Schema are added by the module and do
248-
not need to be declared.
246+
pretty-printing. Should be handed a L<URI::NamespaceMap> object.
249247
250248
=cut
251249

@@ -255,16 +253,14 @@ has 'namespaces' => (is => 'rw',
255253
lazy => 1,
256254
handles => {
257255
'add_namespace_mapping' => 'add_mapping',
256+
'guess_namespaces' => 'guess_and_add',
258257
'list_namespaces' => 'list_namespaces'
259258
});
260259

261260

262261
sub _build_namespaces {
263262
my $self = shift;
264-
my $nsmap = shift || URI::NamespaceMap->new();
265-
$nsmap->guess_and_add('rdf', 'void', 'dct', 'xsd');
266-
$nsmap->add_mapping(hydra => 'http://www.w3.org/ns/hydra/core#');
267-
return $nsmap;
263+
return shift || URI::NamespaceMap->new();
268264
}
269265

270266
# Just a temporary compatibility hack
@@ -352,6 +348,7 @@ sub response {
352348
$output_model->add_statement($st);
353349
}
354350
my $cl = literal($counter, undef, 'http://www.w3.org/2001/XMLSchema#integer');
351+
$self->guess_namespaces('void');
355352
my $void = $self->namespaces->void;
356353
$output_model->add_statement(statement(iri($uri),
357354
iri($void->triples),
@@ -715,7 +712,6 @@ sub _void_content {
715712
}
716713

717714
if ($self->has_fragments) {
718-
$self->add_namespace_mapping(hydra => 'http://www.w3.org/ns/hydra/core#');
719715
$self->_common_fragments_control($self->_voidmodel);
720716
}
721717

meta/makefile.pret

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
:runtime-requirement [ :on "HTTP::Headers"^^:CpanId ];
1919
:runtime-requirement [ :on "RDF::Helper::Properties 0.10"^^:CpanId; ];
2020
:runtime-requirement [ :on "URI 1.52"^^:CpanId ];
21-
:runtime-requirement [ :on "URI::NamespaceMap"^^:CpanId ];
21+
:runtime-requirement [ :on "URI::NamespaceMap 0.31_06"^^:CpanId ];
22+
:runtime-requirement [ :on "RDF::NS::Curated"^^:CpanId ];
2223
:runtime-requirement [ :on "Module::Load::Conditional"^^:CpanId ];
2324
:runtime-requirement [ :on "Encode"^^:CpanId ];
2425
:runtime-requirement [ :on "RDF::RDFa::Generator 0.102"^^:CpanId; ];

0 commit comments

Comments
 (0)