Elive/Entity/Participants.pm

filter: Statementstmt 95.4% 84 / 88 Branchbran 83.3% 30 / 36 Conditioncond 77.7% 14 / 18 MC/DCmcdc 54.5% 6 / 11 Subroutinesub 100% 12 / 12 Podpod 100% 2 / 2 totaltotal 88.6% 148 / 167 CC 29 SCAR 23.1
CC
29
Cov
90%
_build_array
16.0
_group_by_type
11.0
tidied
5.1
CRAP 10.0
« Elive/Entity/Participant.pm ↑ Summary Elive/Entity.pm »
1 package Elive::Entity::Participants;
2 23 ▶use warnings; use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 23 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 23 ▶use Mouse::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 23 extends 'Elive::DAO::Array';
8  
9 23 ▶use Elive::Entity::Participant;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 23 ▶use Elive::Entity::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 23 ▶use Elive::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 23 __PACKAGE__->element_class('Elive::Entity::Participant');
14 23 __PACKAGE__->mk_classdata('separator' => ';');
15  
16 =head1 NAME
17  
18 Elive::Entity::Participants - A list of participants
19  
20 =head1 DESCRIPTION
21  
22 This class implements the C<participants> property of C<Elive::Entity::Session>
23 and C<Elive::Entity::ParticipantList>
24  
25 =cut
26  
27 =head1 METHODS
28  
29 =cut
30  
31 sub _build_array {
32 158 ▶ my $class = shift;
Subroutine _build_array: called CC=16 SCAR=27.8
33 158 my $spec = shift;
34  
35 158 my $type = Elive::Util::_reftype( $spec );
36  
37 158 my @participants;
38  
39 158 ▶ if ($type) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type) { } 118 40 158
elsif (defined $spec) { } 31 9 40
40 118 ▶ $spec = [$spec]
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "ARRAY" 1 117 118
41 unless $type eq 'ARRAY';
42  
43 118 @participants = @$spec;
44 }
45 elsif (defined $spec) {
46 31 @participants = split(__PACKAGE__->separator, Elive::Util::string($spec));
47 }
48  
49 158 my $cur_role;
50 my @args;
51 158 my $element_class = $class->element_class;
52  
53 158 foreach (@participants) {
54  
55 361 ▶ foreach (Elive::Util::_reftype($_) eq 'ARRAY' ? @$_ : ($_)) {
Branch: 1 branch
BranchTrueFalseTotal
Elive::Util::_reftype($_) eq 'ARRAY' ? : 1 360 361
56 362 ▶ next unless defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 362 362
57  
58 362 ▶ if (!ref && m{^-(\w+)$}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_ and /^-(\w+)$/) { } 6 356 362
Condition100%3/3
not ref $_ and /^-(\w+)$/
!ll&&!rl&&r
2291276
MC/DC100%2/2
not ref $_ and /^-(\w+)$/
not ref $_ /^-(\w+)$/
Truth table100%3/3
not(A) and B
A= not ref $_B= /^-(\w+)$/
ABresult
0X0
100
111
59 6 my $opt = $1;
60  
61 6 ▶ if ($opt =~ m{^(participant|other)(s?)$}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt =~ /^(participant|other)(s?)$/) { } 3 3 6
elsif ($opt =~ /^moderator(s?)$/) { } 3 0 3
62 3 $cur_role = ${Elive::Entity::Role::PARTICIPANT};
63 }
64 elsif ($opt =~ m{^moderator(s?)$}) {
65 3 $cur_role = ${Elive::Entity::Role::MODERATOR};
66 }
67 else {
68 0 die "unknown option '$_' in participant list (expected: '-participant', '-moderator' or '-other'";
69 }
70 }
71 else {
72 356 my $participant = $_;
73 356 ▶ $participant = $element_class->new($participant)
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_ and builtin::blessed($_) and $_->isa($element_class) 67 162 229
Condition100%6/6
ref $_ and builtin::blessed($_) and $_->isa($element_class)
!ll&&!rl&&r
1922162
ref $_ and builtin::blessed($_)
!ll&&!rl&&r
12765164
MC/DC100%3/3
ref $_ and builtin::blessed($_) and $_->isa($element_class)
ref $_ builtin::blessed($_) $_->isa($element_class)
Truth table100%4/4
A and B and C
A= ref $_B= builtin::blessed($_)C= $_->isa($element_class)
ABCresult
0XX0
10X0
1100
1111
74 unless ref && Scalar::Util::blessed($_) && $_->isa($element_class);
75  
76 356 ▶ $participant->role($cur_role) if $cur_role;
Branch: 1 branch
BranchTrueFalseTotal
if $cur_role 11 345 356
77  
78 356 push (@args, $participant);
79 }
80 }
81 }
82  
83 158 return \@args;
84 }
85  
86 =head2 add
87  
88 $participants->add('alice=2', 'bob');
89  
90 Add additional participants
91  
92 =cut
93  
94 sub add {
95 2 ▶ my ($self, @elems) = @_;
Subroutine add: called CC=1 SCAR=0.0
Pod documented
96  
97 2 my $participants = $self->_build_array( \@elems );
98  
99 2 return $self->SUPER::add( @$participants );
100 }
101  
102 23 our $class = __PACKAGE__;
103 coerce $class => from 'ArrayRef|Str'
104 12 ▶ => via {$class->new($_);};
Subroutine __ANON__: called CC=1 SCAR=0.0
105  
106 sub _group_by_type {
107 15 ▶ my $self = shift;
Subroutine _group_by_type: called CC=10 SCAR=24.0
108  
109 15 ▶ my @raw_participants = @{ $self || [] };
Branch: 1 branch
BranchTrueFalseTotal
$self or [] 0 15 15
110  
111 15 my %users;
112 my %groups;
113 15 my %guests;
114  
115 15 foreach my $participant (@raw_participants) {
116  
117 17 ▶ $participant = Elive::Entity::Participant->new($participant)
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($participant) and $participant->isa("Elive::Entity::Participant") 0 17 17
Condition33%1/3
builtin::blessed($participant) and $participant->isa("Elive::Entity::Participant")
!ll&&!rl&&r
0017
MC/DC0%0/2
builtin::blessed($participant) and $participant->isa("Elive::Entity::Participant")
builtin::blessed($participant) $participant->isa("Elive::Entity::Participant")
Truth table33%1/3
A and B
A= builtin::blessed($participant)B= $participant->isa("Elive::Entity::Participant")
ABresult
0X0
100
111
118 unless Scalar::Util::blessed $participant
119 && $participant->isa('Elive::Entity::Participant');
120  
121 17 my $id;
122 17 ▶ my $roleId = Elive::Entity::Role->stringify( $participant->role )
Condition66%2/3
'Elive::Entity::Role'->stringify($participant->role) || $Elive::Entity::Role::PARTICIPANT
l!l&&r!l&&!r
1520
MC/DC0%0/2
'Elive::Entity::Role'->stringify($participant->role) || $Elive::Entity::Role::PARTICIPANT
'Elive::Entity::Role'->stringify($participant->role) $Elive::Entity::Role::PARTICIPANT
Truth table66%2/3
A || B
A= 'Elive::Entity::Role'->stringify($participant->role)B= $Elive::Entity::Role::PARTICIPANT
ABresult
1X1
011
000
123 || ${Elive::Entity::Role::PARTICIPANT};
124  
125 17 ▶ if (!defined $participant->type || $participant->type == ${Elive::Entity::Participant::TYPE_USER}) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $participant->type or $participant->type == $Elive::Entity::Participant::TYPE_USER) { } 12 5 17
elsif ($participant->type == $Elive::Entity::Participant::TYPE_GROUP) { } 3 2 5
elsif ($participant->type == $Elive::Entity::Participant::TYPE_GUEST) { } 2 0 2
Condition66%2/3
not defined $participant->type or $participant->type == $Elive::Entity::Participant::TYPE_USER
l!l&&r!l&&!r
0125
MC/DC50%1/2
not defined $participant->type or $participant->type == $Elive::Entity::Participant::TYPE_USER
not defined $participant->type $participant->type == $Elive::Entity::Participant::TYPE_USER
Truth table66%2/3
not(A) or B
A= not defined $participant->typeB= $participant->type == $Elive::Entity::Participant::TYPE_USER
ABresult
1X1
011
000
126 12 $id = Elive::Entity::User->stringify( $participant->user );
127 12 $users{ $id } = $roleId;
128 }
129 elsif ($participant->type == ${Elive::Entity::Participant::TYPE_GROUP}) {
130 3 $id = Elive::Entity::Group->stringify( $participant->group );
131 3 $groups{ $id } = $roleId;
132 }
133 elsif ($participant->type == ${Elive::Entity::Participant::TYPE_GUEST}) {
134 2 $id = Elive::Entity::InvitedGuest->stringify( $participant->guest );
135 2 $guests{ $id } = $roleId;
136 }
137 else {
138 0 carp("unknown type: $participant->{type} in participant list: ".$self->id);
139 }
140 }
141  
142 15 return (\%users, \%groups, \%guests);
143 }
144  
145 =head2 tidied
146  
147 my $untidy = 'trev;bob=3;bob=2'
148 my $participants = Elive::Entity::Participants->new($untidy);
149 # outputs: alice=2;bob=3;trev=3
150 print $participants->tidied;
151  
152 Produces a tidied list of participants. These are sorted with duplicates
153 removed (highest role is retained).
154  
155 The C<facilitatorId> option can be used to ensure that the meeting facilitator
156 is included and has a moderator role.
157
158 =cut
159  
160 sub tidied {
161 15 ▶ my $self = shift;
Subroutine tidied: called CC=5 SCAR=16.2
Pod documented
162  
163 15 my ($_users, $_groups, $_guests) = $self->_group_by_type;
164  
165 # weed out duplicates as we go
166 15 my %roles = (%$_users, %$_groups, %$_guests);
167  
168 15 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 15 0 15
169  
170 # elm3.x compat
171  
172 15 my %guests;
173 my %moderators;
174 15 my %participants;
175  
176 15 foreach (sort keys %roles) {
177  
178 17 my $role = $roles{$_};
179  
180 17 ▶ if (exists $_guests->{$_} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $_guests->{$_}) { } 2 15 17
elsif ($role <= 2) { } 7 8 15
181 2 $guests{$_} = $role;
182 }
183 elsif ($role <= 2) {
184 7 $moderators{$_} = $role;
185 }
186 else {
187 8 $participants{$_} = $role;
188 }
189 }
190  
191 15 return ([ sort keys %guests],
192 [ sort keys %moderators],
193 [ sort keys %participants])
194 }
195 else {
196 # elm2.x compat
197 0 return $self->stringify([ map { $_.'='.$roles{$_} } sort keys %roles ]);
198 }
199 }
200  
201 =head1 SEE ALSO
202  
203 L<Elive::Entity::Session>
204 L<Elive::Entity::ParticipantList>
205  
206 =cut
207  
208 23 1;
« Elive/Entity/Participant.pm ↑ Summary Elive/Entity.pm »