CLI-Dispatch

 view release on metacpan or  search on metacpan

t/lib/CLIDTestClass/Sub/Subcmd.pm  view on Meta::CPAN

package CLIDTestClass::Sub::Subcmd;

use strict;
use warnings;
use Test::Classy::Base;
use CLI::Dispatch;
use Try::Tiny;

sub simple_dispatch : Test {
  my $class = shift;

  my $ret = $class->dispatch(qw( cmd simple_sub ));

  ok $ret eq 'simple subcommand', $class->message("dispatch succeeded: $ret");
}

sub simple_with_args : Test {
  my $class = shift;

  my $ret = $class->dispatch(qw( cmd with_args_sub one two three four));

  ok $ret eq 'onetwothreefour', $class->message("dispatch succeeded: $ret");
}

sub simple_with_options : Test {
  my $class = shift;

  my $ret = $class->dispatch(qw( cmd WithOptionsSub --subcommand --works=great ));

  ok $ret eq 'great subcommand', $class->message("dispatch succeeded: $ret");
}

sub dispatch {
  my $class = shift;

  local @ARGV = @_;

  my $ret;
  try   { $ret = CLI::Dispatch->run('CLIDTest::Sub') }
  catch { $ret = $_ || 'Obscure error' };

  return $ret;
}

1;



( run in 1.087 second using v1.01-cache-2.11-cpan-39bf76dae61 )