NestedGroups(3pm)
π NestedGroups(3pm) π
okay bestie, welcome to Set::NestedGroups β¨ this is a page from the User Contributed Perl Documentation and honestly? it's giving organized queen energy. it's all about grouped data β ACLs, city/state/country situations, that kind of thing π
πΈ NAME πΈ
Set::NestedGroups β grouped data eg ACL's, city/state/country etc π
β¨ SYNOPSIS β¨
use Set::NestedGroups;
$nested = new Set::NestedGroups;
$nested->add('user','group');
$nested->add('group','parentgroup');
do_something() if($nested->member('user','parentgroup'));
look at her go π¦ that's the whole vibe in four lines, no cap.
π DESCRIPTION π
Set::NestedGroups gives you an implementation of nested groups, and access control lists β ACLs β would be one example of nested groups. periodt.
So like, say Joe is a Manager, and Managers have access to payroll π you can create an ACL that implements these rules, and then just... ask the ACL if Joe has access to payroll. iconic.
Another example: maybe you wanna track which city, state and country people are in, by adding people to cities, cities to states, and states to countries. it's giving β¨nested girlbosseryβ¨ fr fr.
π CONSTRUTORS π
(yes bestie that's how the original spells it, we keep the facts exactly as they are π)
new()β creates a newSet::NestedGroupsobject. fresh out the box π«Άnew( fh )β creates a newSet::NestedGroupsobject, and it'll be initialized using data read from this handle. for the format deet's, peek at thesave()method. iykyk πnew( $sth )β creates a newSet::NestedGroupsobject, initialized using data read using this this DBI statement handle. (yes it says "this this", we are not the ones who wrote it, we're just the messenger π) for format deets, again: see thesave()method.
π₯ METHODS π₯
add ( $member, $group)β adds a member to a group. the group will be created if it doesn't already exist. β¨ no group? we make one. main character energy.remove ( $member, $group )β removes a member from a group. and listen: if this was the last member in this group, then the group gets deleted. and if the member was only in this group, then the member gets deleted too. it's cleanup szn π§Ήπsave(FILEHANDLE)β outputs the object to the given filehandle, which must already be open in write mode.
the format is compatible with the format used by CGI, and can be used with new to initialize a new object.
returns true if it successfully wrote the data, or false if something went wrong (usually that meant the handle wasn't already open in write mode π).
save($sth)β saves the object to a DBI database. this can be used withnewto initialize a new object. the$sthshould be expecting 2 values, in this fashion:
$sth = $dbh->prepare('insert into acl values (?,?)')
$acl->save($dbh);
$sth->finish();
$sth = $dbh->prepare('select * from acl');
$newacl=new ACL($sth);
returns true if it successfully wrote the data, or false if something went wrong.
member ( $member, $group )β returns true if$memberis a member of$group. yes bestie, just tell me if she's in πmember ( $member )β returns true if$memberexists in any group. anywhere. at all.group ( $group )β returns true if$groupexists πgroups ( $member, %options )β returns the groups that$memberbelongs to. options are explained below πmembers ( $group , %options )β returns the members of$group. keep on reading for the options πlist(%options)β returns aSet::NestedGroups::Memberobject that will output an list of the members & groups. this could be considered a calling ofgroups()on each member, except this is more efficient. she's doing less work for the same result, we stan efficiency π
the object can be used as follows:
$list=$nested->list();
for(my $i=0;$i<$list->rows();$i++){
my ($member,$group)=$list->next();
print "$member=$group\n";
}
π options π
by default, the above methods give every valid combination. however you might not always want that. therefore there are options which can prevent return of certain values. β¨
all of these examples presume that 'joe' is a member of 'managers', and 'managers' is a member of payroll, and that you are using only one of these options. you can use all 3, but that gets complicated to explain π
-norecurse=>1β no recursion is performed. the method would ignore payroll, and return only managers.-nomiddles=>1β doesn't return groups 'in the middle'. the method would ignore mangers, and return only payroll. (yes,mangers. that's the data we were given, bestie π«Ά)-nogroups=>1β doesn't return members that are groups. this only applies to thelist()method, in which case it acts like nomiddles, except on the member instead of the group.listwould ignore managers and returnjoe => managers,joe => payroll.
this sounds a lot more confusing than it actually is, once you try it once or twice you'll get the idea π no cap, it clicks fast.
π AUTHOR π
Alan R. Barclay, gorilla@elaine.drink.com π
π¦ SEE ALSO π¦
perl(1), CGI, DBI. go read those too, bestie, they're the supporting cast πΈ
π POD ERRORS π
hey! the above document had some coding errors, which are explained below:
- Around line 276:
You forgot a '=back' before '=head1'
- Around line 278:
'=item' outside of any '=over'
- Around line 350:
You forgot a '=back' before '=head2'
- Around line 378:
=back doesn't take any parameters, but you said =back 2
=back without =over
ngl bestie, the docs themselves have pod errors. the manual is not immune. we still love her π
and that's the whole page!! β¨ this one was written for perl v5.36.0 and dated 2022-10-15 β so if you're reading this in a timeline far, far away, just know that's when the lore was last updated π mwah, go build some nested groups π
π
π¦ where this page comes from
- ubuntu noble: libset-nestedgroups-perl 0.01-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libset-nestedgroups-perl 0.01-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libset-nestedgroups-perl 0.01-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms