0
|
1 use strict;
|
|
2 package Deployment::Batch::Temp;
|
|
3 use base qw(Deployment::Batch::Generic);
|
|
4 use Common;
|
|
5 use File::Temp;
|
|
6
|
|
7
|
|
8 BEGIN {
|
|
9 DeclareProperty TmpObj => ACCESS_READ;
|
|
10 DeclareProperty Ref => ACCESS_NONE;
|
|
11 DeclareProperty TmpObjType => ACCESS_NONE;
|
|
12 }
|
|
13
|
|
14 sub CTOR {
|
|
15 my ($this,$type,$ref) = @_;
|
|
16
|
|
17 die "A reference to the temp object can be obtained only in the immediate mode" if $ref and not $this->Context->{Immediate};
|
|
18
|
|
19 $this->{$TmpObjType} = $type or die "The type of a temporary object should be specified";
|
|
20 $this->{$Ref} = $ref;
|
|
21 }
|
|
22
|
|
23 sub Run {
|
|
24 my ($this) = @_;
|
|
25
|
|
26 if ($this->{$TmpObjType} eq 'File') {
|
|
27 $this->{$TmpObj} = File::Temp->new;
|
|
28 if ($this->{$Ref}) {
|
|
29 ${$this->{$Ref}} = $this->{$TmpObj};
|
|
30 } else {
|
|
31 $this->Context('tmpfile') = $this->{$TmpObj}->filename;
|
|
32 }
|
|
33 } elsif ($this->{$TmpObjType} eq 'Dir') {
|
|
34 $this->{$TmpObj} = File::Temp->newdir;
|
|
35 if ($this->{$Ref}) {
|
|
36 ${$this->{$Ref}} = $this->{$TmpObj};
|
|
37 } else {
|
|
38 $this->Context('tmpdir') = $this->{$TmpObj}->dirname;
|
|
39 }
|
|
40 } else {
|
|
41 die "Don't know how to create a temporary $this->{$TmpObjType}";
|
|
42 }
|
|
43 }
|
|
44
|
|
45 sub DESTORY {
|
|
46 my ($this) = @_;
|
|
47
|
|
48 undef $this->{$TmpObj};
|
|
49 }
|
|
50
|
|
51
|
|
52 1; |