aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaarten Vanraes <alien@mageia.org>2016-05-10 20:07:15 +0200
committerMaarten Vanraes <alien@mageia.org>2016-05-14 09:25:25 +0200
commit4c780314dace2294af648228a544fdf50c5b6afb (patch)
tree1acbe8ed96c5be34d27c5f1ccff928d3e4175e29
parentaec9c7f4bd4f3e4b6e54ab34ced613f5becfa674 (diff)
downloadmanatools-4c780314dace2294af648228a544fdf50c5b6afb.tar
manatools-4c780314dace2294af648228a544fdf50c5b6afb.tar.gz
manatools-4c780314dace2294af648228a544fdf50c5b6afb.tar.bz2
manatools-4c780314dace2294af648228a544fdf50c5b6afb.tar.xz
manatools-4c780314dace2294af648228a544fdf50c5b6afb.zip
actions also have a level
-rw-r--r--lib/ManaTools/Shared/Action.pm41
-rw-r--r--lib/ManaTools/Shared/ActionsRole.pm13
2 files changed, 53 insertions, 1 deletions
diff --git a/lib/ManaTools/Shared/Action.pm b/lib/ManaTools/Shared/Action.pm
index 34e968cf..1c211296 100644
--- a/lib/ManaTools/Shared/Action.pm
+++ b/lib/ManaTools/Shared/Action.pm
@@ -65,6 +65,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
use Moose;
+use Moose::Util::TypeConstraints;
+use MooseX::ClassAttribute;
+
has 'name' => (
is => 'ro',
isa => 'Str',
@@ -107,5 +110,43 @@ has 'valid' => (
}
);
+subtype 'LevelType'
+ => as Int
+ => where {($_ > 0 && $_ <= 3)};
+
+has 'level' => (
+ traits => ['Code'],
+ is => 'ro',
+ isa => 'CodeRef',
+ required => 0,
+ default => sub {
+ return sub { return 1; };
+ },
+ handles => {
+ is_level => 'execute'
+ }
+);
+
+class_has 'beginnerLevel' => (
+ is => 'ro',
+ isa => 'LevelType',
+ init_arg => undef,
+ default => sub {return 1;},
+);
+
+class_has 'advancedLevel' => (
+ is => 'ro',
+ isa => 'LevelType',
+ init_arg => undef,
+ default => sub {return 2;},
+);
+
+class_has 'expertLevel' => (
+ is => 'ro',
+ isa => 'LevelType',
+ init_arg => undef,
+ default => sub {return 3;},
+);
+
1;
diff --git a/lib/ManaTools/Shared/ActionsRole.pm b/lib/ManaTools/Shared/ActionsRole.pm
index ba4ed8f1..30f3789d 100644
--- a/lib/ManaTools/Shared/ActionsRole.pm
+++ b/lib/ManaTools/Shared/ActionsRole.pm
@@ -72,6 +72,14 @@ class_has 'acts' => (
default => sub {return [];}
);
+has 'level' => (
+ is => 'rw',
+ init_arg => undef,
+ lazy => 1,
+ isa => 'LevelType',
+ default => sub {return ManaTools::Shared::Action->beginnerLevel;}
+);
+
#=============================================================
=head2 get_actions
@@ -89,8 +97,9 @@ class_has 'acts' => (
#=============================================================
sub get_actions {
my $self = shift;
+ my $level = $self->level();
- return map { return $_->name()} @{$self->acts()};
+ return map { return $_->name()} grep { $_->is_valid($_) && ($_->is_level($_) <= $level) } @{$self->acts()};
}
#=============================================================
@@ -151,8 +160,10 @@ sub add_action {
my $item = shift;
my $action = shift;
my $valid = shift;
+ my $level = shift;
my $options = {name => $name, label => $label, item => $item, action => $action};
$options->{valid} = $valid if defined $valid;
+ $options->{level} = $level if defined $level;
push @{$self->acts()}, ManaTools::Shared::Action->new($options);
}