Abilities
view release on metacpan or search on metacpan
lib/Abilities.pm view on Meta::CPAN
and the 'admins' role inherits from the 'devs' role, then C<does_role('devs')>
will return true for that user (while C<assigned_role('devs')> returns false).
=cut
sub does_role {
my ($self, $role) = @_;
return unless $role;
foreach (map([$_, $self->get_role($_)], $self->roles)) {
return 1 if $_->[0] eq $role || $_->[1]->does_role($role);
}
return;
}
=head2 abilities()
Returns a hash reference of all the abilities a user/role object can
perform, after consolidating abilities inherited from roles (including
lib/Abilities.pm view on Meta::CPAN
unless (ref $_) {
$abilities->{$_} = 1;
} elsif (ref $_ eq 'ARRAY' && scalar @$_ == 2) {
$abilities->{$_->[0]} = [$_->[1]];
} else {
carp "Can't handle action of reference ".ref($_);
}
}
# load actions from roles this user/role consumes
my @hashes = map { $self->get_role($_)->abilities } $self->roles;
# merge all abilities
while (scalar @hashes) {
$abilities = merge($abilities, shift @hashes);
}
return $abilities;
}
=head1 UPGRADING FROM v0.2
lib/Abilities/Features.pm view on Meta::CPAN
the 'premium' plan inherits from the 'basic' plan, then C<inherits_plan('basic')>
will be true for that customer, while C<in_plan('basic')> will be false.
=cut
sub inherits_plan {
my ($self, $plan) = @_;
return unless $plan;
foreach (map([$_, $self->get_plan($_)], $self->plans)) {
return 1 if $_->[0] eq $plan || $_->[1]->inherits_plan($plan);
}
return;
}
=head2 available_features
Returns a hash-ref of all features available to a customer/plan object, after
consolidating features from inherited plans (recursively) and directly granted.
lib/Abilities/Features.pm view on Meta::CPAN
unless (ref $_) {
$features->{$_} = 1;
} elsif (ref $_ eq 'ARRAY' && scalar @$_ == 2) {
$features->{$_->[0]} = [$_->[1]];
} else {
carp "Can't handle feature of reference ".ref($_);
}
}
# load features from plans this customer/plan has
my @hashes = map { $self->get_plan($_)->available_features } $self->plans;
# merge all features
while (scalar @hashes) {
$features = merge($features, shift @hashes);
}
return $features;
}
=head1 UPGRADING FROM v0.2
( run in 1.269 second using v1.01-cache-2.11-cpan-13bb782fe5a )