Connector/Iterator.pm

filter: Statementstmt 90.3% 56 / 62 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 88.8% 72 / 81 CC 7 SCAR 10.9
CC
7
Cov
88%
set
5.0
_init_target
3.5
BEGIN
1.0
CRAP 3.0
« Connector/Proxy/Config/Std.pm ↑ Summary Connector/Proxy/YAML.pm »
1 package Connector::Iterator;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 extends 'Connector';
11  
12 2 has 'BASECONNECTOR' => ( is => 'ro', required => 1 );
13  
14 # Location must not be used
15 2 has '+LOCATION' => ( required => 0, 'isa' => 'Undef' );
16  
17 2 has target => (
18 is => 'rw',
19 isa => 'Undef|ArrayRef',
20 lazy => 1,
21 builder => '_init_target',
22 );
23  
24 2 has skip_on_error => (
25 is => 'rw',
26 isa => 'Bool',
27 default => 0,
28 );
29  
30 2 ▶sub _init_target {
Subroutine _init_target: called CC=3 SCAR=12.5
31  
32 2 my $self = shift;
33  
34 # the connectors prefix points to the root node of the target list
35 2 my @target_node = $self->_build_path_with_prefix();
36
37 2 ▶ if (!$self->BASECONNECTOR()->exists( \@target_node )) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->BASECONNECTOR->exists(\@target_node)) 0 2 2
38 0 $self->log()->warn( 'Target node does not exists ' . join(".", \@target_node) );
39 0 return;
40 }
41  
42 2 $self->log()->debug( 'Node with targets' . Dumper \@target_node );
43
44 2 my @targets = $self->BASECONNECTOR()->get_keys( \@target_node );
45
46 2 ▶ if (!scalar @targets) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @targets) 0 2 2
47 0 $self->log()->warn( 'No targets found!' );
48 0 return;
49 }
50
51 2 $self->log()->debug( 'Targets ' . Dumper \@targets );
52
53 2 return \@targets;
54 }
55  
56 3 ▶sub set {
Subroutine set: called CC=5 SCAR=16.1
Pod documented
57
58 3 my $self = shift;
59 3 my $item = shift;
60 3 my $data = shift;
61  
62 3 my $targets = $self->target();
63
64 3 ▶ if (!$targets) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($targets) 0 3 3
65 0 $self->log()->error( 'No targets found!' );
66 0 return $self->_node_not_exists();
67 }
68
69 3 my @item_path = $self->_build_path( $item );
70 3 $self->log()->debug( 'Item path' . Dumper \@item_path);
71
72 # Initialize the base connector
73 3 my $baseconn = $self->BASECONNECTOR();
74  
75 3 my $result;
76
77 3 foreach my $target (@{$targets}) {
78
79 5 $self->log()->debug( 'Publication to ' . $target . ' with item ' . Dumper $item );
80
81 5 my @publication_target = $self->_build_path_with_prefix( [ $target, @item_path ] );
82
83 5 $result->{$target} = '';
84 5 my $res;
85 5 ▶ if ($self->skip_on_error()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->skip_on_error) { } 2 3 5
86 2 eval{ $res = $baseconn->set( \@publication_target , $data ); };
87 2 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Connector::Iterator::EVAL_ERROR) 1 1 2
88 1 $EVAL_ERROR =~ /\A(.{1,200})/;
89 1 $result->{$target} = $1;
90 }
91 } else {
92 3 $res = $baseconn->set( \@publication_target , $data );
93 }
94 4 $self->log()->debug('Publication result: ' . Dumper $res );
95 }
96  
97 2 return $result;
98 }
99  
100 2 1;
101  
102 __END__;
« Connector/Proxy/Config/Std.pm ↑ Summary Connector/Proxy/YAML.pm »