| 1 | package # hide from pause | ||||||||||||||||||||
| 2 | Monitoring::Livestatus::Class::Base::Table; | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 3 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 3 | ▶ | use Monitoring::Livestatus::Class::Abstract::Filter; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 3 | ▶ | use Monitoring::Livestatus::Class::Abstract::Stats; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 3 | ▶ | use Monitoring::Livestatus::Class; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 3 | ▶ | my $TRACE = Monitoring::Livestatus::Class->TRACE() || 0; | ||||||||||||||||||
|
Condition50%1/2
'Monitoring::Livestatus::Class'->TRACE || 0
MC/DC0%0/1
'Monitoring::Livestatus::Class'->TRACE || 0
'Monitoring::Livestatus::Class'->TRACE
Truth table50%1/2
A
A= 'Monitoring::Livestatus::Class'->TRACE
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 3 | has 'ctx' => ( | |||||||||||||||||||
| 14 | is => 'rw', | ||||||||||||||||||||
| 15 | isa => 'Monitoring::Livestatus::Class', | ||||||||||||||||||||
| 16 | handles => [qw/backend_obj/], | ||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | # | ||||||||||||||||||||
| 20 | # Filter Stuff | ||||||||||||||||||||
| 21 | # | ||||||||||||||||||||
| 22 | 3 | has 'filter_obj' => ( | |||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||
| 24 | isa => 'Monitoring::Livestatus::Class::Abstract::Filter', | ||||||||||||||||||||
| 25 | builder => '_build_filter', | ||||||||||||||||||||
| 26 | handles => { apply_filer => 'apply' }, | ||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 15 | ▶ | sub _build_filter { return Monitoring::Livestatus::Class::Abstract::Filter->new(); }; | ||||||||||||||||||
|
Subroutine
_build_filter: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | ▶ | sub filter { | ||||||||||||||||||
|
Subroutine
filter: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||
| 33 | 0 | my $cond = shift; | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | my @statments = $self->apply_filer($cond); | |||||||||||||||||||
| 36 | 0 | ▶ | my @tmp = @{ $self->statments || [] }; | ||||||||||||||||||
|
Condition0%0/2
$self->statments || []
MC/DC0%0/1
$self->statments || []
$self->statments
Truth table0%0/2
A
A= $self->statments
| |||||||||||||||||||||
| 37 | 0 | push @tmp, @statments; | |||||||||||||||||||
| 38 | 0 | $self->_statments(\@tmp); | |||||||||||||||||||
| 39 | 0 | return $self; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | ▶ | sub options { | ||||||||||||||||||
|
Subroutine
options: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 43 | 0 | my($self, $options) = @_; | |||||||||||||||||||
| 44 | 0 | $self->{'_options'} = $options; | |||||||||||||||||||
| 45 | 0 | return $self; | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | # | ||||||||||||||||||||
| 49 | # Stats Stuff | ||||||||||||||||||||
| 50 | # | ||||||||||||||||||||
| 51 | 3 | has 'stats_obj' => ( | |||||||||||||||||||
| 52 | is => 'ro', | ||||||||||||||||||||
| 53 | isa => 'Monitoring::Livestatus::Class::Abstract::Stats', | ||||||||||||||||||||
| 54 | builder => '_build_stats', | ||||||||||||||||||||
| 55 | handles => { apply_stats => 'apply' }, | ||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 15 | ▶ | sub _build_stats { return Monitoring::Livestatus::Class::Abstract::Stats->new(); }; | ||||||||||||||||||
|
Subroutine
_build_stats: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | ▶ | sub stats { | ||||||||||||||||||
|
Subroutine
stats: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||||||||||
| 62 | 0 | my $cond = shift; | |||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | my @statments = $self->apply_stats($cond); | |||||||||||||||||||
| 65 | 0 | ▶ | my @tmp = @{ $self->statments || [] }; | ||||||||||||||||||
|
Condition0%0/2
$self->statments || []
MC/DC0%0/1
$self->statments || []
$self->statments
Truth table0%0/2
A
A= $self->statments
| |||||||||||||||||||||
| 66 | 0 | push @tmp, @statments; | |||||||||||||||||||
| 67 | 0 | $self->_statments(\@tmp); | |||||||||||||||||||
| 68 | 0 | return $self; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 3 | has 'table_name' => ( | |||||||||||||||||||
| 72 | is => 'ro', | ||||||||||||||||||||
| 73 | isa => 'Str', | ||||||||||||||||||||
| 74 | builder => 'build_table_name', | ||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 0 | ▶ | sub build_table_name { die "build_table_name must be implemented in " . ref(shift) }; | ||||||||||||||||||
|
Subroutine
build_table_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | # | ||||||||||||||||||||
| 80 | # Primary key stuff | ||||||||||||||||||||
| 81 | # | ||||||||||||||||||||
| 82 | 3 | has 'primary_keys' => ( | |||||||||||||||||||
| 83 | is => 'ro', | ||||||||||||||||||||
| 84 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||
| 85 | builder => 'build_primary_keys', | ||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | ▶ | sub build_primary_keys { die "build_primary_keys must be implemented in " . ref(shift) }; | ||||||||||||||||||
|
Subroutine
build_primary_keys: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | ▶ | sub has_single_primary_key { | ||||||||||||||||||
|
Subroutine
has_single_primary_key: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 91 | 0 | my $self = shift; | |||||||||||||||||||
| 92 | 0 | ▶ | if ( scalar @{ $self->primary_keys } == 1 ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | 0 | return 1 | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | 0 | return; | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 0 | ▶ | sub single_primary_key { | ||||||||||||||||||
|
Subroutine
single_primary_key: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 99 | 0 | my $self = shift; | |||||||||||||||||||
| 100 | 0 | ▶ | if ( $self->has_single_primary_key ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | 0 | return $self->primary_keys->[0]; | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | 0 | return; | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | has '_statments' => ( | ||||||||||||||||||||
| 107 | is => 'rw', | ||||||||||||||||||||
| 108 | reader => 'statments', | ||||||||||||||||||||
| 109 | isa => 'ArrayRef', | ||||||||||||||||||||
| 110 | 15 | ▶ | default => sub { return []; } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 111 | 3 | ); | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | has '_options' => ( | ||||||||||||||||||||
| 114 | is => 'rw', | ||||||||||||||||||||
| 115 | isa => 'HashRef', | ||||||||||||||||||||
| 116 | 15 | ▶ | default => sub { return {}; } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 117 | 3 | ); | |||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | has '_columns' => ( | ||||||||||||||||||||
| 120 | is => 'rw', | ||||||||||||||||||||
| 121 | isa => 'ArrayRef', | ||||||||||||||||||||
| 122 | 15 | ▶ | default => sub { return []; } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 123 | 3 | ); | |||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 0 | ▶ | sub columns { | ||||||||||||||||||
|
Subroutine
columns: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 126 | 0 | my $self = shift; | |||||||||||||||||||
| 127 | 0 | my @columns = @_ ; | |||||||||||||||||||
| 128 | 0 | $self->_columns( \@columns ); | |||||||||||||||||||
| 129 | 0 | return $self; | |||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 0 | ▶ | sub headers{ | ||||||||||||||||||
|
Subroutine
headers: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 133 | 0 | my $self = shift; | |||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 0 | my $statment = sprintf("GET %s\nLimit: 1",$self->table_name); | |||||||||||||||||||
| 136 | 0 | my ( $hash_ref ) = @{ $self->backend_obj->selectall_arrayref($statment,{ slice => 1}) }; | |||||||||||||||||||
| 137 | 0 | my @cols = keys %$hash_ref; | |||||||||||||||||||
| 138 | 0 | ▶ | return wantarray ? @cols : \@cols; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 139 | } | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | 0 | ▶ | sub hashref_array { | ||||||||||||||||||
|
Subroutine
hashref_array: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 142 | 0 | my $self = shift; | |||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 0 | my @statments = (); | |||||||||||||||||||
| 145 | 0 | ▶ | if ( scalar @{ $self->_columns } > 0 ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 146 | 0 | push @statments, sprintf('Columns: %s',join(' ',@{ $self->_columns })); | |||||||||||||||||||
| 147 | } | ||||||||||||||||||||
| 148 | 0 | push @statments, @{ $self->statments }; | |||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | 0 | my @data = $self->_execute( @statments ); | |||||||||||||||||||
| 151 | 0 | ▶ | return wantarray ? @data : \@data; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 152 | } | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | 0 | ▶ | sub hashref_pk { | ||||||||||||||||||
|
Subroutine
hashref_pk: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||
| 155 | 0 | my $self = shift; | |||||||||||||||||||
| 156 | 0 | ▶ | my $key = $self->single_primary_key || shift; | ||||||||||||||||||
|
Condition0%0/3
$self->single_primary_key || shift()
MC/DC0%0/2
$self->single_primary_key || shift()
$self->single_primary_key
shift()
Truth table0%0/3
A || B
A= $self->single_primary_keyB= shift()
| |||||||||||||||||||||
| 157 | 0 | ▶ | unless ( $key ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 158 | 0 | croak("There was no single primary key to be found."); | |||||||||||||||||||
| 159 | }; | ||||||||||||||||||||
| 160 | 0 | my %indexed; | |||||||||||||||||||
| 161 | 0 | my @data = $self->hashref_array(); | |||||||||||||||||||
| 162 | 0 | for my $row (@data) { | |||||||||||||||||||
| 163 | 0 | ▶ | if(!defined $row->{$key}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 164 | 0 | my %possible_keys = keys %{$row}; | |||||||||||||||||||
| 165 | 0 | croak("key $key not found in result set, possible keys are: ".join(', ', sort keys %possible_keys)); | |||||||||||||||||||
| 166 | } else { | ||||||||||||||||||||
| 167 | 0 | $indexed{$row->{$key}} = $row; | |||||||||||||||||||
| 168 | } | ||||||||||||||||||||
| 169 | } | ||||||||||||||||||||
| 170 | 0 | ▶ | return wantarray ? %indexed : \%indexed; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 171 | } | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | 0 | ▶ | sub _execute { | ||||||||||||||||||
|
Subroutine
_execute: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 174 | 0 | my $self = shift; | |||||||||||||||||||
| 175 | 0 | my @data = @_; | |||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | 0 | my @statments = (); | |||||||||||||||||||
| 178 | 0 | push @statments, sprintf("GET %s",$self->table_name); | |||||||||||||||||||
| 179 | 0 | push @statments, @data; | |||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | 0 | ▶ | printf STDERR "EXECUTE: %s\n", join("\nEXECUTE: ",@statments) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 182 | if $TRACE >= 1; | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | 0 | my $statment = join("\n",@statments); | |||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | 0 | my $options = $self->{'_options'}; | |||||||||||||||||||
| 187 | 0 | $options->{'slice'} = {}; | |||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | 0 | my $return = $self->backend_obj->selectall_arrayref($statment, $options); | |||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | 0 | ▶ | return wantarray ? @{ $return } : $return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 192 | } | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | 3 | 1; | |||||||||||||||||||
| 195 | __END__ | ||||||||||||||||||||