annotate Lib/Deployment/Batch/Temp.pm @ 10:63f6653b094e

DOM
author Sergey
date Fri, 28 Aug 2009 16:26:20 +0400
parents 03e58a454b20
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
1 use strict;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
2 package Deployment::Batch::Temp;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3 use base qw(Deployment::Batch::Generic);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4 use Common;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
5 use File::Temp;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
6
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
7
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8 BEGIN {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9 DeclareProperty TmpObj => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10 DeclareProperty Ref => ACCESS_NONE;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11 DeclareProperty TmpObjType => ACCESS_NONE;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
12 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
13
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
14 sub CTOR {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
15 my ($this,$type,$ref) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
16
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
17 die "A reference to the temp object can be obtained only in the immediate mode" if $ref and not $this->Context->{Immediate};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
18
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
19 $this->{$TmpObjType} = $type or die "The type of a temporary object should be specified";
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
20 $this->{$Ref} = $ref;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
21 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
22
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23 sub Run {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24 my ($this) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
25
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
26 if ($this->{$TmpObjType} eq 'File') {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
27 $this->{$TmpObj} = File::Temp->new;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
28 if ($this->{$Ref}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29 ${$this->{$Ref}} = $this->{$TmpObj};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
30 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
31 $this->Context('tmpfile') = $this->{$TmpObj}->filename;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
32 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
33 } elsif ($this->{$TmpObjType} eq 'Dir') {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
34 $this->{$TmpObj} = File::Temp->newdir;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
35 if ($this->{$Ref}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
36 ${$this->{$Ref}} = $this->{$TmpObj};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
37 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
38 $this->Context('tmpdir') = $this->{$TmpObj}->dirname;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
39 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
40 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
41 die "Don't know how to create a temporary $this->{$TmpObjType}";
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
42 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
43 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
44
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
45 sub DESTORY {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
46 my ($this) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
47
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
48 undef $this->{$TmpObj};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
49 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
50
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
51
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
52 1;