DJabberd/RosterItem.pm

filter: Statementstmt 27.5% 16 / 58 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 38.4% 5 / 13 Podpod 0.0% 0 / 8 totaltotal 19.0% 21 / 110 CC 14 SCAR 40.9
CC
14
Cov
19%
new
132.0
as_xml
20.0
jid
2.0
CRAP 59.6
« DJabberd/Authen/AllowedUsers.pm ↑ Summary DJabberd/Connection/ClusterIn.pm »
1 package DJabberd::RosterItem;
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 20 ▶use DJabberd::Subscription;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 20 ▶use fields (
Subroutine BEGIN: called CC=1 SCAR=0.0
8 20 'jid',
9 'name',
10 'groups', # arrayref of group names
11 'subscription', # DJabberd::Subscription object
12 'remove', # bool: if client requested rosteritem be removed
13 20 );
14  
15 0 ▶sub new {
Subroutine new: not called CC=11 SCAR=48.8
Pod undocumented
16 0 my $self = shift;
17 0 ▶ $self = fields::new($self) unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
18 0 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
19 0 $self->{jid} = $_[0];
20 } else {
21 0 my %opts = @_;
22 0 ▶ $self->{jid} = delete $opts{'jid'} or croak "No JID";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"jid"} = delete $opts{"jid"} or croak("No JID") 0 0 0
23 0 $self->{name} = delete $opts{'name'};
24 0 $self->{groups} = delete $opts{'groups'};
25 0 $self->{remove} = delete $opts{'remove'};
26 0 $self->{subscription} = delete $opts{'subscription'};
27 0 ▶ croak("unknown ctor fields: " . join(', ', keys %opts)) if %opts;
Branch: 1 branch
BranchTrueFalseTotal
if %opts 0 0 0
28 }
29  
30 0 ▶ unless (ref $self->{jid}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->{"jid"}) 0 0 0
31 $self->{jid} = DJabberd::JID->new($self->{jid})
32 0 ▶ or croak("Invalid JID");
Branch: 1 branch
BranchTrueFalseTotal
$self->{"jid"} = "DJabberd::JID"->new($self->{"jid"}) or croak("Invalid JID") 0 0 0
33 }
34  
35 0 ▶ $self->{groups} ||= [];
Condition0%0/2
$self->{"groups"} ||= []
l!l
00
MC/DC0%0/1
$self->{"groups"} ||= []
$self->{"groups"}
Truth table0%0/2
A
A= $self->{"groups"}
Aresult
11
00
36  
37 # convert subscription name to an object
38 0 ▶ if ($self->{subscription} && ! ref $self->{subscription}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"subscription"} and not ref $self->{"subscription"}) 0 0 0
Condition0%0/3
$self->{"subscription"} and not ref $self->{"subscription"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"subscription"} and not ref $self->{"subscription"}
$self->{"subscription"} not ref $self->{"subscription"}
Truth table0%0/3
A and not(B)
A= $self->{"subscription"}B= not ref $self->{"subscription"}
ABresult
0X0
100
111
39 0 $self->{subscription} = DJabberd::Subscription->new_from_name($self->{subscription});
40 }
41  
42 0 ▶ $self->{subscription} ||= DJabberd::Subscription->none;
Condition0%0/3
$self->{"subscription"} ||= "DJabberd::Subscription"->none
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"subscription"} ||= "DJabberd::Subscription"->none
$self->{"subscription"} "DJabberd::Subscription"->none
Truth table0%0/3
A ||= B
A= $self->{"subscription"}B= "DJabberd::Subscription"->none
ABresult
1X1
011
000
43 0 return $self;
44 }
45  
46 0 ▶sub jid {
Subroutine jid: not called CC=1 SCAR=6.9
Pod undocumented
47 0 my $self = shift;
48 0 return $self->{jid};
49 }
50  
51 0 ▶sub name {
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
52 0 my $self = shift;
53 0 return $self->{name};
54 }
55  
56 0 ▶sub groups {
Subroutine groups: not called CC=1 SCAR=6.9
Pod undocumented
57 0 my $self = shift;
58 0 return @{ $self->{groups} };
59 }
60  
61 0 ▶sub subscription {
Subroutine subscription: not called CC=1 SCAR=6.9
Pod undocumented
62 0 my $self = shift;
63 0 return $self->{subscription};
64 }
65  
66 0 ▶sub set_subscription {
Subroutine set_subscription: not called CC=1 SCAR=6.9
Pod undocumented
67 0 my ($self, $sb) = @_;
68 0 $self->{subscription} = $sb;
69 }
70  
71 0 ▶sub add_group {
Subroutine add_group: not called CC=1 SCAR=6.9
Pod undocumented
72 0 my ($self, $group) = @_;
73 0 push @{ $self->{groups} }, $group;
74 }
75  
76 0 ▶sub as_xml {
Subroutine as_xml: not called CC=4 SCAR=30.0
Pod undocumented
77 0 my $self = shift;
78 my $xml = "<item jid='" . exml($self->{jid}->as_bare_string) . "' " . ($self->{remove} ?
79 "subscription='remove' " :
80 0 ▶ $self->{subscription}->as_attributes);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'remove'} ? : 0 0 0
81 0 ▶ if (defined $self->{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"name"}) 0 0 0
82 0 $xml .= " name='" . exml($self->{name}) . "'";
83 }
84 0 $xml .= ">";
85 0 foreach my $g (@{ $self->{groups} }) {
86 0 $xml .= "<group>" . exml($g) . "</group>";
87 }
88 0 $xml .= "</item>";
89 0 return $xml;
90 }
91  
92  
93 20 1;
« DJabberd/Authen/AllowedUsers.pm ↑ Summary DJabberd/Connection/ClusterIn.pm »