| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package URI::Namespace; |
|
2
|
6
|
|
|
6
|
|
2673
|
use Moo 1.006000; |
|
|
6
|
|
|
|
|
27858
|
|
|
|
6
|
|
|
|
|
39
|
|
|
3
|
6
|
|
|
6
|
|
4943
|
use URI; |
|
|
6
|
|
|
|
|
3827
|
|
|
|
6
|
|
|
|
|
139
|
|
|
4
|
6
|
|
|
6
|
|
2376
|
use IRI 0.003; |
|
|
6
|
|
|
|
|
620747
|
|
|
|
6
|
|
|
|
|
933
|
|
|
5
|
6
|
|
|
6
|
|
58
|
use Scalar::Util qw(blessed); |
|
|
6
|
|
|
|
|
15
|
|
|
|
6
|
|
|
|
|
435
|
|
|
6
|
6
|
|
|
6
|
|
2208
|
use Types::Namespace 0.004 qw( Iri ); |
|
|
6
|
|
|
|
|
133
|
|
|
|
6
|
|
|
|
|
53
|
|
|
7
|
6
|
|
|
6
|
|
4152
|
use namespace::autoclean; |
|
|
6
|
|
|
|
|
26341
|
|
|
|
6
|
|
|
|
|
26
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.10'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
URI::Namespace - A namespace URI/IRI class with autoload methods |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use URI::Namespace; |
|
18
|
|
|
|
|
|
|
my $foaf = URI::Namespace->new( 'http://xmlns.com/foaf/0.1/' ); |
|
19
|
|
|
|
|
|
|
print $foaf->as_string; |
|
20
|
|
|
|
|
|
|
print $foaf->name; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This module provides an object with a URI/IRI attribute, typically used |
|
25
|
|
|
|
|
|
|
prefix-namespace pairs, typically used in XML, RDF serializations, |
|
26
|
|
|
|
|
|
|
etc. The local part can be used as a method, these are autoloaded. |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 METHODS |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=over |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=item C<< new ( $string | URI | IRI ) >> |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
This is the constructor. You may pass a string with a URI or a URI object. |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item C<< uri ( [ $local_part ] ) >> |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Returns a L<URI> object with the namespace IRI. Optionally, the method |
|
39
|
|
|
|
|
|
|
can take a local part as argument, in which case, it will return the |
|
40
|
|
|
|
|
|
|
namespace URI with the local part appended. |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item C<< iri ( [ $local_part ] ) >> |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Returns a L<IRI> object with the namespace IRI. Optionally, the method |
|
45
|
|
|
|
|
|
|
can take a local part as argument, in which case, it will return the |
|
46
|
|
|
|
|
|
|
namespace IRI with the local part appended. |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item C<< local_part ( $uri ) >> |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Returns the local part string if the given argument URI (which may be |
|
51
|
|
|
|
|
|
|
a string, L<URI> or L<IRI> object) matches the namespace URI, or |
|
52
|
|
|
|
|
|
|
C<undef> if not. |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=back |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
The following methods from L<URI> can be used on an URI::Namespace object: C<as_string>, C<as_iri>, C<canonical>, C<eq>, C<abs>, C<rel>. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
One important usage for this module is to enable you to create L<URI>s for full URIs, e.g.: |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
print $foaf->Person->as_string; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
will return |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
http://xmlns.com/foaf/0.1/Person |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 FURTHER DETAILS |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
See L<URI::NamespaceMap> for further details about authors, license, etc. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
around BUILDARGS => sub { |
|
74
|
|
|
|
|
|
|
my ($next, $self, @parameters) = @_; |
|
75
|
|
|
|
|
|
|
return $self->$next(@_) if ((@parameters > 1) || (ref($parameters[0]) eq 'HASH')); |
|
76
|
|
|
|
|
|
|
return { _uri => $parameters[0] }; |
|
77
|
|
|
|
|
|
|
}; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
has _uri => ( |
|
80
|
|
|
|
|
|
|
is => "ro", |
|
81
|
|
|
|
|
|
|
isa => Iri, |
|
82
|
|
|
|
|
|
|
coerce => 1, |
|
83
|
|
|
|
|
|
|
required => 1, |
|
84
|
|
|
|
|
|
|
handles => { |
|
85
|
|
|
|
|
|
|
'as_string' => 'as_string', |
|
86
|
|
|
|
|
|
|
'as_iri' => 'as_string', |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
); |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub iri { |
|
91
|
6
|
|
|
6
|
1
|
17910
|
my ($self, $name) = @_; |
|
92
|
6
|
100
|
|
|
|
21
|
if (defined($name)) { |
|
93
|
2
|
|
|
|
|
48
|
my $str = $self->_uri->as_string; |
|
94
|
|
|
|
|
|
|
# XSD is given without hash in XML world, but hash should be added anyway (see issue #14) |
|
95
|
2
|
100
|
|
|
|
92
|
$str .= '#' if ($str eq 'http://www.w3.org/2001/XMLSchema'); |
|
96
|
2
|
|
|
|
|
33
|
return IRI->new($str . "$name"); |
|
97
|
|
|
|
|
|
|
} else { |
|
98
|
4
|
|
|
|
|
71
|
return $self->_uri; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub uri { |
|
103
|
67
|
|
|
67
|
1
|
19398
|
my ($self, $name) = @_; |
|
104
|
67
|
|
|
|
|
1281
|
my $iri = $self->_uri->as_string; |
|
105
|
67
|
100
|
|
|
|
2897
|
if (defined($name)) { |
|
106
|
61
|
100
|
|
|
|
156
|
$iri .= '#' if ($iri eq 'http://www.w3.org/2001/XMLSchema'); |
|
107
|
61
|
|
|
|
|
241
|
return URI->new($iri . "$name"); |
|
108
|
|
|
|
|
|
|
} else { |
|
109
|
6
|
|
|
|
|
23
|
return URI->new($iri); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub local_part { |
|
114
|
12
|
|
|
12
|
1
|
2104
|
my ($self, $fulluri) = @_; |
|
115
|
12
|
|
|
|
|
15
|
my $local_part = undef; |
|
116
|
12
|
100
|
100
|
|
|
78
|
if (blessed($fulluri) && $fulluri->isa('IRI')) { |
|
117
|
4
|
|
|
|
|
67
|
$fulluri = $fulluri->as_string; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
12
|
|
|
|
|
380
|
my $iri = $self->_uri->as_string; |
|
120
|
12
|
100
|
|
|
|
685
|
if ($fulluri =~ m/^$iri(.+)/) { |
|
121
|
6
|
|
|
|
|
24
|
$local_part = $1; |
|
122
|
|
|
|
|
|
|
} else { |
|
123
|
|
|
|
|
|
|
# TODO: throw error? |
|
124
|
|
|
|
|
|
|
} |
|
125
|
12
|
|
|
|
|
64
|
return $local_part; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
for my $method (qw/ abs rel eq canonical /) { |
|
130
|
1
|
|
|
1
|
0
|
1181
|
eval qq[ sub $method { shift->uri->${method}(\@_) } ]; |
|
|
1
|
|
|
1
|
0
|
5
|
|
|
|
1
|
|
|
1
|
0
|
623
|
|
|
|
1
|
|
|
1
|
0
|
6
|
|
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
our $AUTOLOAD; |
|
134
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
135
|
52
|
|
|
52
|
|
33159
|
my $self = shift; |
|
136
|
52
|
|
|
|
|
265
|
my ($name) = $AUTOLOAD =~ /::(\w+)$/; |
|
137
|
52
|
|
|
|
|
133
|
return $self->uri($name); |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |
|
141
|
|
|
|
|
|
|
__END__ |