blib/lib/DJabberd/Plugin/Balancer.pm

filter: Statementstmt 40.0% 22 / 55 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 1 totaltotal 36.3% 28 / 77 CC 6 SCAR 18.1
CC
6
Cov
34%
register_jid
12.0
unregister_jid
12.0
find_jid
6.0
CRAP 6.1
↑ Summary
1 { package DJabberd::Plugin::Balancer;
2 1 our $VERSION = '0.1';
3 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶ use base qw(DJabberd::Plugin);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶ sub register {
Subroutine register: not called CC=1 SCAR=6.9
Pod undocumented
8 0 my ($self, $vhost) = @_;
9 # here we just re-bless $vhost
10 0 bless $vhost, 'DJabberd::Plugin::Balancer::VHost';
11 }
12 1 };
13 { package DJabberd::Plugin::Balancer::VHost;
14 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶ use base qw(DJabberd::VHost);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 0 ▶ sub register_jid {
Subroutine register_jid: not called CC=3 SCAR=24.8
19 0 my ($self, $jid, $conn, $cb) = @_;
20 0 my $fullstr = $jid->as_string;
21  
22 0 ▶ if (exists $self->{jid2sock}{$fullstr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'jid2sock'}{$fullstr}) { } 0 0 0
23 0 $cb->error("conflict");
24  
25 } else {
26 # XXX: $jid doesn't provide a sane API, but
27 # we are going to get inside anyway.
28 0 my $res = $jid->resource;
29 0 $res .= '#'.$conn->{id};
30 0 $jid->[DJabberd::JID::RES()] = $res;
31 0 $jid->[DJabberd::JID::AS_STRING()] = undef;
32 0 $jid->[DJabberd::JID::AS_BSTRING()] = undef;
33 0 $jid->[DJabberd::JID::AS_STREXML()] = undef;
34  
35 0 ▶ $self->{balancejid}{$fullstr} ||= [];
Condition0%0/2
$self->{"balancejid"}{$fullstr} ||= []
l!l
00
MC/DC0%0/1
$self->{"balancejid"}{$fullstr} ||= []
$self->{"balancejid"}{$fullstr}
Truth table0%0/2
A
A= $self->{"balancejid"}{$fullstr}
Aresult
11
00
36 0 push @{$self->{balancejid}{$fullstr}}, $jid->as_string;
37  
38 0 return $self->SUPER::register_jid($jid, $conn, $cb);
39 }
40 }
41  
42 0 ▶ sub find_jid {
Subroutine find_jid: not called CC=2 SCAR=17.9
43 0 my ($self, $jid) = @_;
44 0 my $fullstr = $jid;
45  
46 0 ▶ if (exists $self->{balancejid}{$fullstr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'balancejid'}{$fullstr}) { } 0 0 0
47 0 my $item = int(rand(scalar(@{$self->{balancejid}{$fullstr}})));
48 0 return $self->SUPER::find_jid($self->{balancejid}{$fullstr}[$item]);
49 } else {
50 0 return $self->SUPER::find_jid($jid);
51 }
52 }
53  
54 0 ▶ sub unregister_jid {
Subroutine unregister_jid: not called CC=3 SCAR=24.8
55 0 my ($self, $jid, $conn) = @_;
56 0 my $fullstr = $jid->as_string;
57 0 my $balancejid = $fullstr;
58 0 ▶ if ($balancejid =~ s/#[^#]+$//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($balancejid =~ s/#[^#]+$//) 0 0 0
59 0 ▶ if (exists $self->{balancejid}{$balancejid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"balancejid"}{$balancejid}) 0 0 0
60 0 @{$self->{balancejid}{$balancejid}} =
61 0 grep { $fullstr ne $_ }
62 0 @{$self->{balancejid}{$balancejid}};
63 }
64 }
65 0 return $self->SUPER::unregister_jid($jid, $conn);
66 }
67  
68 1 };
69  
70 1 __PACKAGE__
71  
72 __END__
↑ Summary