NAME
App::Rad::Plugin::ValuePriority - A Plugin to make it easy to get value from all acessors.
VERSION
Version 0.02
Snippet
use App::Rad qw/ValuePriority/;
sub command_1 {
my $c = shift;
$c->stash->{value_1} = "Test 01";
$c->default_value->{value_2} = "Test 02";
return join " --- ", $c->value->{value_1}, $c->value->{value_2}, $c->value->{value_3};
# It will print Test 01 --- Test 02 ---
# but if you call program like this:
# ./my_app.pl command_1 --value_2="Option 02" --value_3="Option 03"
# it will print:
# Test 01 --- Option 02 --- Option 03
}
sub command_2 {
my $c = shift;
$c->stash->{value_1} = "Test 01";
$c->default_value->{value_2} = "Test 02";
$c->to_stash;
return join " --- ", $c->stash->{value_1}, $c->stash->{value_2}, $c->stash->{value_3};
# It will print Test 01 --- Test 02 ---
# but if you call program like this:
# ./my_app.pl command_2 --value_2="Option 02" --value_3="Option 03"
# it will print:
# Test 01 --- Option 02 --- Option 03
}
Methods
$c->load()
Internal func
$c->default_value()
It is a acessor. You use it to set and get some key/value pairs.
$c->set_priority()
It receives a ordered list of what should receive priority. The options are: options, config, stash, default_value And that is the default order.
$c->get_priority()
As the name says, it return the priority order. As a arrayref
$c->to_stash()
it populate the $c->stash with the values obeying the setted order.
$c->value()
Return the value obeying the setted order.