Fix/xml_transform.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Exporter/XML.pm ↑ Summary Importer/XML.pm »
1 package Catmandu::Fix::xml_transform;
2  
3 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 Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 0 ▶use Catmandu::XML::Transformer;
Subroutine BEGIN: called CC=1 SCAR=2.6
9  
10 with 'Catmandu::Fix::Base';
11  
12 has field => (fix_arg => 1);
13 has file => (fix_opt => 1);
14 has format => (fix_opt => 1);
15  
16 has _transformer => (
17 is => 'ro',
18 lazy => 1,
19 default => sub {
20 Catmandu::XML::Transformer->new(
21 stylesheet => $_[0]->file,
22 output_format => $_[0]->format,
23 );
24 }
25 );
26  
27 sub emit {
28 my ($self,$fixer) = @_;
29  
30 my $path = $fixer->split_path($self->field());
31 my $key = pop @$path;
32
33 my $transformer = $fixer->capture($self->_transformer);
34  
35 return $fixer->emit_walk_path($fixer->var,$path,sub{
36 my $var = $_[0];
37 $fixer->emit_get_key($var,$key,sub{
38 my $var = $_[0];
39 return "${var} = ${transformer}->transform(${var});";
40 });
41 });
42 }
43  
44 1;
45 __END__
« Exporter/XML.pm ↑ Summary Importer/XML.pm »