Aion-Run

 view release on metacpan or  search on metacpan

t/aion/run.t  view on Meta::CPAN

use common::sense; use open qw/:std :utf8/;  use Carp qw//; use Cwd qw//; use File::Basename qw//; use File::Find qw//; use File::Slurper qw//; use File::Spec qw//; use File::Path qw//; use Scalar::Util qw//;  use Test::More 0.98;  use String::Diff q...
# # NAME
# 
# Aion::Run - роль для консольных команд
# 
# # VERSION
# 
# 0.0.2
# 
# # SYNOPSIS
# 
# Файл lib/Scripts/MyScript.pm:
#@> lib/Scripts/MyScript.pm
#>> package Scripts::MyScript;
#>> 
#>> use common::sense;
#>> 
#>> use List::Util qw/reduce/;
#>> use Aion::Format qw/trappout/;
#>> 
#>> use Aion;
#>> 
#>> with qw/Aion::Run/;
#>> 
#>> # Operands for calculations
#>> has operands => (is => "ro+", isa => ArrayRef[Int], arg => "-a", init_arg => "operand");
#>> 
#>> # Operator for calculations
#>> has operator => (is => "ro+", isa => Enum[qw!+ - * /!], arg => 1);
#>> 
#>> #@run math/calc „Calculate”
#>> sub calculate_sum {
#>>     my ($self) = @_;
#>>     printf "Result: %g\n", reduce {
#>>         given($self->operator) {
#>>             $a+$b when /\+/;
#>>             $a-$b when /\-/;
#>>             $a*$b when /\*/;
#>>             $a/$b when /\//;
#>>         }
#>>     } @{$self->operands};
#>> }
#>> 
#>> 1;
#@< EOF
# 
subtest 'SYNOPSIS' => sub { 
use Aion::Format qw/trappout/;

use lib "lib";
use Scripts::MyScript;

local ($::_g0 = do {trappout { Scripts::MyScript->new_from_args([qw/-a 1 -a 2 -a 3 +/])->calculate_sum }}, $::_e0 = "Result: 6\n"); ::ok $::_g0 eq $::_e0, 'trappout { Scripts::MyScript->new_from_args([qw/-a 1 -a 2 -a 3 +/])->calculate_sum } # => Resu...
local ($::_g0 = do {trappout { Scripts::MyScript->new_from_args([qw/--operand=4 * --operand=2/])->calculate_sum }}, $::_e0 = "Result: 8\n"); ::ok $::_g0 eq $::_e0, 'trappout { Scripts::MyScript->new_from_args([qw/--operand=4 * --operand=2/])->calcula...

# 
# # DESCRIPTION
# 
# Роль `Aion::Run` реализует аспект `arg` для установки фич из параметров командной строки.
# 
# * `arg => "-X"` — именованный параметр. Можно использовать как шорткут **\-X**, так и название фичи с **\--**.



( run in 1.668 second using v1.01-cache-2.11-cpan-ceb78f64989 )