line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::XML; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.15'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1316
|
use namespace::clean; |
|
1
|
|
|
|
|
17016
|
|
|
1
|
|
|
|
|
7
|
|
6
|
1
|
|
|
1
|
|
852
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
75360
|
|
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
294
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
545
|
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 transform => (is => 'ro', coerce => sub { |
21
|
|
|
|
|
|
|
Catmandu::XML::Transformer->new( stylesheet => $_[0] ) }); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub generator { |
24
|
|
|
|
|
|
|
my ($self) = @_; |
25
|
|
|
|
|
|
|
sub { |
26
|
|
|
|
|
|
|
state $reader = do { |
27
|
|
|
|
|
|
|
my %options = ( |
28
|
|
|
|
|
|
|
from => ($self->file || $self->fh), |
29
|
|
|
|
|
|
|
whitespace => $self->whitespace, |
30
|
|
|
|
|
|
|
attributes => $self->attributes, |
31
|
|
|
|
|
|
|
depth => $self->depth, |
32
|
|
|
|
|
|
|
ns => $self->ns, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
$options{path} = $self->path if defined $self->path; |
35
|
|
|
|
|
|
|
if ($self->type eq 'simple') { |
36
|
|
|
|
|
|
|
$options{simple} = 1; |
37
|
|
|
|
|
|
|
$options{root} = $self->root; |
38
|
|
|
|
|
|
|
} elsif ($self->type ne 'ordered') { |
39
|
|
|
|
|
|
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
XML::Struct::Reader->new(%options); |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $item = $reader->readNext; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# TODO: transformation should be done earlier for efficiency |
47
|
|
|
|
|
|
|
# and because simple format modifies the XML document (bug) |
48
|
|
|
|
|
|
|
return $self->transform ? |
49
|
|
|
|
|
|
|
$self->transform->transform($item) : $item |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
__END__ |