Represents a role.
Returns the name of this role.
DEPRECATED.
Use name instead.
name
Returns the Tree::Authz subclass used to instantiate this role.
Returns a list of roles inherited by this role, including this role.
Instance method.
Adds methods to the class representing the role. $cando is a single method name, or arrayref of method names. No-op methods are added to the class representing the group:
my $spies = $authz->role( 'spies' ); my $cando = [ qw( read_secret wear_disguise ) ]; $spies->setup_permissions( $cando ); if ( $spies->can( 'read_secret' ) ) { warn 'Compromised!'; } warn 'Trust no-one' if $spies->can( 'wear_disguise' );
Adds methods to the class representing the group. Keys give method names and values are coderefs that will be installed as methods on the group class:
my $spies = $authz->get_group( 'spies' ); my %able = ( read_secret => sub { my ($self, $file) = @_; open( SECRET, $file ); local $/; <SECRET>; }, find_moles => sub { ... }, ); $spies->setup_abilities( %able ); if ( $spies->can( 'read_secret' ) ) { print $spies->read_secret( '/path/to/secret/file' ); } # or if ( my $read = $spies->can( 'read_secret' ) ) { print $spies->$read( '/path/to/secret/file' ); } # with an unknown $group my $get_secret = $group->can( 'read_secret' ) || # spy $group->can( 'steal_document' ) || # mole $group->can( 'create_secret' ) || # spymaster $group->can( 'do_illicit_thing' ) || # politician sub {}; # boring life my $secret = $group->$get_secret;
Instead of adding a set of coderefs to a group's class, this method adds a class to the @ISA array of the group's class.
@ISA
package My::Spies; sub wear_disguise {} sub read_secret { my ($self, $file) = @_; open( SECRET, $file ); local $/; <SECRET>; } package main; my $spies = $authz->get_group( 'spies' ); $spies->setup_plugins( 'My::Spies' ); if ( $spies->can( 'read_secret' ) ) { warn 'Compromised!'; print $spies->read_secret( '/path/to/secret/file' ); } warn 'Trust no-one' if $spies->can( 'wear_disguise' );
To install Tree::Authz, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tree::Authz
CPAN shell
perl -MCPAN -e shell install Tree::Authz
For more information on module installation, please visit the detailed CPAN module installation guide.