ShipIt/Step/MakeDist.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 60 CC 5 SCAR 21.6
CC
5
Cov
0%
init
12.0
run
12.0
BEGIN
2.0
CRAP 8.7
1 package ShipIt::Step::MakeDist;
2 use strict;
3 use base 'ShipIt::Step';
4 use File::Copy ();
5  
6 sub init {
7 my ($self, $conf) = @_;
8 my $dir = $conf->value("MakeDist.destination") || "~/shipit-dist";
9 $dir =~ s/^~/$ENV{HOME}/;
10 unless (-e $dir) {
11 mkdir $dir or die "Failed to mkdir $dir: $!\n";
12 }
13 die "Config value of MakeDist.destination isn't a directory" unless -d $dir;
14 $self->{distdir} = $dir;
15 }
16  
17 sub run {
18 my ($self, $state) = @_;
19 my $pt = $state->pt;
20 my $file = $pt->makedist;
21  
22 if ($state->trial) {
23 my $orig_file = $file;
24 $file =~ s/\.(tar\.gz|tgz|tar.bz2|tbz|zip)$/-TRIAL.$1/
25 or die "Distfile doesn't match supported archive format: $orig_file";
26 warn "renaming $orig_file -> $file for TRIAL release\n";
27 rename $orig_file, $file or die "Renaming $orig_file -> $file failed: $!";
28 }
29  
30 File::Copy::move($file, $self->{distdir})
31 or die "Moving distfile $file to $self->{distdir} failed: $!\n";
32  
33 $file =~ s!.*/!!; # keep only basename of file
34 $file = "$self->{distdir}/$file";
35 die "Distfile should be at $file but isn't.\n" unless -e $file;
36 warn "Distfile now at $file\n";
37  
38 $state->set_distfile($file);
39 }
40  
41 1;