File Coverage

blib/lib/Ixchel/Actions/pkgs.pm
Criterion Covered Total %
statement 14 73 19.1
branch 0 12 0.0
condition 0 9 0.0
subroutine 5 9 55.5
pod 2 4 50.0
total 21 107 19.6


line stmt bran cond sub pod time code
1             package Ixchel::Actions::pkgs;
2              
3 1     1   133666 use 5.006;
  1         4  
4 1     1   14 use strict;
  1         3  
  1         39  
5 1     1   6 use warnings;
  1         1  
  1         79  
6 1     1   637 use Rex::Commands::Pkg;
  1         267896  
  1         12  
7 1     1   749 use base 'Ixchel::Actions::base';
  1         2  
  1         43  
8              
9             =head1 NAME
10              
11             Ixchel::Actions::pkgs - Handles making sure desired packages are installed as specified by the config.
12              
13             =head1 VERSION
14              
15             Version 0.3.0
16              
17             =cut
18              
19             our $VERSION = '0.3.0';
20              
21             =head1 CLI SYNOPSIS
22              
23             ixchel -a pkgs
24              
25             =head1 CODE SYNOPSIS
26              
27             my $results=$ixchel->action(action=>'pkgs', opts=>{}'});
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 modules to be installed are determined by the config.
38              
39             - .pkgs.latest :: Packages to ensure that are installed and up to date, updating if needed.
40             - Default :: []
41              
42             - .pkgs.present :: Packages to ensure that are installed, installing if not needed. Will not update
43             the package if it is installed an update is available.
44             - Default :: []
45              
46             - .pkgs.absent :: Packages to ensure that are not installed, uninstalling if present.
47             - Default :: []
48              
49             =head1 FLAGS
50              
51             None.
52              
53             =head1 RESULT HASH REF
54              
55             .errors :: A array of errors encountered.
56             .status_text :: A string description of what was done and the results.
57             .ok :: Set to zero if any of the above errored.
58              
59             =cut
60              
61       0 0   sub new_extra { }
62              
63             sub action_extra {
64 0     0 0   my $self = $_[0];
65              
66 0           my $latest = '';
67 0           my @latest_failed;
68             my @latest_handled;
69 0           my $present = '';
70 0           my @present_failed;
71             my @present_handled;
72 0           my $absent = '';
73 0           my @absent_failed;
74             my @absent_handled;
75              
76 0 0 0       if ( ref( $self->{config}{pkgs}{latest} ) eq 'ARRAY' && defined( $self->{config}{pkgs}{latest}[0] ) ) {
77 0           $latest = join( ', ', @{ $self->{config}{pkgs}{latest} } );
  0            
78 0           $self->status_add( status => 'Starting Latest: ' . $latest );
79 0           foreach my $pkg ( @{ $self->{config}{pkgs}{latest} } ) {
  0            
80 0           $self->status_add( status => 'ensuring ' . $pkg . ' is latest..' );
81 0           eval { pkg( $pkg, ensure => 'latest' ); };
  0            
82 0 0         if ($@) {
83 0           $self->status_add( status => $pkg . ' errored... ' . $@, error => 1 );
84 0           push( @latest_failed, $pkg );
85             } else {
86 0           push( @latest_handled, $pkg );
87             }
88             } ## end foreach my $pkg ( @{ $self->{config}{pkgs}{latest...}})
89             } ## end if ( ref( $self->{config}{pkgs}{latest} ) ...)
90              
91 0 0 0       if ( ref( $self->{config}{pkgs}{present} ) eq 'ARRAY' && defined( $self->{config}{pkgs}{present}[0] ) ) {
92 0           $present = join( ', ', @{ $self->{config}{pkgs}{present} } );
  0            
93 0           $self->status_add( status => 'Starting Present: ' . $present );
94 0           foreach my $pkg ( @{ $self->{config}{pkgs}{present} } ) {
  0            
95 0           $self->status_add( status => 'ensuring ' . $pkg . ' is present...' );
96 0           eval { pkg( $pkg, ensure => 'present' ); };
  0            
97 0 0         if ($@) {
98 0           $self->status_add( status => $pkg . ' errored... ' . $@, error => 1 );
99 0           push( @present_failed, $pkg );
100             } else {
101 0           push( @present_handled, $pkg );
102             }
103             } ## end foreach my $pkg ( @{ $self->{config}{pkgs}{present...}})
104             } ## end if ( ref( $self->{config}{pkgs}{present} )...)
105              
106 0 0 0       if ( ref( $self->{config}{pkgs}{absent} ) eq 'ARRAY' && defined( $self->{config}{pkgs}{absent}[0] ) ) {
107 0           $absent = join( ', ', @{ $self->{config}{pkgs}{absent} } );
  0            
108 0           $self->status_add( status => 'Starting Absent: ' . $absent );
109 0           foreach my $pkg ( @{ $self->{config}{pkgs}{absent} } ) {
  0            
110 0           $self->status_add( status => 'ensuring ' . $pkg . ' is absent...' );
111 0           eval { pkg( $pkg, ensure => 'absent' ); };
  0            
112 0 0         if ($@) {
113 0           $self->status_add( status => $pkg . ' errored... ' . $@, error => 1 );
114 0           push( @absent_failed, $pkg );
115             } else {
116 0           push( @absent_handled, $pkg );
117             }
118             } ## end foreach my $pkg ( @{ $self->{config}{pkgs}{absent...}})
119             } ## end if ( ref( $self->{config}{pkgs}{absent} ) ...)
120              
121 0           $self->status_add( status => 'Latest: ' . $latest );
122 0           $self->status_add( status => 'Latest Handled: ' . join( ', ', @latest_handled ) );
123 0           $self->status_add( status => 'Latest Failed: ' . join( ', ', @latest_failed ) );
124 0           $self->status_add( status => 'Present: ' . join( ', ', @{ $self->{config}{pkgs}{present} } ) );
  0            
125 0           $self->status_add( status => 'Present Handled: ' . $present );
126 0           $self->status_add( status => 'Present Failed: ' . join( ', ', @present_failed ) );
127 0           $self->status_add( status => 'Absent: ' . $absent );
128 0           $self->status_add( status => 'Absent Handled: ' . join( ', ', @absent_handled ) );
129 0           $self->status_add( status => 'Absent Failed: ' . join( ', ', @absent_failed ) );
130              
131 0           return undef;
132             } ## end sub action_extra
133              
134             sub short {
135 0     0 1   return 'Install packages specified by the config.';
136             }
137              
138             sub opts_data {
139 0     0 1   return '
140             ';
141             }
142              
143             1;