blib/lib/Monitoring/Livestatus/Class/Lite.pm

filter: Statementstmt 65.5% 156 / 238 Branchbran 43.1% 38 / 88 Conditioncond 61.7% 21 / 34 MC/DCmcdc 36.8% 7 / 19 Subroutinesub 62.1% 23 / 37 Podpod 100% 12 / 12 totaltotal 60.0% 257 / 428 CC 63 SCAR 26.1
CC
63
Cov
60%
statement
72.0
hashref_pk
56.0
hashref_array
12.0
CRAP 13.6
↑ Summary
1 package Monitoring::Livestatus::Class::Lite;
2  
3 =head1 NAME
4  
5 Monitoring::Livestatus::Class::Lite - Object-Oriented interface for
6 Monitoring::Livestatus
7  
8 =head1 DESCRIPTION
9  
10 This module is an object-oriented interface for Monitoring::Livestatus.
11 Just like Monitoring::Livestatus::Class but without Moose.
12  
13 =head1 SYNOPSIS
14  
15 use Monitoring::Livestatus::Class::Lite;
16  
17 my $class = Monitoring::Livestatus::Class::Lite->new({
18 peer => '/var/lib/nagios3/rw/livestatus.sock'
19 });
20 # or shorter
21 my $class = Monitoring::Livestatus::Class::Lite->new(
22 '/var/lib/nagios3/rw/livestatus.sock'
23 );
24  
25 my $hosts = $class->table('hosts');
26 my @data = $hosts->columns('display_name')->filter(
27 { display_name => { '-or' => [qw/test_host_47 test_router_3/] } }
28 )->hashref_array();
29  
30 use Data::Dumper;
31 print Dumper \@data;
32  
33 =head1 ATTRIBUTES
34  
35 =head2 peer
36  
37 Connection point to the livestatus addon. This can be a unix
38 domain or tcp socket.
39  
40 =head3 Socket
41  
42 my $class = Monitoring::Livestatus::Class->new(
43 peer => '/var/lib/nagios3/rw/livestatus.sock'
44 );
45  
46 =head3 TCP Connection
47  
48 my $class = Monitoring::Livestatus::Class->new(
49 peer => '192.168.1.1:2134'
50 );
51  
52 =head1 ENVIRONMENT VARIABLES
53  
54 =head2 MONITORING_LIVESTATUS_CLASS_TRACE
55  
56 Print tracer output from this object.
57  
58 =head2 MONITORING_LIVESTATUS_CLASS_TEST_PEER
59  
60 Set peer for live tests.
61  
62 =cut
63  
64 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 6 ▶use Carp qw/croak confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 6 ▶use Monitoring::Livestatus ();
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 6 our $VERSION = '0.07';
70  
71 6 our $compining_prefix = '';
72 6 our $filter_mode = '';
73 6 our $filter_cache = {};
74 6 my $operators = {
75 'and' => '_cond_compining',
76 'or' => '_cond_compining',
77 'groupby' => '_cond_op_groupby',
78 'sum' => '_cond_op_simple',
79 'min' => '_cond_op_simple',
80 'max' => '_cond_op_simple',
81 'avg' => '_cond_op_simple',
82 'std' => '_cond_op_simple',
83 'isa' => '_cond_op_isa',
84 };
85  
86 ################################################################################
87  
88 =head1 METHODS
89  
90 =head2 new
91  
92 new($options)
93  
94 create new Class module
95  
96 =cut
97 5 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
98 5 my($class, @args) = @_;
99  
100 5 my $self = {};
101 5 ▶ if(scalar @args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args == 1) { } 2 3 5
102 2 ▶ if(ref $args[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[0] eq 'HASH') { } 1 1 2
103 1 $self = $args[0];
104 } else {
105 1 $self->{'peer'} = $args[0];
106 }
107 }
108 else {
109 3 my %args = @args;
110 3 $self = \%args;
111 }
112  
113 $self->{backend_obj} = Monitoring::Livestatus->new(
114 name => $self->{'name'},
115 peer => $self->{'peer'},
116 verbose => $self->{'verbose'},
117 5 keepalive => $self->{'keepalive'},
118 );
119 5 bless($self, $class);
120  
121 5 return $self;
122 }
123  
124 ################################################################################
125  
126 =head2 table
127  
128 table($tablename)
129  
130 return instance for this table
131  
132 =cut
133 0 ▶sub table {
Subroutine table: not called CC=2 SCAR=17.9
Pod documented
134 0 my($self, $name) = @_;
135 0 ▶ confess('need table name') unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
136 my $table = {
137 0 '_class' => $self->{'backend_obj'},
138 '_table' => $name,
139 };
140 0 bless($table, 'Monitoring::Livestatus::Class::Lite');
141 0 return $table;
142 }
143  
144 ################################################################################
145  
146 =head2 columns
147  
148 columns($columns)
149  
150 list of columns to fetch
151  
152 =cut
153 0 ▶sub columns {
Subroutine columns: not called CC=1 SCAR=6.9
Pod documented
154 0 my($self, @columns) = @_;
155 0 $self->{'_columns'} = \@columns;
156 0 return $self;
157 }
158  
159 ################################################################################
160  
161 =head2 options
162  
163 options($options)
164  
165 set query options
166  
167 =cut
168 0 ▶sub options {
Subroutine options: not called CC=1 SCAR=6.9
Pod documented
169 0 my($self, $options) = @_;
170 0 $self->{'_options'} = $options;
171 0 return $self;
172 }
173  
174 ################################################################################
175  
176 =head2 filter
177  
178 filter($filter)
179  
180 filter result set
181  
182 =cut
183 0 ▶sub filter {
Subroutine filter: not called CC=2 SCAR=17.9
Pod documented
184 0 my($self, $filter) = @_;
185 0 ▶ $self->{'_filter'} = $self->{'_filter'} ? [@{$self->{'_filter'}}, $filter] : [$filter];
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_filter'} ? : 0 0 0
186 0 return $self;
187 }
188  
189 ################################################################################
190  
191 =head2 stats
192  
193 stats($statsfilter)
194  
195 set stats filter
196  
197 =cut
198 0 ▶sub stats {
Subroutine stats: not called CC=2 SCAR=17.9
Pod documented
199 0 my($self, $filter) = @_;
200 0 ▶ $self->{'_statsfilter'} = $self->{'_statsfilter'} ? [@{$self->{'_statsfilter'}}, $filter] : [$filter];
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_statsfilter'} ? : 0 0 0
201 0 return $self;
202 }
203  
204 ################################################################################
205  
206 =head2 hashref_pk
207  
208 hashref_pk($key)
209  
210 return result as hash ref by key
211  
212 =cut
213 0 ▶sub hashref_pk {
Subroutine hashref_pk: not called CC=7 SCAR=40.3
Pod documented
214 0 my($self, $key) = @_;
215  
216 0 ▶ confess("no key!") unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 0 0
217  
218 0 ▶ return([$self->statement(), $self->{_columns}, $self->{_options}]) if $ENV{'THRUK_SELECT'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"THRUK_SELECT"} 0 0 0
219  
220 0 my %indexed;
221 0 my @data = $self->hashref_array();
222 0 ▶ confess('undefined index: '.$key) if(defined $data[0] && !defined $data[0]->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if defined $data[0] and not defined $data[0]{$key} 0 0 0
Condition0%0/3
defined $data[0] and not defined $data[0]{$key}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $data[0] and not defined $data[0]{$key}
defined $data[0] not defined $data[0]{$key}
Truth table0%0/3
A and not(B)
A= defined $data[0]B= not defined $data[0]{$key}
ABresult
0X0
100
111
223 0 for my $row (@data) {
224 0 $indexed{$row->{$key}} = $row;
225 }
226 0 ▶ return wantarray ? %indexed : \%indexed;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
227 }
228  
229 ################################################################################
230  
231 =head2 hashref_array
232  
233 hashref_array()
234  
235 return result as array
236  
237 =cut
238 0 ▶sub hashref_array {
Subroutine hashref_array: not called CC=3 SCAR=24.8
Pod documented
239 0 my($self) = @_;
240 0 ▶ return([$self->statement(), $self->{_columns}, $self->{_options}]) if $ENV{'THRUK_SELECT'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"THRUK_SELECT"} 0 0 0
241 0 my @data = $self->_execute();
242 0 ▶ return wantarray ? @data : \@data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
243 }
244  
245 ################################################################################
246  
247 =head2 reset_filter
248  
249 reset_filter()
250  
251 removes all current filter
252  
253 =cut
254 0 ▶sub reset_filter {
Subroutine reset_filter: not called CC=1 SCAR=6.9
Pod documented
255 0 my($self) = @_;
256 0 $self->{'_filter'} = undef;
257 0 $self->{'_statsfilter'} = undef;
258 0 return($self);
259 }
260  
261 ################################################################################
262  
263 =head2 save_filter
264  
265 save_filter($name)
266  
267 save this filter with given name which can be reused later.
268  
269 =cut
270 0 ▶sub save_filter {
Subroutine save_filter: not called CC=1 SCAR=6.9
Pod documented
271 0 my($self, $name) = @_;
272 0 $filter_cache->{$name} = $self->statement(1);
273 0 return($self);
274 }
275  
276 ################################################################################
277  
278 =head2 apply_filter
279  
280 apply_filter($name)
281  
282 returns true if a filter with this name has been applied. returns false if filter
283 does not exist.
284  
285 =cut
286 0 ▶sub apply_filter {
Subroutine apply_filter: not called CC=2 SCAR=17.9
Pod documented
287 0 my($self, $name) = @_;
288 0 ▶ return unless $filter_cache->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $Monitoring::Livestatus::Class::Lite::filter_cache->{$name} 0 0 0
289 0 $self->{'_extra_stm'} = $filter_cache->{$name};
290 0 $self->{'_columns'} = undef;
291 0 return($self);
292 }
293  
294 ################################################################################
295  
296 =head2 statement
297  
298 statement($filter_only)
299  
300 return query as text.
301  
302 =cut
303 0 ▶sub statement {
Subroutine statement: not called CC=8 SCAR=42.8
Pod documented
304 0 my($self, $filter_only) = @_;
305  
306 0 ▶ confess("no table??") unless $self->{'_table'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_table"} 0 0 0
307  
308 0 my @statements = ();
309 0 ▶ if( $self->{'_columns'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_columns"}) 0 0 0
310 0 push @statements, sprintf('Columns: %s',join(' ',@{ $self->{'_columns'} }));
311 }
312  
313 # filtering
314 0 ▶ if( $self->{'_filter'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_filter"}) 0 0 0
315 0 push @statements, @{$self->_apply_filter($self->{'_filter'})};
316 }
317 0 ▶ if( $self->{'_statsfilter'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_statsfilter"}) 0 0 0
318 0 push @statements, @{$self->_apply_filter($self->{'_statsfilter'}, 'Stats')};
319 }
320 0 ▶ if( $self->{'_extra_stm'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_extra_stm"}) 0 0 0
321 0 push @statements, @{$self->{'_extra_stm'}};
322 }
323 0 ▶ return(\@statements) if $filter_only;
Branch: 1 branch
BranchTrueFalseTotal
if $filter_only 0 0 0
324  
325 0 unshift @statements, sprintf("GET %s", $self->{'_table'});
326  
327 0 ▶ printf STDERR "EXEC: %s\n", join("\nEXEC: ",@statements) if $ENV{'MONITORING_LIVESTATUS_CLASS_TRACE'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"MONITORING_LIVESTATUS_CLASS_TRACE"} 0 0 0
328  
329 0 my $statement = join("\n",@statements);
330  
331 0 return $statement;
332 }
333  
334 ################################################################################
335 # INTERNAL SUBs
336 ################################################################################
337 0 ▶sub _execute {
Subroutine _execute: not called CC=2 SCAR=17.9
338 0 my($self) = @_;
339 0 my $statement = $self->statement();
340 0 my $options = $self->{'_options'};
341 0 $options->{'slice'} = {};
342  
343 0 my $return = $self->{'_class'}->selectall_arrayref($statement, $options);
344  
345 0 ▶ return wantarray ? @{ $return } : $return;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
346 }
347  
348 ################################################################################
349 31 ▶sub _apply_filter {
Subroutine _apply_filter: called CC=4 SCAR=13.9
350 31 my($self, $filter, $mode) = @_;
351  
352 31 ▶ $compining_prefix = $mode || '';
Condition100%2/2
$mode || ''
l!l
625
MC/DC100%1/1
$mode || ''
$mode
Truth table100%2/2
A
A= $mode
Aresult
11
00
353 31 ▶ $filter_mode = $mode || 'Filter';
Condition100%2/2
$mode || 'Filter'
l!l
625
MC/DC100%1/1
$mode || 'Filter'
$mode
Truth table100%2/2
A
A= $mode
Aresult
11
00
354 #my( $combining_count, @statements)...
355 31 my( undef, @statements) = &_recurse_cond($filter);
356 31 ▶ return wantarray ? @statements: \@statements;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 31 31
357 }
358  
359 ################################################################################
360 144 ▶sub _recurse_cond {
Subroutine _recurse_cond: called CC=2 SCAR=6.9
361 144 my($cond, $combining_count) = @_;
362 144 ▶ $combining_count = 0 unless defined $combining_count;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $combining_count 31 113 144
363 144 my $method = '_cond_'.&_refkind($cond);
364 144 my($child_combining_count, @statement) = &{\&{$method}}($cond,$combining_count);
365 144 $combining_count = $child_combining_count;
366 144 return ( $combining_count, @statement );
367 }
368  
369 ################################################################################
370 0 ▶sub _cond_UNDEF { return ( () ); }
Subroutine _cond_UNDEF: not called CC=1 SCAR=6.9
371  
372 ################################################################################
373 37 ▶sub _cond_ARRAYREF {
Subroutine _cond_ARRAYREF: called CC=3 SCAR=11.0
374 37 my($conds, $combining_count) = @_;
375 37 ▶ $combining_count = $combining_count || 0;
Condition100%2/2
$combining_count || 0
l!l
136
MC/DC100%1/1
$combining_count || 0
$combining_count
Truth table100%2/2
A
A= $combining_count
Aresult
11
00
376 37 my @statement = ();
377  
378 37 my @cp_conds = @{ $conds }; # work with a copy
379 37 ▶ while(my $cond = shift @cp_conds) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cond = shift @cp_conds) 84 37 121
380 my($child_combining_count, @child_statement) = &_dispatch_refkind($cond, {
381 3 ▶ ARRAYREF => sub { &_recurse_cond($cond, $combining_count) },
Subroutine __ANON__: called CC=1 SCAR=0.0
382 13 ▶ HASHREF => sub { &_recurse_cond($cond, $combining_count) },
Subroutine __ANON__: called CC=1 SCAR=0.0
383 0 ▶ UNDEF => sub { croak "not supported : UNDEF in arrayref" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
384 68 ▶ SCALAR => sub { &_recurse_cond( { $cond => shift(@cp_conds) } , $combining_count ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
385 84 });
386 84 push @statement, @child_statement;
387 84 $combining_count = $child_combining_count;
388 }
389 37 return($combining_count, @statement);
390 }
391  
392 ################################################################################
393 107 ▶sub _cond_HASHREF {
Subroutine _cond_HASHREF: called CC=4 SCAR=13.9
394 107 my($cond, $combining_count) = @_;
395 107 ▶ $combining_count = 0 unless $combining_count;
Branch: 1 branch
BranchTrueFalseTotal
unless $combining_count 59 48 107
396 107 my $child_combining_count = 0;
397 107 my @all_statement;
398 my @child_statement;
399  
400 107 ▶ while(my($key, $value) = each %{$cond}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$cond;}) 107 107 214
401 107 ▶ if(substr($key,0,1) eq '-'){
Branch: 1 branch
BranchTrueFalseTotal
if (substr($key, 0, 1) eq '-') { } 22 85 107
402 # Child key for combining filters ( -and / -or )
403 22 ($child_combining_count, @child_statement) = &_cond_op_in_hash($key, $value, $combining_count);
404 22 $combining_count = $child_combining_count;
405 } else {
406 85 my $method = '_cond_hashpair_'.&_refkind($value);
407 85 ($child_combining_count, @child_statement) = &{\&{$method}}($key, $value, undef ,$combining_count);
408 85 $combining_count = $child_combining_count;
409 }
410  
411 107 push @all_statement, @child_statement;
412 }
413 107 return($combining_count, @all_statement);
414 }
415  
416 ################################################################################
417 2 ▶sub _cond_hashpair_UNDEF {
Subroutine _cond_hashpair_UNDEF: called CC=4 SCAR=14.3
418 #my($key, $value, $operator, $combining_count)...
419 2 my($key, undef, $operator, $combining_count) = @_;
420 2 ▶ $combining_count = 0 unless $combining_count;
Branch: 1 branch
BranchTrueFalseTotal
unless $combining_count 2 0 2
421 2 ▶ $key = '' unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 2 2
422 2 ▶ $operator = '=' unless $operator;
Branch: 1 branch
BranchTrueFalseTotal
unless $operator 2 0 2
423  
424 2 my @statement = (sprintf("%s: %s %s",$filter_mode,$key,$operator));
425 2 $combining_count++;
426 2 return ( $combining_count, @statement );
427 }
428  
429 ################################################################################
430 55 ▶sub _cond_hashpair_SCALAR {
Subroutine _cond_hashpair_SCALAR: called CC=4 SCAR=13.9
431 55 my($key, $value, $operator, $combining_count) = @_;
432 55 ▶ $combining_count = 0 unless $combining_count;
Branch: 1 branch
BranchTrueFalseTotal
unless $combining_count 38 17 55
433 55 ▶ my @statement = (sprintf("%s: %s %s %s",
Condition75%3/4
$key || ''
l!l
550
$operator || '='
l!l
1936
MC/DC0%0/1
$key || ''
$key
MC/DC100%1/1
$operator || '='
$operator
Truth table50%1/2
A
A= $key
Aresult
11
00
Truth table100%2/2
A
A= $operator
Aresult
11
00
434 $filter_mode,
435 ($key || '') ,
436 ($operator || '='),
437 $value),
438 );
439 55 $combining_count++;
440 55 return ( $combining_count, @statement );
441 }
442  
443 ################################################################################
444 19 ▶sub _cond_hashpair_ARRAYREF {
Subroutine _cond_hashpair_ARRAYREF: called CC=6 SCAR=18.0
445 19 ▶ my $key = shift || '';
Condition50%1/2
shift() || ''
l!l
190
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
446 19 ▶ my $values = shift || [];
Condition50%1/2
shift() || []
l!l
190
MC/DC0%0/1
shift() || []
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
447 19 ▶ my $operator = shift || '=';
Condition100%2/2
shift() || '='
l!l
910
MC/DC100%1/1
shift() || '='
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
448 19 ▶ my $combining_count = shift || 0;
Condition100%2/2
shift() || 0
l!l
712
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
449  
450 19 my @statement = ();
451 19 foreach my $value ( @{ $values }){
452 40 push @statement, sprintf("%s: %s %s %s",$filter_mode,$key,$operator,$value);
453 40 $combining_count++;
454 }
455 19 return ( $combining_count, @statement );
456 }
457  
458 ################################################################################
459 37 ▶sub _cond_hashpair_HASHREF {
Subroutine _cond_hashpair_HASHREF: called CC=7 SCAR=20.6
460 #my($key, $values, $combining, $combining_count)...
461 37 my($key, $values, undef, $combining_count) = @_;
462 37 ▶ $key = '' unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 37 37
463 37 ▶ $values = {} unless $values;
Branch: 1 branch
BranchTrueFalseTotal
unless $values 0 37 37
464 37 ▶ $combining_count = 0 unless $combining_count;
Branch: 1 branch
BranchTrueFalseTotal
unless $combining_count 20 17 37
465  
466 37 my @statement = ();
467  
468 37 foreach my $child_key ( keys %{ $values } ){
469 37 my $child_value = $values->{ $child_key };
470  
471 37 ▶ if ( $child_key =~ /^-/mxo ){
Branch: 2 branches
BranchTrueFalseTotal
if ($child_key =~ /^-/mox) { } 9 28 37
elsif ($child_key =~ /^[!<>=~]/mox) { } 28 0 28
472 9 my ( $child_combining_count, @child_statement ) = &_cond_op_in_hash($child_key, { $key => $child_value } , 0);
473 9 $combining_count += $child_combining_count;
474 9 push @statement, @child_statement;
475 } elsif ( $child_key =~ /^[!<>=~]/mxo ){
476 # Child key is a operator like:
477 # = equality
478 # ~ match regular expression (substring match)
479 # =~ equality ignoring case
480 # ~~ regular expression ignoring case
481 # < less than
482 # > greater than
483 # <= less or equal
484 # >= greater or equal
485 28 my $method = '_cond_hashpair_'.&_refkind($child_value);
486 28 my($child_combining_count, @child_statement) = &{\&{$method}}($key, $child_value,$child_key);
487 28 $combining_count += $child_combining_count;
488 28 push @statement, @child_statement;
489 } else {
490 0 my $method = '_cond_hashpair_'.&_refkind($child_value);
491 0 my ( $child_combining_count, @child_statement ) = &{\&{$method}}($key, $child_value);
492 0 $combining_count += $child_combining_count;
493 0 push @statement, @child_statement;
494 }
495 }
496 37 return ( $combining_count, @statement );
497 }
498  
499 ################################################################################
500 31 ▶sub _cond_op_in_hash {
Subroutine _cond_op_in_hash: called CC=3 SCAR=11.3
501 31 my($operator, $value, $combining_count) = @_;
502  
503 31 ▶ if ($operator && substr($operator,0,1) eq '-'){
Branch: 1 branch
BranchTrueFalseTotal
if ($operator and substr($operator, 0, 1) eq "-") 31 0 31
Condition33%1/3
$operator and substr($operator, 0, 1) eq "-"
!ll&&!rl&&r
0031
MC/DC0%0/2
$operator and substr($operator, 0, 1) eq "-"
$operator substr($operator, 0, 1) eq "-"
Truth table33%1/3
A and B
A= $operatorB= substr($operator, 0, 1) eq "-"
ABresult
0X0
100
111
504 31 $operator = substr($operator, 1); # remove -
505 31 $operator =~ s/\s+$//gmxo; # remove trailing space
506 }
507  
508 31 my $operator_handler = $operators->{lc $operator};
509 31 return &{\&{$operator_handler}}($operator,$value,$combining_count);
510 }
511  
512 ################################################################################
513 21 ▶sub _cond_compining {
Subroutine _cond_compining: called CC=6 SCAR=19.7
514 21 my $combining = shift;
515 21 my $value = shift;
516 21 ▶ my $combining_count = shift || 0;
Condition100%2/2
shift() || 0
l!l
516
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
517 21 $combining_count++;
518 21 my @statement = ();
519  
520 21 ▶ if ($combining && substr($combining,0,1) eq '-'){
Branch: 1 branch
BranchTrueFalseTotal
if ($combining and substr($combining, 0, 1) eq "-") 0 21 21
Condition33%1/3
$combining and substr($combining, 0, 1) eq "-"
!ll&&!rl&&r
0210
MC/DC0%0/2
$combining and substr($combining, 0, 1) eq "-"
$combining substr($combining, 0, 1) eq "-"
Truth table33%1/3
A and B
A= $combiningB= substr($combining, 0, 1) eq "-"
ABresult
0X0
100
111
521 0 $combining = substr($combining, 1); # remove -
522 0 $combining =~ s/\s+$//gmxo; # remove trailing space
523 }
524 21 my($child_combining_count, @child_statement) = &_recurse_cond($value, 0);
525 21 push @statement, @child_statement;
526 21 ▶ if(defined $combining and $child_combining_count > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $combining and $child_combining_count > 1) 21 0 21
Condition33%1/3
defined $combining and $child_combining_count > 1
!ll&&!rl&&r
0021
MC/DC0%0/2
defined $combining and $child_combining_count > 1
defined $combining $child_combining_count > 1
Truth table33%1/3
A and B
A= defined $combiningB= $child_combining_count > 1
ABresult
0X0
100
111
527 21 push @statement, sprintf("%s%s: %d",
528 $compining_prefix,
529 ucfirst( $combining ),
530 $child_combining_count,
531 );
532 }
533 21 return ( $combining_count, @statement );
534 }
535  
536 ################################################################################
537 341 ▶sub _refkind {
Subroutine _refkind: called CC=3 SCAR=11.0
538 341 my $ref = ref $_[0];
539 341 ▶ return(uc($ref).'REF') if $ref;
Branch: 1 branch
BranchTrueFalseTotal
if $ref 216 125 341
540 125 ▶ return('UNDEF') if !defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 2 123 125
541 123 return('SCALAR');
542 }
543  
544 ################################################################################
545 84 ▶sub _dispatch_refkind {
Subroutine _dispatch_refkind: called CC=2 SCAR=7.0
546 84 my($value, $dispatch_table) = @_;
547  
548 84 my $type = &_refkind($value);
549 84 ▶ my $coderef = $dispatch_table->{$type} ||
Condition50%1/2
$dispatch_table->{$type} || die(sprintf('No coderef for %s ( %s ) found!', $value, $type))
l!l
840
MC/DC0%0/1
$dispatch_table->{$type} || die(sprintf('No coderef for %s ( %s ) found!', $value, $type))
$dispatch_table->{$type}
Truth table50%1/2
A
A= $dispatch_table->{$type}
Aresult
11
00
550 die(sprintf("No coderef for %s ( %s ) found!",$value, $type));
551  
552 84 return $coderef->();
553 }
554  
555 ################################################################################
556 1 ▶sub _cond_op_groupby {
Subroutine _cond_op_groupby: called CC=2 SCAR=7.2
557 #my($operator, $value, $combining_count) = @_;
558 1 ▶ $_[2] = 0 unless defined $_[2];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[2] 0 1 1
559 1 return(++$_[2], (sprintf("%s%s: %s", $compining_prefix, 'GroupBy', $_[1])));
560 }
561  
562 ################################################################################
563 1 ▶sub _cond_op_simple {
Subroutine _cond_op_simple: called CC=2 SCAR=7.1
564 1 my($operator, $value, $combining_count) = @_;
565 1 ▶ $combining_count = 0 unless defined $combining_count;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $combining_count 0 1 1
566 1 return(++$combining_count, (sprintf("%s: %s %s",$compining_prefix,$operator,$value)));
567 }
568  
569 ################################################################################
570 8 ▶sub _cond_op_isa {
Subroutine _cond_op_isa: called CC=3 SCAR=11.1
571 #my($operator, $value, $combining_count) = @_;
572 8 my(undef, $value, $combining_count) = @_;
573 8 ▶ $combining_count = 0 unless defined $combining_count;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $combining_count 0 8 8
574  
575 8 my @keys = keys %{$value};
576 8 ▶ if(scalar @keys != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @keys != 1) 0 8 8
577 0 die "Isa operator doesn't support more then one key.";
578 }
579 8 my $as_name = shift @keys;
580 8 my @values = values(%{$value});
581 8 my($child_combining_count, @statement) = &_recurse_cond(shift( @values ), 0);
582  
583 8 $combining_count += $child_combining_count;
584  
585 # append alias to last operator
586 8 $statement[-1] .= " as ".$as_name;
587  
588 8 return($combining_count, @statement);
589 }
590  
591 ################################################################################
592  
593 6 1;
594 __END__
↑ Summary