File Coverage

blib/lib/Ixchel/Actions/list_actions.pm
Criterion Covered Total %
statement 14 32 43.7
branch 0 6 0.0
condition n/a
subroutine 5 9 55.5
pod 2 4 50.0
total 21 51 41.1


line stmt bran cond sub pod time code
1             package Ixchel::Actions::list_actions;
2              
3 1     1   139913 use 5.006;
  1         5  
4 1     1   6 use strict;
  1         3  
  1         49  
5 1     1   5 use warnings;
  1         2  
  1         61  
6 1     1   741 use Module::List qw(list_modules);
  1         32228  
  1         118  
7 1     1   9 use base 'Ixchel::Actions::base';
  1         2  
  1         600  
8              
9             =head1 NAME
10              
11             Ixchel::Actions::list_actions - Lists the various actions with a short description.
12              
13             =head1 VERSION
14              
15             Version 0.2.0
16              
17             =cut
18              
19             our $VERSION = '0.2.0';
20              
21             =head1 CLI SYNOPSIS
22              
23             ixchel -a list_actions
24              
25             =head1 CODE SYNOPSIS
26              
27             my $results $ixchel->action(action=>'list_actions', opts=>{np=>1}
28              
29             if ($results->{ok}) {
30             print $results->{status_text};
31             }else{
32             die('Action errored... '.joined("\n", @{$results->{errors}}));
33             }
34              
35             =head1 FLAGS
36              
37             =head2 --np
38              
39             Don't print the the filled in template.
40              
41             =head1 RESULT HASH REF
42              
43             .errors :: A array of errors encountered.
44             .status_text :: A string description of what was done and the results.
45             .ok :: Set to zero if any of the above errored.
46              
47             =cut
48              
49       0 0   sub new_extra { }
50              
51             sub action_extra {
52 0     0 0   my $self = $_[0];
53              
54 0           my $actions = list_modules( "Ixchel::Actions::", { list_modules => 1 } );
55              
56 0           foreach my $action ( sort( keys( %{$actions} ) ) ) {
  0            
57 0 0         if ( $action ne 'Ixchel::Actions::base' ) {
58 0           my $action_name = $action;
59 0           $action_name =~ s/^Ixchel\:\:Actions\:\://;
60              
61 0           my $short;
62 0           my $to_eval = 'use ' . $action . '; $short=' . $action . '->short;';
63 0           eval($to_eval);
64 0 0         if ( !defined($short) ) {
65 0           $short = '';
66             }
67 0           my $new_line = $action_name . ' : ' . $short . "\n";
68 0           $self->{results}{status_text} = $self->{results}{status_text} . $new_line;
69 0 0         if ( !$self->{opts}{np} ) {
70 0           print $new_line;
71             }
72             } ## end if ( $action ne 'Ixchel::Actions::base' )
73             } ## end foreach my $action ( sort( keys( %{$actions} ) ...))
74             } ## end sub action_extra
75              
76             sub short {
77 0     0 1   return 'Lists the available actions.';
78             }
79              
80             sub opts_data {
81 0     0 1   return 'np
82             '
83             ;
84             }
85              
86             1;