RegMgr/Monitor.pm

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