Fix/xml_read.pm

filter: Statementstmt 100% 41 / 41 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 98.0% 50 / 51 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Fix/xml_simple.pm ↑ Summary Fix/xml_write.pm »
1 package Catmandu::Fix::xml_read;
2  
3 1 our $VERSION = '0.17';
4  
5 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use XML::Struct::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use XML::LibXML::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 with 'Catmandu::Fix::Base';
12  
13 1 has field => (fix_arg => 1);
14 1 has attributes => (fix_opt => 1);
15 1 has ns => (fix_opt => 1);
16 1 has content => (fix_opt => 1);
17 1 has simple => (fix_opt => 1);
18 1 has root => (fix_opt => 1);
19 1 has depth => (fix_opt => 1);
20 1 has path => (fix_opt => 1);
21 1 has whitespace => (fix_opt => 1);
22  
23 has _reader => (
24 is => 'ro',
25 lazy => 1,
26 4 ▶ builder => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
27 XML::Struct::Reader->new(
28 4 map { $_ => $_[0]->$_ } grep { defined $_[0]->$_ }
29 qw(attributes ns simple root depth content whitespace)
30 );
31 }
32 1 );
33  
34 4 ▶sub emit {
Subroutine emit: called CC=1 SCAR=0.0
Pod undocumented
35 4 my ($self,$fixer) = @_;
36  
37 4 my $path = $fixer->split_path($self->field);
38 4 my $key = pop @$path;
39
40 4 my $reader = $fixer->capture($self->_reader);
41 4 my $xpath = $fixer->capture($self->path);
42  
43 4 ▶ return $fixer->emit_walk_path($fixer->var,$path,sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
44 4 my $var = $_[0];
45 4 ▶ $fixer->emit_get_key($var,$key,sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
46 4 my $var = $_[0];
47 4 return "my \$stream = XML::LibXML::Reader->new( string => ${var} );".
48 "${var} = ${xpath} ? [ ${reader}->readDocument(\$stream, ${xpath}) ] " .
49 ": ${reader}->readDocument(\$stream);";
50 4 });
51 4 });
52 }
53  
54 1 1;
55 __END__
« Fix/xml_simple.pm ↑ Summary Fix/xml_write.pm »