| 1 | # This code is part of Perl distribution User-Identity version 4.00. | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # The POD got stripped from this file by OODoc version 3.05. | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # For contributors see file ChangeLog. | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2003-2025 by Mark Overmeer. | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | package User::Identity::Item;{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | our $VERSION = '4.00'; | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use Log::Report 'user-identity'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use Scalar::Util qw/weaken/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | sub new(@) | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 15 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 15 | ▶ | @_ or return undef; # no empty users. | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 14 | ▶ | unshift @_, 'name' if @_ %2; # odd-length list: starts with nick | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 14 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 14 | my $self = (bless {}, $class)->init(\%args); | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 14 | ▶ | if(my @missing = keys %args) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | { warning __xn"unknown option '{name}' for {class}.", "unknown options {names} for {class}", | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | scalar @missing, name => $missing[0], names => \@missing, class => $class; | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 14 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | sub init($) | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 14 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | $self->{UII_name} = delete $args->{name} | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 14 | ▶ | // error __x"each item requires a name."; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $args->{"name"} // &error(&__x("each item requires a name."))
MC/DC0%0/2
delete $args->{"name"} // &error(&__x("each item requires a name."))
delete $args->{"name"}
&error(&__x("each item requires a name."))
Truth table33%1/3
A // B
A= delete $args->{"name"}B= &error(&__x("each item requires a name."))
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 14 | $self->{UII_description} = delete $args->{description}; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 14 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | sub name(;$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 38 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 38 | ▶ | @_ ? ($self->{UII_name} = shift) : $self->{UII_name}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub description() { $_[0]->{UII_description} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | our %collectors = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | emails => 'User::Identity::Collection::Emails', | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | locations => 'User::Identity::Collection::Locations', | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | systems => 'User::Identity::Collection::Systems', | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | users => 'User::Identity::Collection::Users', | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ); # *s is tried as well, so email, system, and location will work | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | sub addCollection(@) | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addCollection: called CC=9 SCAR=23.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | @_ or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | my $object; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | ▶ | if(ref $_[0]) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | { $object = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | $object->isa('User::Identity::Collection') or error __x"this {object} is not a collection.", object => $object; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | { unshift @_, 'type' if @_ % 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | my $type = delete $args{type} or panic "no collection type specified"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | my $class = $collectors{$type} || $collectors{$type.'s'} || $type; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$User::Identity::Item::collectors{$type} || $User::Identity::Item::collectors{$type . 's'} || $type
$User::Identity::Item::collectors{$type} or $User::Identity::Item::collectors{$type . 's'}
MC/DC0%0/3
$User::Identity::Item::collectors{$type} || $User::Identity::Item::collectors{$type . 's'} || $type
$User::Identity::Item::collectors{$type}
$User::Identity::Item::collectors{$type . 's'}
$type
Truth table25%1/4
A or B || C
A= $User::Identity::Item::collectors{$type}B= $User::Identity::Item::collectors{$type . 's'}C= $type
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | eval "require $class"; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | ▶ | $@ and error __x"cannot load collection module {type} ({class}): {err}", type => $type, class => $class, err => $@; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | $object = $class->new(%args); | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | $object->parent($self); | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | $self->{UI_col}{$object->name} = $object; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | sub removeCollection($) | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
removeCollection: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my $name = ref $_[0] ? $_[0]->name : $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | delete $self->{UI_col}{$name} | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | || delete $self->{UI_col}{$name.'s'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | sub collection($;$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collection: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | my $collname = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 6 | ▶ | my $collection = $self->{UI_col}{$collname} || $self->{UI_col}{$collname.'s'} || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$self->{'UI_col'}{$collname} || $self->{'UI_col'}{$collname . 's'} || (return)
$self->{"UI_col"}{$collname} or $self->{"UI_col"}{$collname . 's'}
MC/DC50%1/2
$self->{'UI_col'}{$collname} || $self->{'UI_col'}{$collname . 's'} || (return)
$self->{"UI_col"}{$collname}
$self->{"UI_col"}{$collname . 's'}
Truth table66%2/3
A or B
A= $self->{"UI_col"}{$collname}B= $self->{"UI_col"}{$collname . 's'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | ▶ | wantarray ? $collection->roles : $collection; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | sub add($$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | ▶ | { my ($self, $collname) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=5 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | ▶ | my $collection | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
ref $collname and $collname->isa("User::Identity::Collection")
$self->collection($collname) or $self->addCollection($collname)
MC/DC0%0/2
ref $collname and $collname->isa("User::Identity::Collection")
ref $collname
$collname->isa("User::Identity::Collection")
MC/DC0%0/2
$self->collection($collname) or $self->addCollection($collname)
$self->collection($collname)
$self->addCollection($collname)
Truth table33%1/3
A and B
A= ref $collnameB= $collname->isa("User::Identity::Collection")
Truth table66%2/3
A or B
A= $self->collection($collname)B= $self->addCollection($collname)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | = ref $collname && $collname->isa('User::Identity::Collection') ? $collname | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | : ($self->collection($collname) || $self->addCollection($collname)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | ▶ | defined $collection | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | or error __x"invalid collection {name}.", name => $collname; | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | $collection->addRole(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub type { "item" } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | sub parent(;$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 18 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 18 | ▶ | @_ or return $self->{UII_parent}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 6 | $self->{UII_parent} = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 6 | weaken($self->{UII_parent}); | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | $self->{UII_parent}; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | sub user() | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 9 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
user: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 9 | my $parent = $self->parent; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 9 | ▶ | defined $parent ? $parent->user : undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | sub find($$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 5 | ▶ | { my $all = shift->{UI_col}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find: called CC=5 SCAR=17.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 5 | my $collname = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | my $collection | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | = ref $collname && $collname->isa('User::Identity::Collection') ? $collname | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 5 | ▶ | : ($all->{$collname} || $all->{$collname.'s'}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
ref $collname and $collname->isa("User::Identity::Collection")
$all->{$collname} or $$all{$collname . 's'}
MC/DC0%0/2
ref $collname and $collname->isa("User::Identity::Collection")
ref $collname
$collname->isa("User::Identity::Collection")
MC/DC50%1/2
$all->{$collname} or $$all{$collname . 's'}
$all->{$collname}
$$all{$collname . 's'}
Truth table33%1/3
A and B
A= ref $collnameB= $collname->isa("User::Identity::Collection")
Truth table66%2/3
A or B
A= $all->{$collname}B= $$all{$collname . 's'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 5 | ▶ | defined $collection ? $collection->find(shift) : (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||