File Coverage

blib/lib/Ixchel/Actions/sneck_config.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::sneck_config;
2              
3 1     1   106549 use 5.006;
  1         4  
4 1     1   6 use strict;
  1         2  
  1         73  
5 1     1   8 use warnings;
  1         2  
  1         76  
6 1     1   575 use File::Slurp;
  1         39615  
  1         62  
7 1     1   6 use base 'Ixchel::Actions::base';
  1         2  
  1         384  
8              
9             =head1 NAME
10              
11             Ixchel::Actions::sneck_config - Generates the config for the Sneck.
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 sneck_config [B<-w>] [B<-o> ]
24              
25             =head1 CODE SYNOPSIS
26              
27             my $results=$ixchel->action(action=>'sneck_config', 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 'sneck'.
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/sneck.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       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} = '/usr/local/etc/sneck.conf';
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 => 'sneck',
89             },
90             );
91             };
92 0 0         if ($@) {
93 0           $self->status_add(
94             status => 'Filling in the template failed... ' . $@,
95             error => 1,
96             );
97 0           return undef;
98             }
99 0           $self->{results}{filled_in} = $filled_in;
100              
101 0 0         if ( !$self->{opts}{np} ) {
102 0           print $filled_in;
103             }
104              
105 0 0         if ( $self->{opts}{w} ) {
106 0           eval { write_file( $self->{opts}{o}, $filled_in ); };
  0            
107 0 0         if ($@) {
108             $self->status_add(
109 0           status => 'Failed to write out filled in template to "' . $self->{opts}{o} . '" ... ' . $@,
110             error => 1
111             );
112             }
113             }
114              
115 0           return undef;
116             } ## end sub action_extra
117              
118             sub short {
119 0     0 1   return 'Generates the config for the Sneck.';
120             }
121              
122             sub opts_data {
123 0     0 1   return '
124             w
125             np
126             o=s
127             ';
128             }
129              
130             1;