File Coverage

lib/Rex/Pkg.pm
Criterion Covered Total %
statement 23 49 46.9
branch 0 12 0.0
condition 0 5 0.0
subroutine 8 10 80.0
pod 0 2 0.0
total 31 78 39.7


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::Pkg;
6              
7 32     32   475 use v5.12.5;
  32         224  
8 32     32   217 use warnings;
  32         145  
  32         1874  
9              
10             our $VERSION = '1.14.3'; # VERSION
11              
12 32     32   332 use Rex::Config;
  32         105  
  32         813  
13 32     32   355 use Rex::Commands::Gather;
  32         237  
  32         283  
14 32     32   258 use Rex::Hardware;
  32         104  
  32         415  
15 32     32   1543 use Rex::Hardware::Host;
  32         169  
  32         449  
16 32     32   1037 use Rex::Logger;
  32         144  
  32         234  
17              
18 32     32   986 use Data::Dumper;
  32         154  
  32         12998  
19              
20             my %PKG_PROVIDER;
21              
22             sub register_package_provider {
23 0     0 0   my ( $class, $service_name, $service_class ) = @_;
24 0           $PKG_PROVIDER{"\L$service_name"} = $service_class;
25 0           return 1;
26             }
27              
28             sub get {
29              
30 0     0 0   my ($self) = @_;
31              
32 0           my %_host = %{ Rex::Hardware::Host->get() };
  0            
33 0           my $host = {%_host};
34              
35 0   0       my $pkg_provider_for = Rex::Config->get("package_provider") || {};
36              
37             #if(lc($host->{"operatingsystem"}) eq "centos" || lc($host->{"operatingsystem"}) eq "redhat") {
38 0 0         if ( is_redhat() ) {
39 0           $host->{"operatingsystem"} = "Redhat";
40             }
41              
42 0 0         if ( is_debian() ) {
43 0           $host->{"operatingsystem"} = "Debian";
44             }
45              
46 0           my $class = "Rex::Pkg::" . $host->{"operatingsystem"};
47              
48 0           my $provider;
49 0 0 0       if ( ref($pkg_provider_for)
    0          
50             && exists $pkg_provider_for->{ $host->{"operatingsystem"} } )
51             {
52 0           $provider = $pkg_provider_for->{ $host->{"operatingsystem"} };
53 0           $class .= "::$provider";
54             }
55             elsif ( exists $PKG_PROVIDER{$pkg_provider_for} ) {
56 0           $class = $PKG_PROVIDER{$pkg_provider_for};
57             }
58              
59 0           Rex::Logger::debug("Using $class for package management");
60 0           eval "use $class";
61              
62 0 0         if ($@) {
63              
64 0 0         if ($provider) {
65 0           Rex::Logger::info( "Provider not supported (" . $provider . ")" );
66             }
67             else {
68             Rex::Logger::info(
69 0           "OS not supported (" . $host->{"operatingsystem"} . ")" );
70             }
71 0           die("OS/Provider not supported");
72              
73             }
74              
75 0           return $class->new;
76              
77             }
78              
79             1;