.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "User::Identity::Collection 3" .TH User::Identity::Collection 3 2023-07-26 "perl v5.38.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME User::Identity::Collection \- base class for collecting roles of a user .SH INHERITANCE .IX Header "INHERITANCE" .Vb 2 \& User::Identity::Collection \& is a User::Identity::Item \& \& User::Identity::Collection is extended by \& User::Identity::Collection::Emails \& User::Identity::Collection::Locations \& User::Identity::Collection::Systems \& User::Identity::Collection::Users .Ve .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 5 \& use User::Identity; \& use User::Identity::Collection; \& my $me = User::Identity\->new(...); \& my $set = User::Identity::Collection::Emails\->new(...); \& $me\->addCollection($set); \& \& # Simpler \& use User::Identity; \& my $me = User::Identity\->new(...); \& my $set = $me\->addCollection(type => \*(Aqemail\*(Aq, ...) \& my $set = $me\->addCollection(\*(Aqemail\*(Aq, ...) \& \& my @roles = $me\->collection(\*(Aqemail\*(Aq); # list of collected items \& \& my $coll = $me\->collection(\*(Aqemail\*(Aq); # a User::Identity::Collection \& my @roles = $coll\->roles; \& my @roles = @$coll; # same, by overloading \& \& my $role = $me\->collection(\*(Aqemail\*(Aq)\->find($coderef); \& my $role = $me\->collection(\*(Aqlocation\*(Aq)\->find(\*(Aqwork\*(Aq); \& my $role = $me\->find(location => \*(Aqwork\*(Aq); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" The \f(CW\*(C`User::Identity::Collection\*(C'\fR object maintains a set user related objects. It helps selecting these objects, which is partially common to all collections (for instance, each object has a name so you can search on names), and sometimes specific to the extension of this collection. .PP Currently imlemented extensions are .IP \(bu 4 \&\fIpeople\fR is a collection of users .IP \(bu 4 \&\fIwhereabouts\fR are locations .IP \(bu 4 a \fImailinglist\fR is a .Sp collection of email addresses .IP \(bu 4 a \fInetwork\fR contains .Sp groups of systems .PP Extends "DESCRIPTION" in User::Identity::Item. .SH OVERLOADED .IX Header "OVERLOADED" .IP "overload: \fB@{}\fR" 4 .IX Item "overload: @{}" When the reference to a collection object is used as array-reference, it will be shown as list of roles. .Sp example: .Sp .Vb 3 \& my $locations = $ui\->collection(\*(Aqlocation\*(Aq); \& foreach my $loc (@$location) ... \& print $location\->[0]; .Ve .IP "overload: \fBstringification \fR" 4 .IX Item "overload: stringification " Returns the name of the collection and a sorted list of defined items. .Sp example: .Sp .Vb 1 \& print "$collection\en"; # location: home, work .Ve .SH METHODS .IX Header "METHODS" Extends "METHODS" in User::Identity::Item. .SS Constructors .IX Subsection "Constructors" Extends "Constructors" in User::Identity::Item. .ie n .IP "User::Identity::Collection\->\fBnew\fR( [$name], %options )" 4 .el .IP "User::Identity::Collection\->\fBnew\fR( [$name], \f(CW%options\fR )" 4 .IX Item "User::Identity::Collection->new( [$name], %options )" .Vb 6 \& \-Option \-\-Defined in \-\-Default \& description User::Identity::Item undef \& item_type \& name User::Identity::Item \& parent User::Identity::Item undef \& roles undef .Ve .RS 4 .IP "description => STRING" 2 .IX Item "description => STRING" .PD 0 .IP "item_type => CLASS" 2 .IX Item "item_type => CLASS" .PD The CLASS which is used to store the information for each of the maintained objects within this collection. .IP "name => STRING" 2 .IX Item "name => STRING" .PD 0 .IP "parent => OBJECT" 2 .IX Item "parent => OBJECT" .IP "roles => ROLE|ARRAY" 2 .IX Item "roles => ROLE|ARRAY" .PD Immediately add some roles to this collection. In case of an ARRAY, each element of the array is passed separately to \fBaddRole()\fR. So, you may end-up with an ARRAY of arrays each grouping a set of options to create a role. .RE .RS 4 .RE .SS Attributes .IX Subsection "Attributes" Extends "Attributes" in User::Identity::Item. .ie n .IP $obj\->\fBdescription\fR() 4 .el .IP \f(CW$obj\fR\->\fBdescription\fR() 4 .IX Item "$obj->description()" Inherited, see "Attributes" in User::Identity::Item .ie n .IP $obj\->\fBitemType\fR() 4 .el .IP \f(CW$obj\fR\->\fBitemType\fR() 4 .IX Item "$obj->itemType()" Returns the type of the items collected. .ie n .IP "$obj\->\fBname\fR( [$newname] )" 4 .el .IP "\f(CW$obj\fR\->\fBname\fR( [$newname] )" 4 .IX Item "$obj->name( [$newname] )" Inherited, see "Attributes" in User::Identity::Item .ie n .IP $obj\->\fBroles\fR() 4 .el .IP \f(CW$obj\fR\->\fBroles\fR() 4 .IX Item "$obj->roles()" Returns all defined roles within this collection. Be warned: the rules are returned in random (hash) order. .SS Collections .IX Subsection "Collections" Extends "Collections" in User::Identity::Item. .ie n .IP "$obj\->\fBadd\fR($collection, $role)" 4 .el .IP "\f(CW$obj\fR\->\fBadd\fR($collection, \f(CW$role\fR)" 4 .IX Item "$obj->add($collection, $role)" Inherited, see "Collections" in User::Identity::Item .ie n .IP "$obj\->\fBaddCollection\fR( $object | <[$type], %options> )" 4 .el .IP "\f(CW$obj\fR\->\fBaddCollection\fR( \f(CW$object\fR | <[$type], \f(CW%options\fR> )" 4 .IX Item "$obj->addCollection( $object | <[$type], %options> )" Inherited, see "Collections" in User::Identity::Item .ie n .IP $obj\->\fBcollection\fR($name) 4 .el .IP \f(CW$obj\fR\->\fBcollection\fR($name) 4 .IX Item "$obj->collection($name)" Inherited, see "Collections" in User::Identity::Item .ie n .IP "$obj\->\fBparent\fR( [$parent] )" 4 .el .IP "\f(CW$obj\fR\->\fBparent\fR( [$parent] )" 4 .IX Item "$obj->parent( [$parent] )" Inherited, see "Collections" in User::Identity::Item .ie n .IP $obj\->\fBremoveCollection\fR($object|$name) 4 .el .IP \f(CW$obj\fR\->\fBremoveCollection\fR($object|$name) 4 .IX Item "$obj->removeCollection($object|$name)" Inherited, see "Collections" in User::Identity::Item .ie n .IP $obj\->\fBtype\fR() 4 .el .IP \f(CW$obj\fR\->\fBtype\fR() 4 .IX Item "$obj->type()" .PD 0 .IP User::Identity::Collection\->\fBtype\fR() 4 .IX Item "User::Identity::Collection->type()" .PD Inherited, see "Collections" in User::Identity::Item .ie n .IP $obj\->\fBuser\fR() 4 .el .IP \f(CW$obj\fR\->\fBuser\fR() 4 .IX Item "$obj->user()" Inherited, see "Collections" in User::Identity::Item .SS "Maintaining roles" .IX Subsection "Maintaining roles" .ie n .IP "$obj\->\fBaddRole\fR($role| <[$name],%options> | ARRAY)" 4 .el .IP "\f(CW$obj\fR\->\fBaddRole\fR($role| <[$name],%options> | ARRAY)" 4 .IX Item "$obj->addRole($role| <[$name],%options> | ARRAY)" Adds a new role to this collection. \f(CW$role\fR is an object of the right type (depends on the extension of this module which type that is) or a list of \f(CW%options\fR which are used to create such role. The options can also be passed as reference to an ARRAY. The added role is returned. .Sp example: .Sp .Vb 1 \& my $uicl = User::Identity::Collection::Locations\->new; \& \& my $uil = User::Identity::Location\->new(home => ...); \& $uicl\->addRole($uil); \& \& $uicl\->addRole( home => address => \*(Aqstreet 32\*(Aq ); \& $uicl\->addRole( [home => address => \*(Aqstreet 32\*(Aq] ); .Ve .Sp Easier .Sp .Vb 3 \& $ui = User::Identity; \& $ui\->add(location => \*(Aqhome\*(Aq, address => \*(Aqstreet 32\*(Aq ); \& $ui\->add(location => [ \*(Aqhome\*(Aq, address => \*(Aqstreet 32\*(Aq ] ); .Ve .ie n .IP $obj\->\fBremoveRole\fR($role|$name) 4 .el .IP \f(CW$obj\fR\->\fBremoveRole\fR($role|$name) 4 .IX Item "$obj->removeRole($role|$name)" The deleted role is returned (if it existed). .ie n .IP "$obj\->\fBrenameRole\fR( <$role|$oldname>, $newname )" 4 .el .IP "\f(CW$obj\fR\->\fBrenameRole\fR( <$role|$oldname>, \f(CW$newname\fR )" 4 .IX Item "$obj->renameRole( <$role|$oldname>, $newname )" Give the role a different name, and move it in the collection. .ie n .IP $obj\->\fBsorted\fR() 4 .el .IP \f(CW$obj\fR\->\fBsorted\fR() 4 .IX Item "$obj->sorted()" Returns the roles sorted by name, alphabetically and case-sensitive. .SS Searching .IX Subsection "Searching" Extends "Searching" in User::Identity::Item. .ie n .IP $obj\->\fBfind\fR($name|CODE|undef) 4 .el .IP \f(CW$obj\fR\->\fBfind\fR($name|CODE|undef) 4 .IX Item "$obj->find($name|CODE|undef)" Find the object with the specified \f(CW$name\fR in this collection. With \f(CW\*(C`undef\*(C'\fR, a randomly selected role is returned. .Sp When a code reference is specified, all collected roles are scanned one after the other (in unknown order). For each role, .Sp .Vb 1 \& CODE\->($object, $collection) .Ve .Sp is called. When the CODE returns true, the role is selected. In list context, all selected roles are returned. In scalar context, the first match is returned and the scan is aborted immediately. .Sp example: .Sp .Vb 2 \& my $emails = $ui\->collection(\*(Aqemails\*(Aq); \& $emails\->find(\*(Aqwork\*(Aq); \& \& sub find_work($$) { \& my ($mail, $emails) = @_; \& $mail\->location\->name eq \*(Aqwork\*(Aq; \& } \& my @at_work = $emails\->find(\e&find_work); \& my @at_work = $ui\->find(location => \e&find_work); \& my $any = $ui\->find(location => undef ); .Ve .SH DIAGNOSTICS .IX Header "DIAGNOSTICS" .ie n .IP "Error: $object is not a collection." 4 .el .IP "Error: \f(CW$object\fR is not a collection." 4 .IX Item "Error: $object is not a collection." The first argument is an object, but not of a class which extends User::Identity::Collection. .ie n .IP "Error: Cannot create a $type to add this to my collection." 4 .el .IP "Error: Cannot create a \f(CW$type\fR to add this to my collection." 4 .IX Item "Error: Cannot create a $type to add this to my collection." Some options are specified to create a \f(CW$type\fR object, which is native to this collection. However, for some reason this failed. .ie n .IP "Error: Cannot load collection module for $type ($class)." 4 .el .IP "Error: Cannot load collection module for \f(CW$type\fR ($class)." 4 .IX Item "Error: Cannot load collection module for $type ($class)." Either the specified \f(CW$type\fR does not exist, or that module named \f(CW$class\fR returns compilation errors. If the type as specified in the warning is not the name of a package, you specified a nickname which was not defined. Maybe you forgot the 'require' the package which defines the nickname. .ie n .IP "Error: Cannot rename $name into $newname: already exists" 4 .el .IP "Error: Cannot rename \f(CW$name\fR into \f(CW$newname:\fR already exists" 4 .IX Item "Error: Cannot rename $name into $newname: already exists" .PD 0 .ie n .IP "Error: Cannot rename $name into $newname: doesn't exist" 4 .el .IP "Error: Cannot rename \f(CW$name\fR into \f(CW$newname:\fR doesn't exist" 4 .IX Item "Error: Cannot rename $name into $newname: doesn't exist" .ie n .IP "Error: Creation of a collection via $class failed." 4 .el .IP "Error: Creation of a collection via \f(CW$class\fR failed." 4 .IX Item "Error: Creation of a collection via $class failed." .PD The \f(CW$class\fR did compile, but it was not possible to create an object of that class using the options you specified. .IP "Error: Don't know what type of collection you want to add." 4 .IX Item "Error: Don't know what type of collection you want to add." If you add a collection, it must either by a collection object or a list of options which can be used to create a collection object. In the latter case, the type of collection must be specified. .ie n .IP "Warning: No collection $name" 4 .el .IP "Warning: No collection \f(CW$name\fR" 4 .IX Item "Warning: No collection $name" The collection with \f(CW$name\fR does not exist and can not be created. .ie n .IP "Error: Wrong type of role for $collection: requires a $expect but got a $type" 4 .el .IP "Error: Wrong type of role for \f(CW$collection:\fR requires a \f(CW$expect\fR but got a \f(CW$type\fR" 4 .IX Item "Error: Wrong type of role for $collection: requires a $expect but got a $type" Each \f(CW$collection\fR groups sets of roles of one specific type ($expect). You cannot add objects of a different \f(CW$type\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" This module is part of User-Identity distribution version 1.02, built on April 17, 2023. Website: \fIhttp://perl.overmeer.net/CPAN/\fR .SH LICENSE .IX Header "LICENSE" Copyrights 2003\-2023 by [Mark Overmeer ]. For other contributors see ChangeLog. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See \fIhttp://dev.perl.org/licenses/\fR