| 1 | package Elive::Entity::Participant; | ||||||||||||||||||||||||||||||||||||
| 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::Entity'; | |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||
| 9 | 23 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | 23 | ▶ | use Elive; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | 23 | ▶ | use Elive::Util; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 13 | 23 | ▶ | use Elive::Entity::User; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 14 | 23 | ▶ | use Elive::Entity::Group; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 15 | 23 | ▶ | use Elive::Entity::InvitedGuest; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 16 | 23 | ▶ | use Elive::Entity::Role; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 17 | 23 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||
| 21 | Elive::Entity::Participant - A Single Meeting Participant | ||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||
| 25 | This is a component of L<Elive::Entity::Participants>. It contains details | ||||||||||||||||||||||||||||||||||||
| 26 | on a participating user, including their type and participation role. | ||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||
| 28 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||
| 32 | 23 | __PACKAGE__->entity_name('Participant'); | |||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||
| 34 | 23 | has 'user' => (is => 'rw', isa => 'Elive::Entity::User', | |||||||||||||||||||||||||||||||||||
| 35 | documentation => 'User (type=0)', | ||||||||||||||||||||||||||||||||||||
| 36 | coerce => 1, | ||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||
| 39 | 23 | has 'group' => (is => 'rw', isa => 'Elive::Entity::Group', | |||||||||||||||||||||||||||||||||||
| 40 | documentation => 'Group of attendees (type=1)', | ||||||||||||||||||||||||||||||||||||
| 41 | coerce => 1, | ||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||
| 43 | # for the benefit of createSession and updateSession commands | ||||||||||||||||||||||||||||||||||||
| 44 | 23 | __PACKAGE__->_alias(participant => 'user' ); | |||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||
| 46 | 23 | has 'guest' => (is => 'rw', isa => 'Elive::Entity::InvitedGuest', | |||||||||||||||||||||||||||||||||||
| 47 | documentation => 'Guest (type=2)', | ||||||||||||||||||||||||||||||||||||
| 48 | coerce => 1, | ||||||||||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||||||||||
| 50 | 23 | __PACKAGE__->_alias( invitedGuestId => 'guest' ); | |||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||
| 52 | 23 | has 'role' => (is => 'rw', isa => 'Elive::Entity::Role', | |||||||||||||||||||||||||||||||||||
| 53 | documentation => 'Role level of the meeting participant', | ||||||||||||||||||||||||||||||||||||
| 54 | coerce => 1, | ||||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||
| 57 | 23 | has 'type' => (is => 'rw', isa => 'Int', | |||||||||||||||||||||||||||||||||||
| 58 | documentation => 'type of participant; 0:user, 1:group, 2:guest' | ||||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||
| 61 | 23 | our ( $TYPE_USER, $TYPE_GROUP, $TYPE_GUEST ); | |||||||||||||||||||||||||||||||||||
| 62 | BEGIN { | ||||||||||||||||||||||||||||||||||||
| 63 | 23 | ▶ | $TYPE_USER = 0; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 64 | 23 | $TYPE_GROUP = 1; | |||||||||||||||||||||||||||||||||||
| 65 | 23 | $TYPE_GUEST = 2; | |||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||
| 68 | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||
| 69 | 554 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=20 SCAR=31.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 70 | 554 | local ($_) = shift; | |||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||
| 72 | 554 | ▶ | if (Scalar::Util::blessed($_)) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||
| 74 | 354 | ▶ | if (try {$_->isa('Elive::Entity::User')}) { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 75 | # | ||||||||||||||||||||||||||||||||||||
| 76 | # coerce participant as regular user | ||||||||||||||||||||||||||||||||||||
| 77 | # | ||||||||||||||||||||||||||||||||||||
| 78 | return { | ||||||||||||||||||||||||||||||||||||
| 79 | 1 | user => $_, | |||||||||||||||||||||||||||||||||||
| 80 | role => {roleId => ${Elive::Entity::Role::PARTICIPANT}}, | ||||||||||||||||||||||||||||||||||||
| 81 | type => $TYPE_USER, | ||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||
| 85 | 353 | ▶ | if (try {$_->isa('Elive::Entity::Group')}) { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 86 | # | ||||||||||||||||||||||||||||||||||||
| 87 | # coerce to group of participants | ||||||||||||||||||||||||||||||||||||
| 88 | # | ||||||||||||||||||||||||||||||||||||
| 89 | return { | ||||||||||||||||||||||||||||||||||||
| 90 | 1 | group => $_, | |||||||||||||||||||||||||||||||||||
| 91 | role => {roleId => ${Elive::Entity::Role::PARTICIPANT}}, | ||||||||||||||||||||||||||||||||||||
| 92 | type => $TYPE_GROUP, | ||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||
| 96 | 352 | ▶ | if (try {$_->isa('Elive::Entity::InvitedGuest')}) { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 97 | # | ||||||||||||||||||||||||||||||||||||
| 98 | # coerce to an invited guest | ||||||||||||||||||||||||||||||||||||
| 99 | # | ||||||||||||||||||||||||||||||||||||
| 100 | return { | ||||||||||||||||||||||||||||||||||||
| 101 | 0 | guest => $_, | |||||||||||||||||||||||||||||||||||
| 102 | role => {roleId => ${Elive::Entity::Role::PARTICIPANT}}, | ||||||||||||||||||||||||||||||||||||
| 103 | type => $TYPE_GUEST, | ||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||
| 108 | 552 | my $reftype = Elive::Util::_reftype($_); | |||||||||||||||||||||||||||||||||||
| 109 | 552 | ▶ | if ($reftype eq 'HASH') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 110 | # already structured as a participant | ||||||||||||||||||||||||||||||||||||
| 111 | 423 | my %spec = %$_; | |||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||
| 113 | 423 | my $type; | |||||||||||||||||||||||||||||||||||
| 114 | 423 | ▶ | if ($spec{user}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 115 | 380 | ▶ | $spec{type} ||= $TYPE_USER; | ||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$spec{"type"} ||= $Elive::Entity::Participant::TYPE_USER
MC/DC0%0/2
$spec{"type"} ||= $Elive::Entity::Participant::TYPE_USER
$spec{"type"}
$Elive::Entity::Participant::TYPE_USER
Truth table33%1/3
A ||= B
A= $spec{"type"}B= $Elive::Entity::Participant::TYPE_USER
| |||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||
| 117 | elsif ($spec{group}) { | ||||||||||||||||||||||||||||||||||||
| 118 | 23 | ▶ | $spec{type} ||= $TYPE_GROUP; | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$spec{"type"} ||= $Elive::Entity::Participant::TYPE_GROUP
MC/DC0%0/2
$spec{"type"} ||= $Elive::Entity::Participant::TYPE_GROUP
$spec{"type"}
$Elive::Entity::Participant::TYPE_GROUP
Truth table66%2/3
A ||= B
A= $spec{"type"}B= $Elive::Entity::Participant::TYPE_GROUP
| |||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||
| 120 | elsif ($spec{guest}) { | ||||||||||||||||||||||||||||||||||||
| 121 | 20 | ▶ | $spec{type} ||= $TYPE_GUEST; | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$spec{"type"} ||= $Elive::Entity::Participant::TYPE_GUEST
MC/DC0%0/2
$spec{"type"} ||= $Elive::Entity::Participant::TYPE_GUEST
$spec{"type"}
$Elive::Entity::Participant::TYPE_GUEST
Truth table66%2/3
A ||= B
A= $spec{"type"}B= $Elive::Entity::Participant::TYPE_GUEST
| |||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||
| 124 | 423 | ▶ | return \%spec if defined $spec{type}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||
| 127 | 129 | ▶ | if ($reftype) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | warn YAML::Syck::Dump({unbuildable_participant => $_}) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 129 | if Elive->debug; | ||||||||||||||||||||||||||||||||||||
| 130 | 0 | die "unable to build participant from $reftype reference"; | |||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||
| 133 | # | ||||||||||||||||||||||||||||||||||||
| 134 | # Simple users: | ||||||||||||||||||||||||||||||||||||
| 135 | # 'bob=3' => user:bob, role:3, type: 0 (user) | ||||||||||||||||||||||||||||||||||||
| 136 | # 'alice' => user:bob, role:3 (defaulted), type: 0 (user) | ||||||||||||||||||||||||||||||||||||
| 137 | # A leading '*' indicates a group: | ||||||||||||||||||||||||||||||||||||
| 138 | # '*mygroup=2' => group:mygroup, role:2 type:1 (group) | ||||||||||||||||||||||||||||||||||||
| 139 | # Invited guests are of the form: displayName(loginName) | ||||||||||||||||||||||||||||||||||||
| 140 | # 'Robert(bob)' => guest:{loginName:bob, displayName:Robert} | ||||||||||||||||||||||||||||||||||||
| 141 | # | ||||||||||||||||||||||||||||||||||||
| 142 | 129 | my %parse; | |||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||
| 144 | 129 | ▶ | if (m{^ \s* | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 145 | ([^;]*?) # display name | ||||||||||||||||||||||||||||||||||||
| 146 | \s* | ||||||||||||||||||||||||||||||||||||
| 147 | \( ([^;\)]+) \) # (login name) | ||||||||||||||||||||||||||||||||||||
| 148 | \s* | ||||||||||||||||||||||||||||||||||||
| 149 | (= (\d) \s*)? # possible '=role' (ignored) | ||||||||||||||||||||||||||||||||||||
| 150 | $}x) { | ||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||
| 152 | 3 | $parse{guest} = {displayName => $1, loginName => $2}; | |||||||||||||||||||||||||||||||||||
| 153 | 3 | $parse{type} = $TYPE_GUEST; | |||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||
| 155 | 3 | return \%parse; | |||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||
| 157 | elsif (m{^ \s* | ||||||||||||||||||||||||||||||||||||
| 158 | (\*?) # optional group indicator '*' | ||||||||||||||||||||||||||||||||||||
| 159 | \s* | ||||||||||||||||||||||||||||||||||||
| 160 | ([^,]*?) # user/group id | ||||||||||||||||||||||||||||||||||||
| 161 | \s* | ||||||||||||||||||||||||||||||||||||
| 162 | (= (\d) \s*)? # optional '=role' | ||||||||||||||||||||||||||||||||||||
| 163 | $}x) { | ||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||
| 165 | 126 | my $is_group = $1; | |||||||||||||||||||||||||||||||||||
| 166 | 126 | my $id = $2; | |||||||||||||||||||||||||||||||||||
| 167 | 126 | my $roleId = $4; | |||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||
| 169 | 126 | ▶ | $roleId = ${Elive::Entity::Role::PARTICIPANT} | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $roleId and $roleId ne ""
MC/DC50%1/2
defined $roleId and $roleId ne ""
defined $roleId
$roleId ne ""
Truth table66%2/3
A and B
A= defined $roleIdB= $roleId ne ""
| |||||||||||||||||||||||||||||||||||||
| 170 | unless defined $roleId && $roleId ne ''; | ||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||
| 172 | 126 | ▶ | if ( $is_group ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 173 | 7 | $parse{group} = {groupId => $id}; | |||||||||||||||||||||||||||||||||||
| 174 | 7 | $parse{type} = $TYPE_GROUP; | |||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||
| 176 | else { | ||||||||||||||||||||||||||||||||||||
| 177 | 119 | $parse{user} = {userId => $id}; | |||||||||||||||||||||||||||||||||||
| 178 | 119 | $parse{type} = $TYPE_USER; | |||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||
| 181 | 126 | $parse{role}{roleId} = $roleId; | |||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||
| 183 | 126 | return \%parse; | |||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||
| 186 | # | ||||||||||||||||||||||||||||||||||||
| 187 | # slightly convoluted die on return to keep Perl::Critic happy | ||||||||||||||||||||||||||||||||||||
| 188 | # | ||||||||||||||||||||||||||||||||||||
| 189 | 0 | return die "participant '$_' not in format: userId=[0-3] or *groupId=[0-3] or guestName(guestLogin)"; | |||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||
| 192 | coerce 'Elive::Entity::Participant' => from 'Str' | ||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | => via { __PACKAGE__->new( $_) }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||
| 195 | =head2 participant | ||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||
| 197 | Returns a participant. This can either be of type L<Elive::Entity::User> (type | ||||||||||||||||||||||||||||||||||||
| 198 | 0), L<Elive::Entity::Group> (type 1) or L<Elive::Entity::InvitedGuest> (type 2). | ||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||
| 200 | =cut | ||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||
| 202 | sub participant { | ||||||||||||||||||||||||||||||||||||
| 203 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
participant: called CC=7 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||
| 205 | return (!defined $self->type || $self->type == $TYPE_USER) ? $self->user | ||||||||||||||||||||||||||||||||||||
| 206 | : ($self->type == $TYPE_GROUP) ? $self->group | ||||||||||||||||||||||||||||||||||||
| 207 | : ($self->type == $TYPE_GUEST) ? $self->guest | ||||||||||||||||||||||||||||||||||||
| 208 | 5 | ▶ | : do {warn "unknown participant type: ".$self->type; | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
not defined $self->type or $self->type == $Elive::Entity::Participant::TYPE_USER
MC/DC50%1/2
not defined $self->type or $self->type == $Elive::Entity::Participant::TYPE_USER
not defined $self->type
$self->type == $Elive::Entity::Participant::TYPE_USER
Truth table66%2/3
not(A) or B
A= not defined $self->typeB= $self->type == $Elive::Entity::Participant::TYPE_USER
| |||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | $self->user || $self->group || $self->guest}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->user or $self->group
MC/DC0%0/2
$self->user or $self->group
$self->user
$self->group
Truth table0%0/3
A or B
A= $self->userB= $self->group
| |||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||
| 212 | =head2 is_moderator | ||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||
| 214 | Utility method to examine or set a meeting participant's moderator privileges. | ||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||
| 216 | # does Bob have moderator privileges? | ||||||||||||||||||||||||||||||||||||
| 217 | my $is_moderator = $bob->is_moderator; | ||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||
| 219 | # grant moderator privileges to Alice | ||||||||||||||||||||||||||||||||||||
| 220 | $alice->is_moderator(1); | ||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||
| 222 | =cut | ||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||
| 224 | sub is_moderator { | ||||||||||||||||||||||||||||||||||||
| 225 | 9 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
is_moderator: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||
| 227 | 9 | my $role_id; | |||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||
| 229 | 9 | ▶ | if (defined $self->type && $self->type == $TYPE_GUEST) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->type and $self->type == $Elive::Entity::Participant::TYPE_GUEST
MC/DC50%1/2
defined $self->type and $self->type == $Elive::Entity::Participant::TYPE_GUEST
defined $self->type
$self->type == $Elive::Entity::Participant::TYPE_GUEST
Truth table66%2/3
A and B
A= defined $self->typeB= $self->type == $Elive::Entity::Participant::TYPE_GUEST
| |||||||||||||||||||||||||||||||||||||
| 230 | # | ||||||||||||||||||||||||||||||||||||
| 231 | # invited guests cannot be moderators | ||||||||||||||||||||||||||||||||||||
| 232 | 1 | return; | |||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||
| 235 | 8 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 236 | 4 | my $is_moderator = shift; | |||||||||||||||||||||||||||||||||||
| 237 | 4 | ▶ | $role_id = $is_moderator | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 238 | ? ${Elive::Entity::Role::MODERATOR} | ||||||||||||||||||||||||||||||||||||
| 239 | : ${Elive::Entity::Role::PARTICIPANT}; | ||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||
| 241 | 4 | ▶ | $self->role( $role_id ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 242 | unless $role_id == $self->role->stringify; | ||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||
| 244 | else { | ||||||||||||||||||||||||||||||||||||
| 245 | 4 | $role_id = $self->role->stringify; | |||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||
| 248 | 8 | ▶ | return defined $role_id && $role_id != ${Elive::Entity::Role::PARTICIPANT}; | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $role_id && $role_id != $Elive::Entity::Role::PARTICIPANT
MC/DC50%1/2
defined $role_id && $role_id != $Elive::Entity::Role::PARTICIPANT
defined $role_id
$role_id != $Elive::Entity::Role::PARTICIPANT
Truth table66%2/3
A && B
A= defined $role_idB= $role_id != $Elive::Entity::Role::PARTICIPANT
| |||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||
| 251 | =head2 stringify | ||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||
| 253 | Returns a string of the form 'userId=role' (users) '*groupId=role (groups), | ||||||||||||||||||||||||||||||||||||
| 254 | or displayName(loginName) (guests). This value is used for comparisons, | ||||||||||||||||||||||||||||||||||||
| 255 | display, etc... | ||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||
| 257 | =cut | ||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||
| 259 | sub stringify { | ||||||||||||||||||||||||||||||||||||
| 260 | 352 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 261 | 352 | ▶ | my $data = shift || $self; | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $self
MC/DC0%0/2
shift() || $self
shift()
$self
Truth table66%2/3
A || B
A= shift()B= $self
| |||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||
| 263 | 352 | $data = $self->BUILDARGS($data); | |||||||||||||||||||||||||||||||||||
| 264 | 352 | my $role_id = Elive::Entity::Role->stringify( $data->{role} ); | |||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||
| 266 | 352 | ▶ | if (!defined $data->{type} || $data->{type} == $TYPE_USER) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
not defined $data->{"type"} or $data->{"type"} == $Elive::Entity::Participant::TYPE_USER
MC/DC50%1/2
not defined $data->{"type"} or $data->{"type"} == $Elive::Entity::Participant::TYPE_USER
not defined $data->{"type"}
$data->{"type"} == $Elive::Entity::Participant::TYPE_USER
Truth table66%2/3
not(A) or B
A= not defined $data->{"type"}B= $data->{"type"} == $Elive::Entity::Participant::TYPE_USER
| |||||||||||||||||||||||||||||||||||||
| 267 | # user => 'userId' | ||||||||||||||||||||||||||||||||||||
| 268 | 316 | return Elive::Entity::User->stringify($data->{user}).'='.$role_id; | |||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||
| 270 | elsif ($data->{type} == $TYPE_GUEST) { | ||||||||||||||||||||||||||||||||||||
| 271 | # guest => 'displayName(loginName)' | ||||||||||||||||||||||||||||||||||||
| 272 | 15 | my $guest_str = Elive::Entity::InvitedGuest->stringify($data->{guest}); | |||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||
| 274 | 15 | ▶ | Carp::carp ("ignoring moderator role for invited guest: $guest_str") | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $role_id and $role_id != $Elive::Entity::Role::PARTICIPANT
MC/DC100%2/2
defined $role_id and $role_id != $Elive::Entity::Role::PARTICIPANT
defined $role_id
$role_id != $Elive::Entity::Role::PARTICIPANT
Truth table100%3/3
A and B
A= defined $role_idB= $role_id != $Elive::Entity::Role::PARTICIPANT
| |||||||||||||||||||||||||||||||||||||
| 275 | if defined $role_id && $role_id != ${Elive::Entity::Role::PARTICIPANT}; | ||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||
| 277 | 15 | return $guest_str; | |||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||
| 279 | elsif ($data->{type} == $TYPE_GROUP) { | ||||||||||||||||||||||||||||||||||||
| 280 | # group => '*groupId' | ||||||||||||||||||||||||||||||||||||
| 281 | 21 | return Elive::Entity::Group->stringify($data->{group}).'='.$role_id; | |||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||
| 283 | else { | ||||||||||||||||||||||||||||||||||||
| 284 | # unknown | ||||||||||||||||||||||||||||||||||||
| 285 | 0 | die "unrecognised participant type: $data->{type}"; | |||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||
| 289 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||
| 291 | L<Elive::Entity::ParticipantList> | ||||||||||||||||||||||||||||||||||||
| 292 | L<Elive::Entity::Participants> | ||||||||||||||||||||||||||||||||||||
| 293 | L<Elive::Entity::User> | ||||||||||||||||||||||||||||||||||||
| 294 | L<Elive::Entity::Group> | ||||||||||||||||||||||||||||||||||||
| 295 | L<Elive::Entity::InvitedGuest>; | ||||||||||||||||||||||||||||||||||||
| 296 | L<Elive::Entity::Role> | ||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||
| 298 | =cut | ||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||
| 300 | 23 | 1; | |||||||||||||||||||||||||||||||||||