Fix/xml_write.pm

filter: Statementstmt 100% 41 / 41 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 1 totaltotal 98.1% 52 / 53 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Fix/xml_read.pm ↑ Summary
1 package Catmandu::Fix::xml_write;
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::Writer;
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 pretty => (fix_opt => 1);
16 2 ▶has encoding => (fix_opt => 1, default => sub { 'UTF-8' });
Subroutine __ANON__: called CC=1 SCAR=0.0
17 1 has version => (fix_opt => 1);
18 1 has standalone => (fix_opt => 1);
19 1 ▶has xmldecl => (fix_opt => 1, default => sub { 1 });
Subroutine __ANON__: called CC=1 SCAR=0.0
20  
21 has _writer => (
22 is => 'ro',
23 lazy => 1,
24 2 ▶ builder => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
25 XML::Struct::Writer->new(
26 2 map { $_ => $_[0]->$_ } grep { defined $_[0]->$_ }
27 qw(attributes pretty encoding version standalone xmldecl)
28 );
29 }
30 1 );
31  
32 2 ▶sub emit {
Subroutine emit: called CC=1 SCAR=0.0
Pod undocumented
33 2 my ($self,$fixer) = @_;
34  
35 2 my $path = $fixer->split_path($self->field);
36 2 my $key = pop @$path;
37
38 2 my $writer = $fixer->capture($self->_writer);
39 2 my $pretty = $fixer->capture($self->pretty);
40  
41 2 ▶ return $fixer->emit_walk_path($fixer->var,$path,sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
42 2 my $var = $_[0];
43 2 ▶ $fixer->emit_get_key($var,$key,sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
44 2 my $var = $_[0];
45 2 return "${var} = (ref(${var}) =~ 'XML::LibXML::Document=')" .
46 "? ${var}->serialize(${pretty}) : do {".
47 "my \$s=''; ${writer}->to(\\\$s); ${writer}->write(${var}); \$s" .
48 "}";
49 2 });
50 2 });
51 }
52  
53 1 1;
54 __END__
« Fix/xml_read.pm ↑ Summary