line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::LIDO; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
56960
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
124688
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
686
|
use Lido::XML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use XML::LibXML::Reader; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Moo; |
10
|
|
|
|
|
|
|
use namespace::clean; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'lido' => (is => 'lazy'); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _build_lido { |
17
|
|
|
|
|
|
|
return Lido::XML->new; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub generator { |
21
|
|
|
|
|
|
|
my ($self) = @_; |
22
|
|
|
|
|
|
|
my $file = $self->file; |
23
|
|
|
|
|
|
|
my %opts; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
if (ref($file)) { |
26
|
|
|
|
|
|
|
%opts = ('IO' , $file); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
|
|
|
|
|
|
%opts = ('location' , $file); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub { |
33
|
|
|
|
|
|
|
state $reader = XML::LibXML::Reader->new(%opts); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $match = $reader->nextPatternMatch( |
36
|
|
|
|
|
|
|
XML::LibXML::Pattern->new( |
37
|
|
|
|
|
|
|
'//lido:lido', { lido => 'http://www.lido-schema.org' } |
38
|
|
|
|
|
|
|
) |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return undef unless $match == 1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $xml = $reader->readOuterXml(); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
return undef unless length $xml; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$reader->nextSibling(); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
return $self->lido->parse($xml); |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=pod |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 NAME |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Catmandu::Importer::LIDO - A LIDO XML importer |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 SYNOPSIS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# From the command line |
66
|
|
|
|
|
|
|
$ catmandu convert LIDO to YAML < ex/lido.xml |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# From Perl |
69
|
|
|
|
|
|
|
use Catmandu; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $importer = Catmandu->importer('LIDO',file => 'ex/lido.xml'); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $n = $importer->each(sub { |
74
|
|
|
|
|
|
|
my $hashref = $_[0]; |
75
|
|
|
|
|
|
|
# ... |
76
|
|
|
|
|
|
|
}); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 DESCRIPTION |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This is a L<Catmandu::Importer> for converting LIDO data (an XML Schema for |
81
|
|
|
|
|
|
|
Contributing Content to Cultural Heritage Repositories). |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 CONFIGURATION |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=over |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item file |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Read input from a local file given by its path. Alternatively a scalar |
90
|
|
|
|
|
|
|
reference can be passed to read from a string. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item fh |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Read input from an L<IO::Handle>. If not specified, L<Catmandu::Util::io> is used to |
95
|
|
|
|
|
|
|
create the input stream from the C<file> argument or by using STDIN. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item encoding |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Binmode of the input stream C<fh>. Set to C<:utf8> by default. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item fix |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
An ARRAY of one or more fixes or file scripts to be applied to imported items. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item size |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Number of items. If not set, an endless stream is imported. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=back |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 METHODS |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Every L<Catmandu::Importer> is a L<Catmandu::Iterable> all its methods are |
114
|
|
|
|
|
|
|
inherited. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 SEE ALSO |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
L<Catmandu::Importer>, L<Lido::XML> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |