view Lib/IMPL/Security/Role.pm @ 51:a1498298d3ee

Security in progress
author wizard@linux-odin.local
date Mon, 01 Mar 2010 17:25:36 +0300
parents
children 2f31ecabe9ea
line wrap: on
line source

package IMPL::Security::Role;

use base qw(IMPL::Object);

use IMPL::Class::Property;

BEGIN {
	public property roleName => prop_get;
	public property parentRoles => prop_get;
}

sub CTOR {
	my ($this,$name,$parentRoles) = @_;
	
	$this->roleName($name);
	$this->parentRoles($parentRoles);
}

sub Satisfy {
	my ($this,@roles) = @_;	
	
	return 1 unless $this->_FilterRoles( @roles );
}

sub _FilterRoles {
	my ($this,@roles) = @_;
	
	@roles = grep not (ref $_ ? $this == $_ : $this->roleName eq $_), @roles;
	
	@roles = $_->_FilterRoles(@roles) or return foreach @{$this->parentRoles} ;
	
	return @roles;
}


1;

__END__

=pod

=head1 DESCRIPTION

Роль. Может включать в себя базовые роли.
Имеется метод для проверки наличия необходимых ролей в текущей роли.

=head1 MEMBERS

=over

=item C<roleName>

Имя роли, ее идентификатор

=item C<parentRoles>

Список родительских ролей

=item C<Satisfy(@roles_list)>

Проверяет наличие ролей указанных ролей из списка @roles_list.
Допускается использование как самих объектов, так и имен ролей.
Возвращает 0 в случае неудачи, 1 при наличии необходимых ролей

=back

=cut