| 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
| |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | unless (ref $self->{jid}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | $self->{jid} = DJabberd::JID->new($self->{jid}) | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | or croak("Invalid JID"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | $self->{groups} ||= []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"groups"} ||= []
MC/DC0%0/1
$self->{"groups"} ||= []
$self->{"groups"}
Truth table0%0/2
A
A= $self->{"groups"}
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # convert subscription name to an object | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ($self->{subscription} && ! ref $self->{subscription}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"subscription"} and not ref $self->{"subscription"}
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"}
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if (defined $self->{name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||