| 1 | # Copyrights 2003-2022 by [Mark Overmeer <markov@cpan.org>]. | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.03. | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # This code is part of distribution User-Identity. Meta-POD processed with | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # OODoc into POD and HTML manual-pages. See README.md | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | package User::Identity::Item; | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | $VERSION = '1.01'; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use Scalar::Util qw/weaken/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | sub new(@) | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 15 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 15 | ▶ | return undef unless @_; # no empty users. | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 14 | ▶ | unshift @_, 'name' if @_ %2; # odd-length list: starts with nick | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 14 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 14 | my $self = (bless {}, $class)->init(\%args); | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 14 | ▶ | if(my @missing = keys %args) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | { local $" = '", "'; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | warn "WARNING: Unknown ".(@missing==1? 'option' : 'options' ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | . " \"@missing\" for a $class\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 14 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | sub init($) | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 14 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 14 | ▶ | unless(defined($self->{UII_name} = delete $args->{name})) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | { croak "ERROR: Each item requires a name"; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 14 | $self->{UII_description} = delete $args->{description}; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 14 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | #----------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | sub name(;$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 69 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 69 | ▶ | @_ ? ($self->{UII_name} = shift) : $self->{UII_name}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | #----------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub description() {shift->{UII_description}} | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | #----------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | our %collectors = | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | ( emails => 'User::Identity::Collection::Emails' | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | , locations => 'User::Identity::Collection::Locations' | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | , systems => 'User::Identity::Collection::Systems' | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | , users => 'User::Identity::Collection::Users' | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ); # *s is tried as well, so email, system, and location will work | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | sub addCollection(@) | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addCollection: called CC=10 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | return unless @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | my $object; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | if(ref $_[0]) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | { $object = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | croak "ERROR: $object is not a collection" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | unless $object->isa('User::Identity::Collection'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | { unshift @_, 'type' if @_ % 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | my $type = delete $args{type}; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | ▶ | croak "ERROR: Don't know what type of collection you want to add" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | unless $type; | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | eval "require $class"; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | ▶ | croak "ERROR: Cannot load collection module $type ($class); $@\n" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | if $@; | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | $object = $class->new(%args); | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | ▶ | croak "ERROR: Creation of a collection via $class failed\n" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | unless defined $object; | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | $object->parent($self); | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | $self->{UI_col}{$object->name} = $object; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | sub removeCollection($) | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
removeCollection: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | my $name = ref $_[0] ? $_[0]->name : $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | delete $self->{UI_col}{$name} | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | || delete $self->{UI_col}{$name.'s'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | sub collection($;$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collection: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 6 | my $collname = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | my $collection | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 6 | ▶ | = $self->{UI_col}{$collname} || $self->{UI_col}{$collname.'s'} || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
$self->{'UI_col'}{$collname} || $self->{'UI_col'}{$collname . 's'} || (return)
$self->{"UI_col"}{$collname} or $self->{"UI_col"}{$collname . 's'}
MC/DC100%2/2
$self->{'UI_col'}{$collname} || $self->{'UI_col'}{$collname . 's'} || (return)
$self->{"UI_col"}{$collname}
$self->{"UI_col"}{$collname . 's'}
Truth table100%3/3
A or B
A= $self->{"UI_col"}{$collname}B= $self->{"UI_col"}{$collname . 's'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | ▶ | wantarray ? $collection->roles : $collection; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | sub add($$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | ▶ | { my ($self, $collname) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=5 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 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)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | = ref $collname && $collname->isa('User::Identity::Collection') | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ? $collname | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | : ($self->collection($collname) || $self->addCollection($collname)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | ▶ | unless($collection) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | { carp "No collection $collname"; | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | $collection->addRole(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub type { "item" } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | sub parent(;$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 18 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 18 | ▶ | return $self->{UII_parent} unless @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 6 | $self->{UII_parent} = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 6 | weaken($self->{UII_parent}); | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | 6 | $self->{UII_parent}; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | sub user() | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 9 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
user: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 9 | my $parent = $self->parent; | |||||||||||||||||||||||||||||||||||||||||||||
| 160 | 9 | ▶ | defined $parent ? $parent->user : undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | #----------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | sub find($$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 5 | ▶ | { my $all = shift->{UI_col}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find: called CC=5 SCAR=17.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 5 | my $collname = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | my $collection | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | = ref $collname && $collname->isa('User::Identity::Collection') ? $collname | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 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'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 5 | ▶ | defined $collection ? $collection->find(shift) : (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||