line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lido::XML; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
27828
|
use Moo; |
|
1
|
|
|
|
|
12187
|
|
|
1
|
|
|
|
|
9
|
|
6
|
1
|
|
|
1
|
|
1857
|
use Lido::XML::LIDO_1_0; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
7
|
1
|
|
|
1
|
|
357
|
use Lido::XML::Error; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use XML::Compile; |
9
|
|
|
|
|
|
|
use XML::Compile::Cache; |
10
|
|
|
|
|
|
|
use XML::Compile::Schema; |
11
|
|
|
|
|
|
|
use XML::Compile::Util 'pack_type'; |
12
|
|
|
|
|
|
|
use Try::Tiny; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'namespace' => (is => 'ro' , default => sub {'http://www.lido-schema.org'}); |
15
|
|
|
|
|
|
|
has 'root' => (is => 'ro' , default => sub {'lido'}); |
16
|
|
|
|
|
|
|
has 'prefixes' => (is => 'ro' , default => sub { |
17
|
|
|
|
|
|
|
[ |
18
|
|
|
|
|
|
|
'lido' => 'http://www.lido-schema.org', |
19
|
|
|
|
|
|
|
'doc' => 'http://www.mda.org.uk/spectrumXML/Documentation', |
20
|
|
|
|
|
|
|
'gml' => 'http://www.opengis.net/gml', |
21
|
|
|
|
|
|
|
'xsd' => 'http://www.w3.org/2001/XMLSchema', |
22
|
|
|
|
|
|
|
'xml' => 'http://www.w3.org/XML/1998/namespace' |
23
|
|
|
|
|
|
|
] |
24
|
|
|
|
|
|
|
}); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'reader' => (is => 'ro'); |
27
|
|
|
|
|
|
|
has 'writer' => (is => 'ro'); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub BUILD { |
30
|
|
|
|
|
|
|
my ($self) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my @schemes = Lido::XML::LIDO_1_0->new->content; |
33
|
|
|
|
|
|
|
my $schema = XML::Compile::Cache->new(\@schemes); |
34
|
|
|
|
|
|
|
my $type = pack_type $self->namespace, $self->root; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$self->{reader} = $schema->compile(READER => $type); |
37
|
|
|
|
|
|
|
$self->{writer} = $schema->compile(WRITER => $type, ( prefixes => $self->prefixes ) ); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$schema = undef; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub parse { |
43
|
|
|
|
|
|
|
my ($self,$input) = @_; |
44
|
|
|
|
|
|
|
my $perl; |
45
|
|
|
|
|
|
|
try { |
46
|
|
|
|
|
|
|
$perl = $self->reader->($input); |
47
|
|
|
|
|
|
|
} catch {; |
48
|
|
|
|
|
|
|
Lido::XML::Error->throw(sprintf('%s', $_)); |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
$perl; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub to_xml { |
54
|
|
|
|
|
|
|
my ($self,$data) = @_; |
55
|
|
|
|
|
|
|
my $doc = XML::LibXML::Document->new('1.0', 'UTF-8'); |
56
|
|
|
|
|
|
|
my $xml; |
57
|
|
|
|
|
|
|
try { |
58
|
|
|
|
|
|
|
$xml = $self->writer->($doc, $data); |
59
|
|
|
|
|
|
|
} catch { |
60
|
|
|
|
|
|
|
Lido::XML::Error->throw(sprintf('%s', $_)); |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
$doc->setDocumentElement($xml); |
63
|
|
|
|
|
|
|
$doc->toString(1); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |