line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::xml_simple; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.15'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
18047
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
86349
|
|
|
1
|
|
|
|
|
7
|
|
6
|
1
|
|
|
1
|
|
266
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
1468
|
use XML::Struct::Reader; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use XML::LibXML::Reader; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'Catmandu::Fix::Base'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# TODO: avoid code duplication with xml_read |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has field => (is => 'ro', required => 1); |
15
|
|
|
|
|
|
|
has attributes => (is => 'ro'); |
16
|
|
|
|
|
|
|
has ns => (is => 'ro'); |
17
|
|
|
|
|
|
|
has content => (is => 'ro'); |
18
|
|
|
|
|
|
|
has root => (is => 'ro'); |
19
|
|
|
|
|
|
|
has depth => (is => 'ro'); |
20
|
|
|
|
|
|
|
has path => (is => 'ro'); |
21
|
|
|
|
|
|
|
has whitespace => (is => 'ro'); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub simple { 1 } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
around BUILDARGS => sub { |
26
|
|
|
|
|
|
|
my ($orig,$class,$field,%opts) = @_; |
27
|
|
|
|
|
|
|
$orig->($class, |
28
|
|
|
|
|
|
|
field => $field, |
29
|
|
|
|
|
|
|
map { $_ => $opts{$_} } |
30
|
|
|
|
|
|
|
qw(attributes ns root depth content path whitespace) |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has _reader => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
lazy => 1, |
37
|
|
|
|
|
|
|
builder => sub { |
38
|
|
|
|
|
|
|
XML::Struct::Reader->new( |
39
|
|
|
|
|
|
|
map { $_ => $_[0]->$_ } grep { defined $_[0]->$_ } |
40
|
|
|
|
|
|
|
qw(attributes ns simple root depth content whitespace) |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub emit { |
46
|
|
|
|
|
|
|
my ($self,$fixer) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $path = $fixer->split_path($self->field); |
49
|
|
|
|
|
|
|
my $key = pop @$path; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $reader = $fixer->capture($self->_reader); |
52
|
|
|
|
|
|
|
my $xpath = $fixer->capture($self->path); |
53
|
|
|
|
|
|
|
my $attributes = $fixer->capture($self->attributes); |
54
|
|
|
|
|
|
|
# TODO: use XML::Struct::Simple instead |
55
|
|
|
|
|
|
|
my $options = $fixer->capture({ |
56
|
|
|
|
|
|
|
map { $_ => $self->$_ } grep { defined $self->$_ } |
57
|
|
|
|
|
|
|
qw(root depth attributes) |
58
|
|
|
|
|
|
|
}); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return $fixer->emit_walk_path($fixer->var,$path,sub{ |
61
|
|
|
|
|
|
|
my $var = $_[0]; |
62
|
|
|
|
|
|
|
$fixer->emit_get_key($var,$key,sub{ |
63
|
|
|
|
|
|
|
my $var = $_[0]; |
64
|
|
|
|
|
|
|
return <
|
65
|
|
|
|
|
|
|
if (ref(${var}) and ref(${var}) =~ /^ARRAY/) { |
66
|
|
|
|
|
|
|
${var} = XML::Struct::simpleXML( ${var}, %{${options}} ); |
67
|
|
|
|
|
|
|
} else { |
68
|
|
|
|
|
|
|
# TODO: code duplication with xml_read |
69
|
|
|
|
|
|
|
my \$stream = XML::LibXML::Reader->new( string => ${var} ); |
70
|
|
|
|
|
|
|
${var} = ${xpath} |
71
|
|
|
|
|
|
|
? [ ${reader}->readDocument(\$stream, ${xpath}) ] |
72
|
|
|
|
|
|
|
: ${reader}->readDocument(\$stream); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
PERL |
75
|
|
|
|
|
|
|
}); |
76
|
|
|
|
|
|
|
}); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
__END__ |