User::I...lection(3)
π NAME π
Okay bestie, gather round: this is User::Identity::Collection β the base class for collecting roles of a user. It's a Perl module, it lives in section 3 of the manual (library functions, iykyk), and it's giving "the mom friend who organises everyone's stuff". π
𧬠INHERITANCE π§¬
The family tree, no cap:
User::Identity::Collectionβ is aUser::Identity::Itemπ«ΆUser::Identity::Collectionis extended by:User::Identity::Collection::EmailsUser::Identity::Collection::LocationsUser::Identity::Collection::SystemsUser::Identity::Collection::Users
So it's the parent, and those four are its iconic children. π
β¨ SYNOPSIS β¨
Here's the vibe in code, literally:
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 => 'email', ...)
my $set = $me->addCollection('email', ...)
my @roles = $me->collection('email'); # list of collected items
my $coll = $me->collection('email'); # a User::Identity::Collection
my @roles = $coll->roles;
my @roles = @$coll; # same, by overloading
my $role = $me->collection('email')->find($coderef);
my $role = $me->collection('location')->find('work');
my $role = $me->find(location => 'work');
πΈ DESCRIPTION πΈ
The User::Identity::Collection 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. It's giving β¨organised chaosβ¨ in the best way.
Currently imlemented extensions are π¦
- people is a collection of users
- whereabouts are locations
- a mailinglist is a collection of email addresses
- a network contains groups of systems
Extends DESCRIPTION in User::Identity::Item.
π OVERLOADED π
- overload:
""stringification β Returns the name of the collection and a sorted list of defined items.
Β» example:
print "$collection\n"; # location: home, work
- overload:
@{}array dereference β When the reference to a collection object is used as array-reference, it will be shown as list of roles.
Β» example:
my $locations = $ui->collection('location');
foreach my $loc (@$location) ...
print $location->[0];
π METHODS π
Extends METHODS in User::Identity::Item.
π«Ά Constructors
Extends Constructors in User::Identity::Item.
$class->new( [$name], %options )
The option rundown, straight from the source table:
-Option --Defined in --Default
description User::Identity::Item undef
item_type <required>
name User::Identity::Item <required>
parent User::Identity::Item undef
roles undef
Breaking it down, one by one:
description=> STRING β defined inUser::Identity::Item, defaultundefitem_type=> CLASS β default<required>. This is the CLASS which is used to store the information for each of the maintained objects within this collection.name=> STRING β defined inUser::Identity::Item, default<required>parent=> OBJECT β defined inUser::Identity::Item, defaultundefroles=> $role|@roles β defaultundef. Immediately add some@rolesto this collection. In case of an ARRAY, each element is passed separately toaddRole(). So, you may end-up with an ARRAY of ARRAYS each grouping a set of options to create a role. π (fr fr, nested arrays go brrr)
π¦ Attributes
Extends Attributes in User::Identity::Item.
$obj->description()β Inherited, seeAttributesinUser::Identity::Item$obj->itemType()β Returns the type of the items collected.$obj->name( [$newname] )β Inherited, seeAttributesinUser::Identity::Item$obj->roles()β Returns all defined roles within this collection. Be warned: the rules are returned in random (hash) order. Not me warning you twice about the ordering π
π Collections
Extends Collections in User::Identity::Item.
$obj->add($collection, $role)β Inherited, seeCollectionsinUser::Identity::Item$obj->addCollection( $object | <[$type], %options> )β Inherited, seeCollectionsinUser::Identity::Item$obj->collection($name)β Inherited, seeCollectionsinUser::Identity::Item$obj->parent( [$parent] )β Inherited, seeCollectionsinUser::Identity::Item$obj->removeCollection($object|$name)β Inherited, seeCollectionsinUser::Identity::Item$any->type()β Inherited, seeCollectionsinUser::Identity::Item$obj->user()β Inherited, seeCollectionsinUser::Identity::Item
π Maintaining roles
$obj->addRole($role|([$name], %options))β Adds a new role to this collection.$roleis an object of the right type (depends on the extension of this module which type that is) or a list of%optionswhich are used to create such role. The options can also be passed as reference to an ARRAY. The added role is returned. π«Ά
Β» example:
my $uicl = User::Identity::Collection::Locations->new;
my $uil = User::Identity::Location->new(home => ...);
$uicl->addRole($uil);
$uicl->addRole( home => address => 'street 32' );
$uicl->addRole( [home => address => 'street 32'] );
Easier β¨
$ui = User::Identity;
$ui->add(location => 'home', address => 'street 32' );
$ui->add(location => [ 'home', address => 'street 32' ] );
$obj->removeRole($role|$name)β The deleted role is returned (if it existed). Bye bestie π$obj->renameRole( <$role|$oldname>, $newname )β Give the role a different name, and move it in the collection. Glow-up arc.$obj->sorted()β Returns the roles sorted by name, alphabetically and case-sensitive.
π₯ Searching
Extends Searching in User::Identity::Item.
$obj->find($name|CODE|undef)
Find the object with the specified $name in this collection. With undef, a randomly selected role is returned. π²
When a code reference is specified, all collected roles are scanned one after the other (in unknown order). For each role,
CODE->($object, $collection)
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. Improves base, see Searching in User::Identity::Item.
Β» example:
my $emails = $ui->collection('emails');
$emails->find('work');
sub find_work($$) {
my ($mail, $emails) = @_;
$mail->location->name eq 'work';
}
my @at_work = $emails->find(\&find_work);
my @at_work = $ui->find(location => \&find_work);
my $any = $ui->find(location => undef );
π DIAGNOSTICS π
The error messages, and what they're actually trying to tell you:
- Error: cannot create a
$typeto add this to my collection. β Some options are specified to create a$typeobject, which is native to this collection. However, for some reason this failed. Cast byaddRole() - Error: cannot load collection module for
$type($class):$@β Either the specified$typedoes not exist, or that module named$classreturns 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. Cast byaddCollection() - Error: cannot rename
$frominto$to: already exists. β Cast byrenameRole() - Error: cannot rename
$frominto$to: doesn't exist. β Cast byrenameRole() - Error: nvalid collection
$name. β The collection with$namedoes not exist and can not be created. Cast byadd() - Error: this
$objectis not a collection. β Cast byaddCollection() - Error: wrong type of role for
$collection: requires a$expectbut got a$type. β Each$collectiongroups sets of roles of one specific type ($expect). You cannot add objects of a different$type. Cast byaddRole()
Not every error here is your fault, but the rename ones lowkey always are π
β SEE ALSO β
This module is part of User-Identity version 4.00, built on December 12, 2025. Website: http://perl.overmeer.net/CPAN/ π
π LICENSE π
For contributors see file ChangeLog.
This software is copyright (c) 2003-2025 by Mark Overmeer.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page bestie π this was User::I...lection(3) from User Contributed Perl Documentation, running on perl v5.42.0, dated 2026-01-17 β slay, no cap, go read it again if you forgot the flags πβ¨
π¦ where this page comes from
- fedora 44: perl-User-Identity 4.00-2.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms