DJabberd/Subscription.pm

filter: Statementstmt 15.3% 16 / 104 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 17.8% 5 / 28 Podpod 0.0% 0 / 22 totaltotal 9.4% 21 / 222 CC 27 SCAR 27.9
CC
27
Cov
10%
as_attributes
42.0
got_outbound_subscribe
30.0
as_bitmask
30.0
CRAP 16.4
« DJabberd/Delivery/ComponentConnection.pm ↑ Summary DJabberd/Connection/ComponentIn.pm »
1 package DJabberd::Subscription;
2 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 20 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use DJabberd::Util qw(exml);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 use overload
6 20 ▶ '""' => \&as_string;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 20 ▶use fields (
Subroutine BEGIN: called CC=1 SCAR=0.0
9 20 'to', # all bools
10 'from',
11 'pendin',
12 'pendout',
13 20 );
14  
15 # The nine valid subscription states from the spec:
16 # TO FROM PIN POUT
17 # None - - - -
18 # None+PendOut - - - X
19 # None+PendIn - - X -
20 # None+PendIn+PendOut - - X X
21 # To X - - -
22 # To+PendIn X - X -
23 # From - X - -
24 # From+PendOut - X - X
25 # Both X X - -
26  
27 # Invalid conditions:
28 # TO && PendOut
29 # From && PendIn
30  
31  
32 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
33 0 my $self = shift;
34 0 ▶ $self = fields::new($self) unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
35 0 return $self;
36 }
37  
38 0 ▶sub none {
Subroutine none: not called CC=1 SCAR=6.9
Pod undocumented
39 0 my $class = shift;
40 0 return $class->new;
41 }
42  
43 0 ▶sub new_from_name {
Subroutine new_from_name: not called CC=2 SCAR=17.9
Pod undocumented
44 0 my ($class, $name) = @_;
45 my $sb = {
46 0 ▶ 'none' => sub { $class->none },
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 # ...
48 0 }->{$name};
49 0 ▶ croak "Unknown subscription state name '$name'" unless $sb;
Branch: 1 branch
BranchTrueFalseTotal
unless $sb 0 0 0
50 0 return $sb->();
51 }
52  
53 0 ▶sub is_none_pending_in {
Subroutine is_none_pending_in: not called CC=4 SCAR=30.0
Pod undocumented
54 0 my $self = shift;
55 return $self->{pendin} &&
56 ! $self->{pendout} &&
57 ! $self->{to} &&
58 0 ▶ ! $self->{from};
Condition0%0/9
$self->{'pendin'} && !$self->{'pendout'} && !$self->{'to'} && !$self->{'from'}
!ll&&!rl&&r
000
$self->{"pendin"} and not $self->{"pendout"} and not $self->{"to"}
!ll&&!rl&&r
000
$self->{"pendin"} and not $self->{"pendout"}
!ll&&!rl&&r
000
MC/DC0%0/4
$self->{'pendin'} && !$self->{'pendout'} && !$self->{'to'} && !$self->{'from'}
$self->{"pendin"} not $self->{"pendout"} not $self->{"to"} !$self->{'from'}
Truth table0%0/5
A and not(B) and not(C) && not(D)
A= $self->{"pendin"}B= not $self->{"pendout"}C= not $self->{"to"}D= !$self->{'from'}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
59 }
60  
61 0 ▶sub pending_out {
Subroutine pending_out: not called CC=1 SCAR=6.9
Pod undocumented
62 0 my $self = shift;
63 0 return $self->{pendout};
64 }
65  
66 0 ▶sub pending_in {
Subroutine pending_in: not called CC=1 SCAR=6.9
Pod undocumented
67 0 my $self = shift;
68 0 return $self->{pendin};
69 }
70  
71 0 ▶sub sub_from {
Subroutine sub_from: not called CC=1 SCAR=6.9
Pod undocumented
72 0 my $self = shift;
73 0 return $self->{from};
74 }
75  
76 0 ▶sub sub_to {
Subroutine sub_to: not called CC=1 SCAR=6.9
Pod undocumented
77 0 my $self = shift;
78 0 return $self->{to};
79 }
80  
81 0 ▶sub set_from {
Subroutine set_from: not called CC=2 SCAR=17.9
Pod undocumented
82 0 my ($self, $val) = @_;
83 0 ▶ $val = 1 unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
84 0 $self->{from} = $val;
85 0 return $self;
86 }
87  
88 0 ▶sub set_to {
Subroutine set_to: not called CC=2 SCAR=17.9
Pod undocumented
89 0 my ($self, $val) = @_;
90 0 ▶ $val = 1 unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
91 0 $self->{to} = $val;
92 0 return $self;
93 }
94  
95 0 ▶sub set_pending_out {
Subroutine set_pending_out: not called CC=2 SCAR=17.9
Pod undocumented
96 0 my ($self, $val) = @_;
97 0 ▶ $val = 1 unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
98 0 $self->{pendout} = $val;
99 0 return $self;
100 }
101  
102 0 ▶sub set_pending_in {
Subroutine set_pending_in: not called CC=2 SCAR=17.9
Pod undocumented
103 0 my ($self, $val) = @_;
104 0 ▶ $val = 1 unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
105 0 $self->{pendin} = $val;
106 0 return $self;
107 }
108  
109 0 ▶sub got_inbound_subscribed {
Subroutine got_inbound_subscribed: not called CC=1 SCAR=6.9
Pod undocumented
110 0 my $self = shift;
111 0 $self->{to} = 1;
112 0 $self->{pendout} = 0;
113 }
114  
115 0 ▶sub got_outbound_unsubscribe {
Subroutine got_outbound_unsubscribe: not called CC=1 SCAR=6.9
Pod undocumented
116 0 my $self = shift;
117 0 $self->{to} = 0;
118 0 $self->{pendout} = 0;
119 }
120  
121 0 ▶sub got_outbound_unsubscribed {
Subroutine got_outbound_unsubscribed: not called CC=1 SCAR=6.9
Pod undocumented
122 0 my $self = shift;
123 0 $self->{pendin} = 0;
124 0 $self->{from} = 0;
125 }
126  
127 0 ▶sub got_inbound_unsubscribe {
Subroutine got_inbound_unsubscribe: not called CC=1 SCAR=6.9
Pod undocumented
128 0 my $self = shift;
129 0 $self->{from} = 0;
130 0 $self->{pendin} = 0;
131 }
132  
133 0 ▶sub got_outbound_subscribed {
Subroutine got_outbound_subscribed: not called CC=1 SCAR=6.9
Pod undocumented
134 0 my $self = shift;
135 0 $self->{from} = 1;
136 0 $self->{pendin} = 0;
137 }
138  
139 # returns 1 if any action was taken, 0 if it was no-op
140 0 ▶sub got_outbound_subscribe {
Subroutine got_outbound_subscribe: not called CC=5 SCAR=34.0
Pod undocumented
141 0 my $self = shift;
142 # the no-op case
143 0 ▶ return 0 if $self->{to} && ! $self->{pendout};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"to"} and not $self->{"pendout"} 0 0 0
Condition0%0/3
$self->{"to"} and not $self->{"pendout"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"to"} and not $self->{"pendout"}
$self->{"to"} not $self->{"pendout"}
Truth table0%0/3
A and not(B)
A= $self->{"to"}B= not $self->{"pendout"}
ABresult
0X0
100
111
144  
145 # for some reason, user's pendout bit is set even though
146 # it shouldn't be. fix up.
147 0 ▶ if ($self->{to} && $self->{pendout}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"to"} and $self->{"pendout"}) 0 0 0
Condition0%0/3
$self->{"to"} and $self->{"pendout"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"to"} and $self->{"pendout"}
$self->{"to"} $self->{"pendout"}
Truth table0%0/3
A and B
A= $self->{"to"}B= $self->{"pendout"}
ABresult
0X0
100
111
148 0 $self->{pendout} = 0;
149 0 return 1;
150 }
151  
152 0 $self->{pendout} = 1;
153 0 return 1;
154 }
155  
156 0 ▶sub as_bitmask {
Subroutine as_bitmask: not called CC=5 SCAR=34.0
Pod undocumented
157 0 my $self = shift;
158 0 my $ret = 0;
159 0 ▶ $ret = $ret | 1 if $self->{to};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"to"} 0 0 0
160 0 ▶ $ret = $ret | 2 if $self->{from};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"from"} 0 0 0
161 0 ▶ $ret = $ret | 4 if $self->{pendin};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pendin"} 0 0 0
162 0 ▶ $ret = $ret | 8 if $self->{pendout};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pendout"} 0 0 0
163 0 return $ret;
164 }
165  
166 0 ▶sub from_bitmask {
Subroutine from_bitmask: not called CC=5 SCAR=34.0
Pod undocumented
167 0 my ($class, $mask) = @_;
168 0 $mask += 0; # force to numeric context
169 0 my $new = $class->new;
170 0 ▶ $new->{to} = 1 if $mask & 1;
Branch: 1 branch
BranchTrueFalseTotal
if $mask & 1 0 0 0
171 0 ▶ $new->{from} = 1 if $mask & 2;
Branch: 1 branch
BranchTrueFalseTotal
if $mask & 2 0 0 0
172 0 ▶ $new->{pendin} = 1 if $mask & 4;
Branch: 1 branch
BranchTrueFalseTotal
if $mask & 4 0 0 0
173 0 ▶ $new->{pendout} = 1 if $mask & 8;
Branch: 1 branch
BranchTrueFalseTotal
if $mask & 8 0 0 0
174 0 return $new;
175 }
176  
177 0 ▶sub as_string {
Subroutine as_string: not called CC=1 SCAR=6.9
Pod undocumented
178 0 my $self = shift;
179 0 my @fields = grep { $self->{$_} } qw(to from pendin pendout);
180 0 return "[@fields]";
181 }
182  
183 0 ▶sub as_attributes {
Subroutine as_attributes: not called CC=6 SCAR=37.4
Pod undocumented
184 0 my $self = shift;
185 0 my $state;
186 0 ▶ if ($self->{to} && $self->{from}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'to'} and $self->{'from'}) { } 0 0 0
elsif ($self->{'to'}) { } 0 0 0
elsif ($self->{'from'}) { } 0 0 0
Condition0%0/3
$self->{"to"} and $self->{"from"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"to"} and $self->{"from"}
$self->{"to"} $self->{"from"}
Truth table0%0/3
A and B
A= $self->{"to"}B= $self->{"from"}
ABresult
0X0
100
111
187 0 $state = "both";
188 } elsif ($self->{to}) {
189 0 $state = "to";
190 } elsif ($self->{from}) {
191 0 $state = "from";
192 } else {
193 0 $state = "none";
194 }
195  
196 0 my $ret = "subscription='$state'";
197 0 ▶ if ($self->{pendout}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pendout"}) 0 0 0
198 0 $ret .= " ask='subscribe'";
199 }
200 0 return $ret;
201 }
202  
203 20 1;
204  
205  
206  
« DJabberd/Delivery/ComponentConnection.pm ↑ Summary DJabberd/Connection/ComponentIn.pm »