1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
package Data::HAL::URI::NamespaceMap;
use strictures;
use Data::HAL::URI qw();
use Moo; # extends
use URI::IRI qw();
use URI::Template qw();
use XML::RegExp qw();
extends 'URI::NamespaceMap';
our $VERSION = '1.001';
sub uri {
my ($self, $abbr) = @_;
if (my ($prefix, $reference) = $abbr =~ m/\A ($XML::RegExp::NCName) : (.*) \z/msx) {
if ($self->namespace_uri($prefix)) {
return Data::HAL::URI->new(
_original => $abbr,
uri => URI::Template
->new($self->namespace_uri($prefix)->as_string)
->process(rel => URI::IRI->new($reference)->canonical->as_string),
);
}
}
return;
}
sub add_mapping {
my ($self,$name,$href) = @_;
my $map = $self->namespace_map;
if ($map) {
return $map->{$name} = $href;
} else {
return $self->SUPER::add_mapping($name,$href);
}
}
1;
|