File Coverage

blib/lib/MooX/Cmd.pm
Criterion Covered Total %
statement 43 43 100.0
branch 19 20 95.0
condition n/a
subroutine 9 9 100.0
pod n/a
total 71 72 98.6


line stmt bran cond sub pod time code
1             package MooX::Cmd;
2             # ABSTRACT: Giving an easy Moo style way to make command organized CLI apps
3             our $VERSION = '1.000';
4 6     6   549418 use strict;
  6         14  
  6         263  
5 6     6   36 use warnings;
  6         14  
  6         369  
6              
7 6     6   714 use Package::Stash;
  6         10375  
  6         442  
8              
9             sub import
10             {
11 20     20   56156 my (undef, %import_options) = @_;
12 20         84 my $caller = caller;
13 20         76 my @caller_isa;
14             ## no critic qw(ProhibitNoStrict)
15 6     6   41 { no strict 'refs'; @caller_isa = @{"${caller}::ISA"} };
  6         29  
  6         3370  
  20         46  
  20         41  
  20         170  
16              
17             #don't add this to a role
18             #ISA of a role is always empty !
19 20 50       89 @caller_isa or return;
20              
21 20         54 my $execute_return_method_name = $import_options{execute_return_method_name};
22              
23 20 100       106 exists $import_options{execute_from_new} or $import_options{execute_from_new} = 1; # set default until we want other way
24              
25 20         1972 my $stash = Package::Stash->new($caller);
26             defined $import_options{execute_return_method_name}
27             and $stash->add_symbol('&' . $import_options{execute_return_method_name},
28 20 100   1   119 sub { shift->{$import_options{execute_return_method_name}} });
  1         26  
29 20 100       124 defined $import_options{creation_method_name} or $import_options{creation_method_name} = "new_with_cmd";
30 20     43   513 $stash->add_symbol('&' . $import_options{creation_method_name}, sub { shift->_initialize_from_cmd(@_); });
  43         388629  
31              
32             my $apply_modifiers = sub {
33 20 100   20   366 $caller->can('_initialize_from_cmd') and return;
34 19         111 my $with = $caller->can('with');
35 19         99 $with->('MooX::Cmd::Role');
36             # XXX prove whether it can chained ...
37 19 100       85281 $import_options{with_config_from_file} and $with->('MooX::ConfigFromFile::Role');
38 19 100       21909 $import_options{with_config_from_file} and $with->('MooX::Cmd::Role::ConfigFromFile');
39 19 100       11934 $import_options{with_abbrev_cmds} and $with->('MooX::Cmd::Role::AbbrevCmds');
40 20         141 };
41 20         92 $apply_modifiers->();
42              
43 20         7694 my %default_modifiers = (
44             base => '_build_command_base',
45             execute_method_name => '_build_command_execute_method_name',
46             execute_return_method_name => '_build_command_execute_return_method_name',
47             creation_chain_methods => '_build_command_creation_chain_methods',
48             creation_method_name => '_build_command_creation_method_name',
49             execute_from_new => '_build_command_execute_from_new',
50             );
51              
52 20         54 my $around;
53 20         83 foreach my $opt_key (keys %default_modifiers)
54             {
55 120 100       33504 exists $import_options{$opt_key} or next;
56 41 100       250 $around or $around = $caller->can('around');
57 41     38   275 $around->($default_modifiers{$opt_key} => sub { $import_options{$opt_key} });
  38         2734  
58             }
59              
60 20         5631 return;
61             }
62              
63             1;
64              
65             __END__