File Coverage

blib/lib/MooX/Commander/IsaHelpCommand.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package MooX::Commander::IsaHelpCommand;
2              
3 1     1   140464 use Moo::Role;
  1         16244  
  1         8  
4              
5 1     1   1061 use String::CamelSnakeKebab qw/upper_camel_case/;
  1         10421  
  1         12  
6 1     1   425 use Class::Load qw/load_class/;
  0            
  0            
7              
8             with 'MooX::Commander::HasOptions';
9              
10             has '+argv' => (is => 'lazy');
11              
12             sub go {
13             my ($self, $cmd) = @_;
14              
15             $self->usage unless $cmd;
16              
17             my $class = ref($self);
18             $class =~ s/::Help$/::/;
19             $class .= upper_camel_case $cmd;
20              
21             eval { load_class($class) };
22             $self->usage if $@;
23              
24             $class->new(argv => $self->argv)->usage;
25             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