File Coverage

blib/lib/Ixchel/Actions/auto_cron.pm
Criterion Covered Total %
statement 14 36 38.8
branch 0 12 0.0
condition n/a
subroutine 5 9 55.5
pod 2 4 50.0
total 21 61 34.4


line stmt bran cond sub pod time code
1             package Ixchel::Actions::auto_cron;
2              
3 1     1   88109 use 5.006;
  1         4  
4 1     1   4 use strict;
  1         4  
  1         20  
5 1     1   3 use warnings;
  1         1  
  1         73  
6 1     1   416 use File::Slurp;
  1         34081  
  1         86  
7 1     1   8 use base 'Ixchel::Actions::base';
  1         2  
  1         587  
8              
9             =head1 NAME
10              
11             Ixchel::Actions::auto_cron - Generates a cron file for stuff configured/handled via Ixchel.
12              
13             =head1 VERSION
14              
15             Version 0.1.0
16              
17             =cut
18              
19             our $VERSION = '0.1.0';
20              
21             =head1 CLI SYNOPSIS
22              
23             ixchel -a auto_cron [B<-w>] [B<-o> ]
24              
25             =head1 CODE SYNOPSIS
26              
27             my $results=$ixchel->action(action=>'auto_cron', opts=>{w=>1});
28              
29             if ($results->{ok}) {
30             print $results->{filled_in};
31             }else{
32             die('Action errored... '.joined("\n", @{$results->{errors}}));
33             }
34              
35             =head1 DESCRIPTION
36              
37             The template used is 'auto_cron'.
38              
39             The returned value is the filled in template..
40              
41             =head1 FLAGS
42              
43             =head2 -w
44              
45             Write out the file instead of stdout.
46              
47             =head2 -o
48              
49             File to write the out to if -w is specified.
50              
51             Default :: /etc/cron.d/ixchel
52              
53             =head2 --np
54              
55             Don't print the the filled in template.
56              
57             =head1 RESULT HASH REF
58              
59             .errors :: A array of errors encountered.
60             .status_text :: A string description of what was done and the results.
61             .ok :: Set to zero if any of the above errored.
62             .filled_in :: The filled in template.
63              
64             =cut
65              
66       0 0   sub new_extra { }
67              
68             sub action_extra {
69 0     0 0   my $self = $_[0];
70              
71             # set the default output for -o if not defined
72 0 0         if ( !defined( $self->{opts}{o} ) ) {
73 0           $self->{opts}{o} = '/etc/cron.d/ixchel';
74             }
75              
76             # set the default output for -o if not defined
77 0 0         if ( !defined( $self->{opts}{w} ) ) {
78 0           $self->{opts}{w} = 0;
79             }
80              
81 0           my $filled_in;
82 0           eval {
83             $filled_in = $self->{ixchel}->action(
84 0           action => 'template',
85             vars => {},
86             opts => {
87             np => 1,
88             t => 'auto_cron',
89             },
90             );
91             };
92 0 0         if ($@) {
93 0           $self->status_add( status => 'Failed to fill out template auto_cron ... ' . $@, error => 1 );
94 0           return undef;
95             }
96 0           $self->{results}{filled_in} = $filled_in;
97              
98 0 0         if ( !$self->{opts}{np} ) {
99 0           print $filled_in;
100             }
101              
102 0 0         if ( $self->{opts}{w} ) {
103 0           eval { write_file( $self->{opts}{o}, $filled_in ); };
  0            
104 0 0         if ($@) {
105             $self->status_add(
106 0           status => 'Failed to write out filled in template to "' . $self->{opts}{o} . '" ... ' . $@,
107             error => 1
108             );
109             }
110             }
111              
112 0           return undef;
113             } ## end sub action
114              
115             sub short {
116 0     0 1   return 'Generates a cron file for stuff configured/handled via Ixchel.';
117             }
118              
119             sub opts_data {
120 0     0 1   return '
121             w
122             o=s
123             np
124             ';
125             }
126              
127             1;