File Coverage

blib/lib/Ixchel/Actions/extend_logsize_config.pm
Criterion Covered Total %
statement 14 36 38.8
branch 0 12 0.0
condition n/a
subroutine 5 8 62.5
pod 2 3 66.6
total 21 59 35.5


line stmt bran cond sub pod time code
1             package Ixchel::Actions::extend_logsize_config;
2              
3 1     1   120645 use 5.006;
  1         4  
4 1     1   6 use strict;
  1         2  
  1         30  
5 1     1   5 use warnings;
  1         4  
  1         61  
6 1     1   601 use File::Slurp;
  1         46451  
  1         90  
7 1     1   8 use base 'Ixchel::Actions::base';
  1         2  
  1         600  
8              
9             =head1 NAME
10              
11             Ixchel::Actions::extend_logsize_config - Generates the config for the logsize SNMP extend.
12              
13             =head1 VERSION
14              
15             Version 0.0.1
16              
17             =cut
18              
19             our $VERSION = '0.0.1';
20              
21             =head1 CLI SYNOPSIS
22              
23             ixchel -a extend_logsize_config [B<-w>] [B<-o> ]
24              
25             =head1 CODE SYNOPSIS
26              
27             my $results=$ixchel->action(action=>'extends_logsize_config', opts=>{w=>1, np=>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 'extend_logsize'.
38              
39             The returned value is the filed 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 :: /usr/local/etc/logsize.conf
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             sub action_extra {
67 0     0 0   my $self = $_[0];
68              
69             # set the default output for -o if not defined
70 0 0         if ( !defined( $self->{opts}{o} ) ) {
71 0           $self->{opts}{o} = '/usr/local/etc/logsize.conf';
72             }
73              
74             # set the default output for -o if not defined
75 0 0         if ( !defined( $self->{opts}{w} ) ) {
76 0           $self->{opts}{w} = 0;
77             }
78              
79 0           my $filled_in;
80 0           eval {
81             $filled_in = $self->{ixchel}->action(
82 0           action => 'template',
83             vars => {},
84             opts => {
85             np => 1,
86             t => 'extend_logsize',
87             },
88             );
89             };
90 0 0         if ($@) {
91 0           $self->status_add( status => 'Failed to fill out template extend_logsize ... ' . $@, error => 1 );
92 0           return undef;
93             }
94 0           $self->{results}{filled_in} = $filled_in;
95              
96 0 0         if ( !$self->{opts}{np} ) {
97 0           print $filled_in;
98             }
99              
100 0 0         if ( $self->{opts}{w} ) {
101 0           eval { write_file( $self->{opts}{o}, $filled_in ); };
  0            
102 0 0         if ($@) {
103             $self->status_add(
104 0           status => 'Failed to write out filled_in template to "' . $self->{opts}{o} . '" ... ' . $@,
105             error => 1
106             );
107             }
108             }
109              
110 0           return undef;
111             } ## end sub action_extra
112              
113             sub short {
114 0     0 1   return 'Generates the config for the logsize SNMP extend.';
115             }
116              
117             sub opts_data {
118 0     0 1   return '
119             w
120             o=s
121             np
122             ';
123             }
124              
125             1;