File Coverage

blib/lib/Ixchel/Actions/apt_proxy.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::apt_proxy;
2              
3 1     1   85304 use 5.006;
  1         4  
4 1     1   4 use strict;
  1         4  
  1         17  
5 1     1   4 use warnings;
  1         2  
  1         43  
6 1     1   718 use File::Slurp;
  1         33013  
  1         62  
7 1     1   7 use base 'Ixchel::Actions::base';
  1         1  
  1         502  
8              
9             =head1 NAME
10              
11             Ixchel::Actions::apt_proxy - Generates the proxy config file for apt.
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 apt_proxy [B<-w>] [B<-o> ]
24              
25             =head1 CODE SYNOPSIS
26              
27             my $results=$ixchel->action(action=>'apt_proxy', 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 'apt_proxy'.
38              
39             The returned value is the filed in template.
40              
41             The template used is apt_proxy.
42              
43             =head1 FLAGS
44              
45             =head2 -w
46              
47             Write out the file.
48              
49             =head2 -o
50              
51             File to write the out to if -w is specified.
52              
53             Default :: /etc/apt/apt.conf.d/00aptproxy
54              
55             =head2 --np
56              
57             Don't print the the filled in template.
58              
59             =head1 RESULT HASH REF
60              
61             .errors :: A array of errors encountered.
62             .status_text :: A string description of what was done and the results.
63             .ok :: Set to zero if any of the above errored.
64             .filled_in :: The filled in template.
65              
66             =cut
67              
68       0 0   sub new_extra { }
69              
70             sub action_extra {
71 0     0 0   my $self = $_[0];
72              
73             # set the default output for -o if not defined
74 0 0         if ( !defined( $self->{opts}{o} ) ) {
75 0           $self->{opts}{o} = '/etc/apt/apt.conf.d/00aptproxy';
76             }
77              
78             # set the default output for -o if not defined
79 0 0         if ( !defined( $self->{opts}{w} ) ) {
80 0           $self->{opts}{w} = 0;
81             }
82              
83 0           my $filled_in;
84 0           eval {
85             $filled_in = $self->{ixchel}->action(
86 0           action => 'template',
87             vars => {},
88             opts => {
89             np => 1,
90             t => 'apt_proxy',
91             },
92             );
93             };
94 0 0         if ($@) {
95 0           $self->status_add( status => 'Failed to fill out template apt_proxy ... ' . $@, error => 1 );
96 0           return undef;
97             }
98 0           $self->{results}{filled_in} = $filled_in;
99              
100 0 0         if ( !$self->{opts}{np} ) {
101 0           print $filled_in;
102             }
103              
104 0 0         if ( $self->{opts}{w} ) {
105 0           eval { write_file( $self->{opts}{o}, $filled_in ); };
  0            
106 0 0         if ($@) {
107             $self->status_add(
108 0           status => 'Failed to write out filled in template to "' . $self->{opts}{o} . '" ... ' . $@,
109             error => 1
110             );
111             }
112             }
113              
114 0           return undef;
115             } ## end sub action_extra
116              
117             sub short {
118 0     0 1   return 'Generates the proxy config file for apt.';
119             }
120              
121             sub opts_data {
122 0     0 1   return '
123             w
124             o=s
125             np
126             ';
127             }
128              
129             1;