annotate Lib/Deployment/Batch/Generic.pm @ 7:94d47b388442

Улучшены тесты Исправлены ошибки Улучшена документация Работа над схемой DOM
author Sergey
date Mon, 24 Aug 2009 01:05:34 +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;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3 our @history;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
5 package Deployment::Batch::Generic;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
6 use Common;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
7 use Time::HiRes;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8 our @ISA = qw(Object);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10 BEGIN {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11 DeclareProperty isProcessed => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
12 DeclareProperty LastError => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
13 DeclareProperty LocalHistory => ACCESS_NONE;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
14 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
15
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
16 sub _Run {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
17 my ($this) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
18
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
19 undef $@;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
20 local @history = ();
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
21 my $t0 = [Time::HiRes::gettimeofday];
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
22 eval {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23 $this->Run;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24 };
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
25 $this->Log("completed in ",Time::HiRes::tv_interval($t0)," s");
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
26
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
27 if ($@) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
28 $this->{$LastError} = $@;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29 Deployment::Batch::Rollback; # rallback nested actions
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
30 return 0;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
31 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
32
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
33 $this->{$LocalHistory} = \@history;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
34 $this->{$isProcessed} = 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
35
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
36 return 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
37 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
38
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
39 sub Name {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
40 my $this = shift;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
41 (my $mod = ref $this) =~ s/^(?:\w+\:\:)*(\w+)$/$1/;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
42 return $mod;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
43 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
44
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
45 sub _Rollback {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
46 my ($this) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
47
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
48 undef $@;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
49 eval {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
50 $this->Rollback;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
51 };
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
52
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
53 if ($@) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
54 $this->{$LastError} = $@;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
55 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
56
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
57 $this->{$isProcessed} = 0;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
58
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
59 if ($this->{$LocalHistory}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
60 local @history = @{$this->{$LocalHistory}};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
61 Deployment::Batch::Rollback;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
62 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
63
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
64 return 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
65 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
66
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
67 sub Context {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
68 my $this = shift;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
69
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
70 return \%Deployment::Batch::Context;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
71 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
72
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
73 sub Log {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
74 my $this = shift @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
75 if ($this->Context->{LogOutput}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
76 my $out = $this->Context->{LogOutput};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
77 print $out $this->Name,": ",@_,"\n";
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
78 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
79 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
80
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
81 sub Run {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
82 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
83
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
84 sub Rollback {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
85 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
86
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
87 1;