BusyBird/Main.pm

filter: Statementstmt 94.6% 88 / 93 Branchbran 88.4% 23 / 26 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 22 / 22 Podpod 100% 11 / 11 totaltotal 95.0% 154 / 162 CC 17 SCAR 14.8
CC
17
Cov
94%
watch_unacked_counts
11.1
install_timeline
3.1
get_timeline_config
3.0
CRAP 4.4
« BusyBird/StatusStorage/Common.pm ↑ Summary BusyBird/Timeline.pm »
1 package BusyBird::Main;
2 9 ▶use v5.8.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use BusyBird::Timeline;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use BusyBird::Watcher::Aggregator;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use BusyBird::Log qw(bblog);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use BusyBird::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 9 our @CARP_NOT = qw(BusyBird::Timeline BusyBird::Config);
14  
15 63 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
16 63 my ($class) = @_;
17 63 tie(my %timelines, 'Tie::IxHash');
18 63 my $self = bless {
19 timelines => \%timelines,
20 config => BusyBird::Config->new(type => "global", with_default => 1),
21 }, $class;
22 63 return $self;
23 }
24  
25 128 ▶sub timeline {
Subroutine timeline: called CC=2 SCAR=6.9
Pod documented
26 128 my ($self, $name) = @_;
27 128 my $timeline = $self->get_timeline($name);
28 128 ▶ if(not defined $timeline) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $timeline) 112 16 128
29 112 $timeline = $self->create_timeline($name);
30 112 $self->install_timeline($timeline);
31 }
32 128 return $timeline;
33 }
34  
35 114 ▶sub create_timeline {
Subroutine create_timeline: called CC=1 SCAR=0.0
Pod documented
36 114 my ($self, $name) = @_;
37 114 return BusyBird::Timeline->new(name => $name, storage => $self->get_config("default_status_storage"));
38 }
39  
40 663 ▶sub get_timeline {
Subroutine get_timeline: called CC=1 SCAR=0.0
Pod documented
41 663 my ($self, $name) = @_;
42 663 return $self->{timelines}{$name};
43 }
44  
45 30 ▶sub get_all_timelines {
Subroutine get_all_timelines: called CC=1 SCAR=0.0
Pod documented
46 30 my ($self) = @_;
47 30 return values %{$self->{timelines}};
48 }
49  
50 119 ▶sub install_timeline {
Subroutine install_timeline: called CC=3 SCAR=11.4
Pod documented
51 119 my ($self, $timeline) = @_;
52 119 ▶ if($timeline->name eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeline->name eq "") 0 119 119
53 0 bblog("warn", "Invalid timeline name (it's empty)");
54 0 return;
55 }
56 119 ▶ if($timeline->name =~ qr{/}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeline->name =~ qr"/") 10 109 119
57 10 bblog("warn", "Invalid timeline name (it contains /)");
58 10 return;
59 }
60 109 $self->{timelines}{$timeline->name} = $timeline;
61 }
62  
63 6 ▶sub uninstall_timeline {
Subroutine uninstall_timeline: called CC=1 SCAR=0.0
Pod documented
64 6 my ($self, $name) = @_;
65 6 my $timeline = $self->get_timeline($name);
66 6 delete $self->{timelines}{$name};
67 6 return $timeline;
68 }
69  
70 76 ▶sub set_config {
Subroutine set_config: called CC=1 SCAR=0.0
Pod documented
71 76 shift()->{config}->set_config(@_);
72 }
73  
74 554 ▶sub get_config {
Subroutine get_config: called CC=1 SCAR=0.0
Pod documented
75 554 shift()->{config}->get_config(@_);
76 }
77  
78 304 ▶sub get_timeline_config {
Subroutine get_timeline_config: called CC=3 SCAR=11.0
Pod documented
79 304 my ($self, $timeline_name, $key) = @_;
80 304 my $timeline = $self->get_timeline($timeline_name);
81 304 ▶ my $timeline_config = defined($timeline) ? $timeline->get_config($key) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $timeline ? : 303 1 304
82 304 ▶ return $timeline_config if defined $timeline_config;
Branch: 1 branch
BranchTrueFalseTotal
if defined $timeline_config 8 296 304
83 296 return $self->get_config($key);
84 }
85  
86 46 ▶sub watch_unacked_counts {
Subroutine watch_unacked_counts: called CC=11 SCAR=24.1
Pod documented
87 46 my ($self, %watch_args) = @_;
88 46 my $level = $watch_args{level};
89 46 ▶ $level = 'total' if not defined $level;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $level 13 33 46
90 46 my $assumed = $watch_args{assumed};
91 46 my $callback = $watch_args{callback};
92 46 ▶ if(!defined($assumed) || ref($assumed) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $assumed or ref $assumed ne "HASH") 5 41 46
Condition100%3/3
not defined $assumed or ref $assumed ne "HASH"
l!l&&r!l&&!r
2341
MC/DC100%2/2
not defined $assumed or ref $assumed ne "HASH"
not defined $assumed ref $assumed ne "HASH"
Truth table100%3/3
not(A) or B
A= not defined $assumedB= ref $assumed ne "HASH"
ABresult
1X1
011
000
93 5 croak 'assumed must be a hash-ref';
94 }
95 41 ▶ if(!defined($callback) || ref($callback) ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $callback or ref $callback ne "CODE") 5 36 41
Condition100%3/3
not defined $callback or ref $callback ne "CODE"
l!l&&r!l&&!r
2336
MC/DC100%2/2
not defined $callback or ref $callback ne "CODE"
not defined $callback ref $callback ne "CODE"
Truth table100%3/3
not(A) or B
A= not defined $callbackB= ref $callback ne "CODE"
ABresult
1X1
011
000
96 5 croak "callback must be a code-ref";
97 }
98 36 my $watcher = BusyBird::Watcher::Aggregator->new;
99 36 foreach my $tl_name (keys %$assumed) {
100 63 my $timeline = $self->get_timeline($tl_name);
101 63 ▶ next if not defined $timeline;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timeline 6 57 63
102 my $tl_watcher = $timeline->watch_unacked_counts(
103 assumed => {$level => $assumed->{$tl_name}},
104 29 ▶ callback => sub {
Subroutine __ANON__: called CC=2 SCAR=8.4
105 29 my ($error, $w, $unacked_counts) = @_;
106 29 ▶ if(defined $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) { } 0 29 29
107 0 $watcher->cancel();
108 0 $callback->("Error from timeline $tl_name: $error", $watcher);
109 }else {
110 29 $callback->(undef, $watcher, { $tl_name => $unacked_counts });
111 }
112 }
113 57 );
114 57 ▶ if(!$tl_watcher->isa('Async::Selector::Aggregator')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tl_watcher->isa("Async::Selector::Aggregator")) 0 57 57
115 0 confess '$tl_watcher is not a Async::Selector::Aggregator. Something is terribly wrong.';
116 }
117 57 $watcher->add($tl_watcher);
118 57 ▶ last if !$watcher->active;
Branch: 1 branch
BranchTrueFalseTotal
unless $watcher->active 23 34 57
119 }
120 36 ▶ if(!$watcher->watchers) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($watcher->watchers) 4 32 36
121 4 croak "assumed argument does not contain any installed timeline.";
122 }
123 32 return $watcher;
124 }
125  
126  
127 9 1;
128  
129 __END__
« BusyBird/StatusStorage/Common.pm ↑ Summary BusyBird/Timeline.pm »