File Coverage

blib/lib/Rex/Apache/Deploy/Package/tgz.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4             # vim: set ts=3 sw=3 tw=0:
5             # vim: set expandtab:
6              
7             =head1 NAME
8              
9             Rex::Apache::Deploy::tgz - Deploy tgz package
10              
11             =head1 DESCRIPTION
12              
13             With this module you can deploy a TGZ packages.
14              
15             If the package is not build yet, it will pass all the arguments to the build() function and executes the build on the local machine.
16              
17             =head1 SYNOPSIS
18              
19             deploy "my-software.tgz";
20            
21             deploy "my-software",
22             type => "rpm",
23             version => "1.0",
24             # below this, it is all optional
25             source => "html",
26             path => "/var/www/html";
27              
28             =cut
29              
30              
31             package Rex::Apache::Deploy::Package::tgz;
32              
33 1     1   2624 use strict;
  1         2  
  1         32  
34 1     1   6 use warnings;
  1         3  
  1         26  
35              
36 1     1   6511 use Rex::Apache::Build;
  0            
  0            
37             use Rex::Commands;
38             use Rex::Commands::Upload;
39             use Rex::Commands::Run;
40             use Rex::Commands::Fs;
41             use Rex::Apache::Deploy::Package::Base;
42             use base qw(Rex::Apache::Deploy::Package::Base);
43              
44              
45             sub new {
46             my $that = shift;
47             my $proto = ref($that) || $that;
48             my $self = $proto->SUPER::new(@_);
49              
50             bless($self, $proto);
51              
52             return $self;
53             }
54              
55             sub deploy {
56             my ($self, $package_name, %option) = @_;
57              
58              
59             LOCAL {
60             if(! -f $package_name) {
61             $package_name = $self->name . "-" . $self->version . ".tar.gz";
62              
63             if(! -f $package_name) {
64             build($self->name, %option);
65             }
66             }
67             };
68              
69             upload $package_name, "/tmp";
70              
71             my $to = $self->prefix;
72             run "tar -C $to -xzf /tmp/$package_name";
73             if($? != 0) {
74             die("Error installing $package_name");
75             }
76              
77             Rex::Logger::info("Package $package_name installed.");
78              
79             unlink "/tmp/$package_name";
80             }
81              
82             1;