File Coverage

blib/lib/MooX/Commander/IsaHelpCommand.pm
Criterion Covered Total %
statement 9 19 47.3
branch 0 6 0.0
condition n/a
subroutine 3 4 75.0
pod 0 1 0.0
total 12 30 40.0


line stmt bran cond sub pod time code
1             package MooX::Commander::IsaHelpCommand;
2              
3 1     1   188866 use Moo::Role;
  1         13654  
  1         9  
4              
5 1     1   686 use String::CamelSnakeKebab qw/upper_camel_case/;
  1         8738  
  1         6  
6 1     1   644 use Class::Load qw/load_class/;
  1         7059  
  1         168  
7              
8             with 'MooX::Commander::HasOptions';
9              
10             has '+argv' => (is => 'lazy');
11              
12             sub go {
13 0     0 0   my ($self, $cmd) = @_;
14              
15 0 0         $self->usage unless $cmd;
16              
17 0           my $class = ref($self);
18 0           $class =~ s/::Help$/::/;
19 0           $class .= upper_camel_case $cmd;
20              
21 0           eval { load_class($class) };
  0            
22 0 0         $self->usage if $@;
23              
24 0           $class->new(argv => $self->argv)->usage;
25 0 0         die $@ if $@;
26             }
27              
28             1;
29              
30             =encoding utf-8
31              
32             =head1 NAME
33              
34             MooX::Commander::IsaHelpCommand - Add a help command to your command line app
35              
36             =head1 SYNOPSIS
37              
38             package PieFactory::Cmd::Help;
39             use Moo;
40             with 'MooX::Commander::IsaHelpCommand';
41              
42             sub usage {
43             return >> EOF
44             usage: pie-factory [options]
45              
46             You have inherited a pie factory. Use your powers wisely.
47            
48             COMMANDS
49             pie-factory recipe list List pie recipes
50             pie-factory recipe show Display a recipe
51             pie-factory recipe add Add a recipe
52             pie-factory recipe delete Delete a recipe
53             pie-factory bake Bake a pie
54             pie-factory eat Eat a pie
55             pie-factory throw Throw a pie at something
56             pie-factory help Get help with a command
57              
58             OPTIONS
59             -v, --version pie-factory version
60             -h, --help Show this message
61             EOF
62             }
63              
64              
65             =head1 DESCRIPTION
66              
67             MooX::Commander::IsaHelpCommand is a simple Moo::Role for adding a help command
68             to your command line app.
69              
70             It loads and instantiates the command class that the user is requesting help
71             with and calls the C method on that object. C works the same
72             way here as it does in L -- it prints
73             the usage statement and exits the program unsuccessfuly.
74              
75             =head1 LICENSE
76              
77             Copyright (C) Eric Johnson.
78              
79             This library is free software; you can redistribute it and/or modify
80             it under the same terms as Perl itself.
81              
82             =head1 AUTHOR
83              
84             Eric Johnson Eeric.git@iijo.orgE
85              
86             =cut
87