NestedGroups(3pm) | User Contributed Perl Documentation | NestedGroups(3pm) |
Set::NestedGroups - grouped data eg ACL's, city/state/country etc
use Set::NestedGroups; $nested = new Set::NestedGroups; $nested->add('user','group'); $nested->add('group','parentgroup'); do_something() if($nested->member('user','parentgroup'));
Set::NestedGroups gives an implementation of nested groups, access control lists (ACLs) would be one example of nested groups.
For example, if Joe is a Manager, and Managers have access to payroll, you can create an ACL which implements these rules, then ask the ACL if Joe has access to payroll.
Another example, you may wish to track which city, state and country people are in, by adding people to cities, cities to states, and states to countries.
The format is compatible with the format used by CGI, and can be used with new to initialize a new object;
Returns true if successfully wrote the data, or false if something went wrong (usually that meant that the handle wasn't already open in write mode).
$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 successfully wrote the data, or false if something went wrong.
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"; }
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, method would ignore payroll, and return only managers.
-nomiddles=>1
Doesn't returns groups 'in the middle', method would ignore mangers, and return only payroll.
-nogroups=>1
Doesn't return members that are groups. This only applies to the list() method, in which case it acts like nomiddles, except on the member instead of the group. list would ignore managers and return joe => 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.
Alan R. Barclay, gorilla@elaine.drink.com
perl(1), CGI, DBI.
Hey! The above document had some coding errors, which are explained below:
=back without =over
2022-10-15 | perl v5.34.0 |