line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
28088
|
use warnings; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
157
|
|
4
|
5
|
|
|
5
|
|
26
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
254
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Gwybodaeth::NamespaceManager; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
NamespaceManager - parses and stores namespaces for gwybodaeth |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use NamespaceManager; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $nm = NamespaceManager->new(); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$nm->map_namespace($data); |
19
|
|
|
|
|
|
|
$nm->get_namspace_hash(); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This module stores namespace data and makes these available as a hash. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=over |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
5
|
|
|
5
|
|
30
|
use Carp qw(croak); |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
2286
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# A hash to store all the namespaces |
32
|
|
|
|
|
|
|
my %namespace; |
33
|
|
|
|
|
|
|
# Default for $base set to an empty string. |
34
|
|
|
|
|
|
|
# This will be interpreted as 'this document'. |
35
|
|
|
|
|
|
|
my $base = ""; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item new() |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Returns an instance of the NamespaceManager class. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new { |
44
|
6
|
|
|
6
|
1
|
95
|
my $class = shift; |
45
|
6
|
|
|
|
|
17
|
my $self = {}; |
46
|
6
|
|
|
|
|
17
|
bless $self, $class; |
47
|
6
|
|
|
|
|
21
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item map_namespace($data) |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Takes an array reference $data, and maps any namespaces declared into a hash. |
53
|
|
|
|
|
|
|
Returns a refence to this hash. It also stores any @base elements found. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub map_namespace { |
58
|
6
|
50
|
|
6
|
1
|
596
|
ref(my $self = shift) or croak "instance variable needed"; |
59
|
6
|
|
|
|
|
13
|
my $data = shift; # A referece to the data |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Clear what may already be in %namespace from a previous run |
62
|
6
|
|
|
|
|
27
|
for (keys %namespace) { delete $namespace{$_}; }; |
|
1
|
|
|
|
|
4
|
|
63
|
|
|
|
|
|
|
# Clear what may have been in $base from a previous run |
64
|
6
|
|
|
|
|
14
|
$base = ""; |
65
|
|
|
|
|
|
|
|
66
|
6
|
|
|
|
|
13
|
for my $line (@{ $data }) { |
|
6
|
|
|
|
|
17
|
|
67
|
17
|
100
|
|
|
|
57
|
if ($line =~ m/^\@prefix # string begins with a @prefix grammar |
68
|
|
|
|
|
|
|
\s+ |
69
|
|
|
|
|
|
|
(\S*:) # zero or more non whitespace chars |
70
|
|
|
|
|
|
|
# followed by a colon - namespace key |
71
|
|
|
|
|
|
|
\s+ |
72
|
|
|
|
|
|
|
< # open angle bracket |
73
|
|
|
|
|
|
|
(\S+) # one or more non whitepace chars |
74
|
|
|
|
|
|
|
# - namespace value |
75
|
|
|
|
|
|
|
> # close angle bracket |
76
|
|
|
|
|
|
|
\s+ |
77
|
|
|
|
|
|
|
. |
78
|
|
|
|
|
|
|
/x) { |
79
|
1
|
|
|
|
|
7
|
$namespace{$1} = $2; |
80
|
|
|
|
|
|
|
} |
81
|
17
|
100
|
|
|
|
58
|
if ($line =~ m/^\@base # string begins with a @base grammar |
82
|
|
|
|
|
|
|
\s+ |
83
|
|
|
|
|
|
|
<([^>]*)> # angle brackets enclosed by any non |
84
|
|
|
|
|
|
|
# closing angle bracket chars - base |
85
|
|
|
|
|
|
|
\s+ |
86
|
|
|
|
|
|
|
. # any non \n char |
87
|
|
|
|
|
|
|
\s* |
88
|
|
|
|
|
|
|
$/x) { |
89
|
1
|
|
|
|
|
5
|
$base = $1; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
6
|
|
|
|
|
26
|
return $self->get_namespace_hash(); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item get_namespace_hash() |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Returns a hash reference to a hash containing mapped namespaces. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub get_namespace_hash { |
102
|
7
|
50
|
|
7
|
1
|
26
|
ref(my $self = shift) or croak "instance variable needed"; |
103
|
|
|
|
|
|
|
|
104
|
7
|
|
|
|
|
27
|
return \%namespace; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item get_base() |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Returns a reference to the base of the document. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub get_base { |
114
|
1
|
50
|
|
1
|
1
|
8
|
ref(my $self = shift) or croak "instance variable needed"; |
115
|
|
|
|
|
|
|
|
116
|
1
|
|
|
|
|
8
|
return \$base; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
__END__ |