line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#! -*- perl -*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Wizard - A Perl package for implementing system administration |
4
|
|
|
|
|
|
|
# applications in the style of Windows wizards. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# This module is |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Copyright (C) 1999 Jochen Wiedmann |
10
|
|
|
|
|
|
|
# Am Eisteich 9 |
11
|
|
|
|
|
|
|
# 72555 Metzingen |
12
|
|
|
|
|
|
|
# Germany |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# Email: joe@ispsoft.de |
15
|
|
|
|
|
|
|
# Phone: +49 7123 14887 |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# and Amarendran R. Subramanian |
18
|
|
|
|
|
|
|
# Grundstr. 32 |
19
|
|
|
|
|
|
|
# 72810 Gomaringen |
20
|
|
|
|
|
|
|
# Germany |
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# Email: amar@ispsoft.de |
23
|
|
|
|
|
|
|
# Phone: +49 7072 920696 |
24
|
|
|
|
|
|
|
# |
25
|
|
|
|
|
|
|
# All Rights Reserved. |
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public |
28
|
|
|
|
|
|
|
# License or the Artistic License, as specified in the Perl README file. |
29
|
|
|
|
|
|
|
# |
30
|
|
|
|
|
|
|
# $Id$ |
31
|
|
|
|
|
|
|
# |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
799
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
249
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=pod |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 NAME |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Wizard::State - A class for storing the Wizard state. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Create a new state |
46
|
|
|
|
|
|
|
my $state = Wizard::State->new(); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 DESCRIPTION |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
A Wizard can be interpreted as a very simple finite state machine. The |
52
|
|
|
|
|
|
|
state is stored in ab object of class Wizard::State. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
A wizard state is typically a collection of Wizard::SaveAble objects. |
55
|
|
|
|
|
|
|
For example, while configuring an Apache webserver, the state might |
56
|
|
|
|
|
|
|
have attributes I (global preferences), I (the machine |
57
|
|
|
|
|
|
|
where the webserver is running on) and I (the web server), each |
58
|
|
|
|
|
|
|
of them being a SaveAble object. If the state's I method is |
59
|
|
|
|
|
|
|
called, then the I method is called for any of these objects, |
60
|
|
|
|
|
|
|
as if they were a single object. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 CLASS INTERFACE |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 Constructor |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $state = Wizard::State->new(\%attr) |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
(Class Method) A new object is generated by calling its I method. |
69
|
|
|
|
|
|
|
The object attributes are passed as a hash ref. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
package Wizard::State; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub new { |
76
|
0
|
|
|
0
|
0
|
|
my $proto = shift; my $attr = shift; |
|
0
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $self = { %$attr }; |
78
|
0
|
|
0
|
|
|
|
bless($self, (ref($proto) || $proto)); |
79
|
0
|
|
|
|
|
|
$self->{'running'} = 1; |
80
|
0
|
|
|
|
|
|
$self; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=pod |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 Terminating the application |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Stopping the application |
88
|
|
|
|
|
|
|
$state->Running(0); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Querying whether the application is running |
91
|
|
|
|
|
|
|
$is_running = $state->Running(); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
(Instance method) The state's I method can be used to set or |
94
|
|
|
|
|
|
|
get its I attribute. This attribute will be set to 0 for |
95
|
|
|
|
|
|
|
stopping the application. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub Running { |
100
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
101
|
0
|
0
|
|
|
|
|
$self->{'running'} = shift if @_; |
102
|
0
|
|
|
|
|
|
$self->{'running'}; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=pod |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 Storing a state |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Storing a state temporarily; real SaveAble objects won't be |
111
|
|
|
|
|
|
|
# changed |
112
|
|
|
|
|
|
|
$state->Store($wiz); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Storing a state, including the SaveAble objects. |
115
|
|
|
|
|
|
|
$state->Store($wiz, 1); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub Store { |
120
|
0
|
|
|
0
|
0
|
|
my $self = shift; my $wiz = shift; |
|
0
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
$wiz->Store($self); |
122
|
0
|
0
|
|
|
|
|
return unless shift; |
123
|
0
|
|
|
|
|
|
while (my($var, $val) = each %$self) { |
124
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::can($val, 'Store')) { |
125
|
0
|
|
|
|
|
|
$val->Store(); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |