| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 118 | ▶ | $spec = [$spec] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 362 | ▶ | next unless defined; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 362 | ▶ | if (!ref && m{^-(\w+)$}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $_ and /^-(\w+)$/
MC/DC100%2/2
not ref $_ and /^-(\w+)$/
not ref $_
/^-(\w+)$/
Truth table100%3/3
not(A) and B
A= not ref $_B= /^-(\w+)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | my $opt = $1; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 6 | ▶ | if ($opt =~ m{^(participant|other)(s?)$}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
ref $_ and builtin::blessed($_) and $_->isa($element_class)
ref $_ and builtin::blessed($_)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | unless ref && Scalar::Util::blessed($_) && $_->isa($element_class); | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 356 | ▶ | $participant->role($cur_role) if $cur_role; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
builtin::blessed($participant) and $participant->isa("Elive::Entity::Participant")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | || ${Elive::Entity::Role::PARTICIPANT}; | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 17 | ▶ | if (!defined $participant->type || $participant->type == ${Elive::Entity::Participant::TYPE_USER}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
not defined $participant->type or $participant->type == $Elive::Entity::Participant::TYPE_USER
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||||