RegMgr/Monitor.pm

filter: Statementstmt 34.7% 25 / 72 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 53.3% 8 / 15 Podpod 25.0% 1 / 4 totaltotal 31.1% 34 / 109 CC 13 SCAR 33.3
CC
13
Cov
28%
_cb_monitor
72.0
_is_differ
30.0
STOP
6.0
CRAP 27.9
« RegMgr/Utils.pm ↑ Summary RegMgr/Service.pm »
1 package Inferno::RegMgr::Monitor;
2 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = 'v1.0.0';
9  
10 1 ▶use Scalar::Util qw( weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Inferno::RegMgr::Utils qw( run_callback );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Inferno::RegMgr::Lookup;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
17 0 my ($class, $opt) = @_;
18 my $self = {
19 lookup => undef,
20 cb_add => $opt->{cb_add},
21 cb_del => $opt->{cb_del},
22 cb_mod => $opt->{cb_mod},
23 method_add => $opt->{method_add},
24 method_del => $opt->{method_del},
25 method_mod => $opt->{method_mod},
26 0 manager => undef,
27 cur => {},
28 };
29 0 bless $self, $class;
30 0 weaken( my $this = $self );
31 $self->{lookup} = Inferno::RegMgr::Lookup->new({
32 attr => $opt->{attr},
33 0 ▶ cb => sub { $this->_cb_monitor(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 0 });
35 0 return $self;
36 }
37  
38 0 ▶sub START {
Subroutine START: not called CC=1 SCAR=6.9
Pod undocumented
39 0 my ($self) = @_;
40 0 $self->{manager}->attach( $self->{lookup} );
41 0 return;
42 }
43  
44 0 ▶sub _cb_monitor {
Subroutine _cb_monitor: not called CC=8 SCAR=42.8
45 0 my ($self, $svc) = @_;
46 0 my @prev = keys %{ $self->{cur} };
47 0 for my $name (@prev) {
48 0 ▶ if (exists $svc->{ $name }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $svc->{$name}) { } 0 0 0
49 0 my $attr = delete $svc->{ $name };
50 0 ▶ if (_is_differ($self->{cur}{ $name }, $attr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_differ($self->{"cur"}{$name}, $attr)) 0 0 0
51 0 $self->{cur}{ $name } = $attr;
52 0 ▶ if (defined $self->{cb_mod}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"cb_mod"}) 0 0 0
53 0 run_callback( $self->{cb_mod}, $self->{method_mod}, $name => $attr );
54 }
55 }
56 }
57 else {
58 0 my $attr = delete $self->{cur}{ $name };
59 0 ▶ if (defined $self->{cb_del}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"cb_del"}) 0 0 0
60 0 run_callback( $self->{cb_del}, $self->{method_del}, $name => $attr );
61 }
62 }
63 }
64 0 for my $name (keys %{ $svc }) {
65 0 my $attr = $svc->{ $name };
66 0 $self->{cur}{ $name } = $attr;
67 0 ▶ if (defined $self->{cb_add}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"cb_add"}) 0 0 0
68 0 run_callback( $self->{cb_add}, $self->{method_add}, $name => $attr );
69 }
70 }
71 0 return;
72 }
73  
74 0 ▶sub _is_differ {
Subroutine _is_differ: not called CC=5 SCAR=34.0
75 0 my ($h1, $h2) = @_;
76 0 ▶ return 1 if keys %{ $h1 } != keys %{ $h2 };
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$h1;} != keys %{$h2;} 0 0 0
77 0 for my $key (keys %{ $h1 }) {
78 0 ▶ return 1 if !exists $h2->{ $key };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $h2->{$key} 0 0 0
79 0 ▶ return 1 if $h1->{ $key } ne $h2->{ $key };
Branch: 1 branch
BranchTrueFalseTotal
if $h1->{$key} ne $h2->{$key} 0 0 0
80 }
81 0 return 0;
82 }
83  
84 0 ▶sub STOP {
Subroutine STOP: not called CC=2 SCAR=17.9
Pod undocumented
85 0 my ($self) = @_;
86 # Inferno::RegMgr::Lookup may already detach itself (after finishing search).
87 0 ▶ if ($self->{lookup}{manager}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"lookup"}{"manager"}) 0 0 0
88 0 $self->{manager}->detach( $self->{lookup} );
89 }
90 0 return;
91 }
92  
93 0 ▶sub REFRESH {
Subroutine REFRESH: not called CC=1 SCAR=6.9
Pod undocumented
94 0 my ($self) = @_;
95 0 $self->STOP();
96 0 $self->START();
97 0 return;
98 }
99  
100  
101 1 1; # Magic true value required at end of module
102 __END__
« RegMgr/Utils.pm ↑ Summary RegMgr/Service.pm »