line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::XML; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.16'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
951
|
use namespace::clean; |
|
1
|
|
|
|
|
12626
|
|
|
1
|
|
|
|
|
4
|
|
6
|
1
|
|
|
1
|
|
537
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
58102
|
|
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
199
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
371
|
use XML::Struct::Reader; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Catmandu::XML::Transformer; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has type => (is => 'ro', default => sub { 'simple' }); |
14
|
|
|
|
|
|
|
has path => (is => 'ro'); |
15
|
|
|
|
|
|
|
has root => (is => 'lazy', default => sub { defined $_[0]->path ? 1 : 0 }); |
16
|
|
|
|
|
|
|
has depth => (is => 'ro'); |
17
|
|
|
|
|
|
|
has ns => (is => 'ro', default => sub { '' }); |
18
|
|
|
|
|
|
|
has attributes => (is => 'ro', default => sub { 1 }); |
19
|
|
|
|
|
|
|
has whitespace => (is => 'ro', default => sub { 0 }); |
20
|
|
|
|
|
|
|
has xslt => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
lazy => 1, |
23
|
|
|
|
|
|
|
coerce => sub { |
24
|
|
|
|
|
|
|
Catmandu::XML::Transformer->new( stylesheet => $_[0] ) if defined $_[0] |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
builder => sub { |
27
|
|
|
|
|
|
|
$_[0]->transform |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
has transform => ( |
31
|
|
|
|
|
|
|
is => 'ro', |
32
|
|
|
|
|
|
|
coerce => sub { |
33
|
|
|
|
|
|
|
warn "Catmandu::Importer::XML option 'transform' renamed to 'xslt'\n"; |
34
|
|
|
|
|
|
|
$_[0]; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub generator { |
39
|
|
|
|
|
|
|
my ($self) = @_; |
40
|
|
|
|
|
|
|
sub { |
41
|
|
|
|
|
|
|
state $reader = do { |
42
|
|
|
|
|
|
|
my %options = ( |
43
|
|
|
|
|
|
|
from => ($self->file || $self->fh), |
44
|
|
|
|
|
|
|
whitespace => $self->whitespace, |
45
|
|
|
|
|
|
|
attributes => $self->attributes, |
46
|
|
|
|
|
|
|
depth => $self->depth, |
47
|
|
|
|
|
|
|
ns => $self->ns, |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
$options{path} = $self->path if defined $self->path; |
50
|
|
|
|
|
|
|
if ($self->type eq 'simple') { |
51
|
|
|
|
|
|
|
$options{simple} = 1; |
52
|
|
|
|
|
|
|
$options{root} = $self->root; |
53
|
|
|
|
|
|
|
} elsif ($self->type ne 'ordered') { |
54
|
|
|
|
|
|
|
return; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
XML::Struct::Reader->new(%options); |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $item = $reader->readNext; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# TODO: transformation should be done earlier for efficiency |
62
|
|
|
|
|
|
|
# and because simple format modifies the XML document (bug) |
63
|
|
|
|
|
|
|
return $self->xslt ? |
64
|
|
|
|
|
|
|
$self->xslt->transform($item) : $item |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
__END__ |