DJabberd/RosterStorage/InMemoryOnly.pm

filter: Statementstmt 25.0% 17 / 68 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 38.4% 5 / 13 Podpod 0.0% 0 / 8 totaltotal 22.9% 22 / 96 CC 5 SCAR 14.8
CC
5
Cov
23%
get_roster
12.0
addupdate_roster_item
6.0
load_roster_item
6.0
CRAP 4.4
« DJabberd/SASL.pm ↑ Summary DJabberd/JID.pm »
1 package DJabberd::RosterStorage::InMemoryOnly;
2  
3 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 20 ▶use base 'DJabberd::RosterStorage';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 20 ▶use DJabberd::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 20 ▶use DJabberd::RosterItem;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 20 our $logger = DJabberd::Log->get_logger();
10  
11 0 ▶sub finalize {
Subroutine finalize: not called CC=1 SCAR=6.9
Pod undocumented
12 0 my $self = shift;
13  
14 0 $self->{rosters} = {};
15 # 'user@local' => {
16 # 'contact@remote' => { rosteritem attribs },
17 # ...
18 # }
19  
20 0 return $self;
21 }
22  
23 0 ▶sub blocking { 0 }
Subroutine blocking: not called CC=1 SCAR=6.9
Pod undocumented
24  
25 0 ▶sub get_roster {
Subroutine get_roster: not called CC=3 SCAR=24.8
Pod undocumented
26 0 my ($self, $cb, $jid) = @_;
27 0 my $jidstr = $jid->as_bare_string;
28  
29 0 $logger->debug("Getting roster for '$jid'");
30  
31 0 my $roster = DJabberd::Roster->new;
32  
33 0 ▶ foreach my $item (values %{$self->{rosters}->{$jidstr} || {}}) {
Condition0%0/2
$self->{'rosters'}{$jidstr} || {}
l!l
00
MC/DC0%0/1
$self->{'rosters'}{$jidstr} || {}
$self->{'rosters'}{$jidstr}
Truth table0%0/2
A
A= $self->{'rosters'}{$jidstr}
Aresult
11
00
34 0 my $subscription = DJabberd::Subscription->from_bitmask($item->{subscription});
35 0 $roster->add(DJabberd::RosterItem->new(%$item, subscription => $subscription));
36 }
37  
38 0 $logger->debug(" ... got groups, calling set_roster..");
39  
40 0 $cb->set_roster($roster);
41 }
42  
43 0 ▶sub set_roster_item {
Subroutine set_roster_item: not called CC=1 SCAR=6.9
Pod undocumented
44 0 my ($self, $cb, $jid, $ritem) = @_;
45 0 my $jidstr = $jid->as_bare_string;
46 0 my $rjidstr = $ritem->jid->as_bare_string;
47  
48 0 $self->{rosters}->{$jidstr}->{$rjidstr} = {
49 jid => $rjidstr,
50 name => $ritem->name,
51 groups => [$ritem->groups],
52 subscription => $ritem->subscription->as_bitmask,
53 };
54
55 0 $logger->debug("Set roster item");
56 0 $cb->done($ritem);
57 }
58  
59 0 ▶sub addupdate_roster_item {
Subroutine addupdate_roster_item: not called CC=2 SCAR=17.9
Pod undocumented
60 0 my ($self, $cb, $jid, $ritem) = @_;
61 0 my $jidstr = $jid->as_bare_string;
62 0 my $rjidstr = $ritem->jid->as_bare_string;
63  
64 0 my $olditem = $self->{rosters}->{$jidstr}->{$rjidstr};
65  
66 0 my $newitem = $self->{rosters}->{$jidstr}->{$rjidstr} = {
67 jid => $rjidstr,
68 name => $ritem->name,
69 groups => [$ritem->groups],
70 };
71  
72 0 ▶ if (defined $olditem) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $olditem) { } 0 0 0
73 0 $ritem->set_subscription(DJabberd::Subscription->from_bitmask($olditem->{subscription}));
74 0 $newitem->{subscription} = $olditem->{subscription};
75 }
76 else {
77 0 $newitem->{subscription} = $ritem->subscription->as_bitmask;
78 }
79
80 0 $cb->done($ritem);
81 }
82  
83 0 ▶sub delete_roster_item {
Subroutine delete_roster_item: not called CC=1 SCAR=6.9
Pod undocumented
84 0 my ($self, $cb, $jid, $ritem) = @_;
85 0 $logger->debug("delete roster item!");
86  
87 0 my $jidstr = $jid->as_bare_string;
88 0 my $rjidstr = $ritem->jid->as_bare_string;
89
90 0 delete $self->{rosters}->{$jidstr}->{$rjidstr};
91  
92 0 $cb->done;
93 }
94  
95 0 ▶sub load_roster_item {
Subroutine load_roster_item: not called CC=2 SCAR=17.9
Pod undocumented
96 0 my ($self, $jid, $contact_jid, $cb) = @_;
97  
98 0 my $jidstr = $jid->as_bare_string;
99 0 my $cjidstr = $contact_jid->as_bare_string;
100
101 0 my $options = $self->{rosters}->{$jidstr}->{$cjidstr};
102  
103 0 ▶ unless (defined $options) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $options) 0 0 0
104 0 $cb->set(undef);
105 0 return;
106 }
107  
108 0 my $subscription = DJabberd::Subscription->from_bitmask($options->{subscription});
109  
110 0 my $item = DJabberd::RosterItem->new(%$options, subscription => $subscription);
111  
112 0 $cb->set($item);
113 0 return;
114 }
115  
116 0 ▶sub wipe_roster {
Subroutine wipe_roster: not called CC=1 SCAR=6.9
Pod undocumented
117 0 my ($self, $cb, $jid) = @_;
118  
119 0 my $jidstr = $jid->as_bare_string;
120  
121 0 delete $self->{rosters}->{$jidstr};
122  
123 0 $cb->done;
124 }
125  
126 20 1;
« DJabberd/SASL.pm ↑ Summary DJabberd/JID.pm »