File Coverage

blib/lib/Wizard/Examples/Apache.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             # -*- perl -*-
2              
3 1     1   614 use strict;
  1         2  
  1         35  
4              
5 1     1   5 use Wizard::State ();
  1         3  
  1         17  
6 1     1   39 use Wizard::SaveAble ();
  0            
  0            
7             use Wizard::Examples::Apache::Config ();
8              
9              
10             package Wizard::Examples::Apache;
11              
12             @Wizard::Examples::Apache::ISA = qw(Wizard::Examples);
13             $Wizard::Examples::Apache::VERSION = '0.01';
14              
15              
16             sub GetKey { 'prefs'; };
17              
18             sub init {
19             my $self = shift;
20             my $prefs = $self->{'prefs'} || die "Missing preferences";
21             return ($prefs) unless shift;
22             my $basedir = $prefs->{'apache-prefs-basedir'} || die "Missing basedir";
23             wantarray ? ($prefs, $basedir) : $prefs;
24             }
25              
26             sub getFileDir {
27             my($self, $wiz) = @_;
28             my $basedir = $self->{'prefs'}->{'apache-prefs-basedir'};
29             wantarray ? ($basedir, $basedir) : $basedir;
30             }
31              
32             sub Action_Reset {
33             my($self, $wiz) = @_;
34              
35             # Load prefs, if required.
36             unless ($self->{'prefs'}) {
37             my $cfg = $Wizard::Examples::Apache::Config::config;
38             my $file = $cfg->{'apache-prefs-file'};
39             $self->{'prefs'} = Wizard::SaveAble->new('file' => $file, 'load' => 1);
40             $self->Store($wiz);
41             }
42              
43             # Return the initial menu.
44             (['Wizard::Elem::Title', 'value' => 'Apache Wizard Menu'],
45             ['Wizard::Elem::Submit', 'value' => 'Host Menu',
46             'name' => 'Wizard::Examples::Apache::Host::Action_Reset',
47             'id' => 1],
48             ['Wizard::Elem::BR'],
49             ['Wizard::Elem::Submit', 'value' => 'Apache Wizard preferences',
50             'name' => 'Action_Preferences',
51             'id' => 2],
52             ['Wizard::Elem::BR'],
53             ['Wizard::Elem::Submit', 'value' => 'Return to Wizard Examples',
54             'name' => 'Wizard::Examples::Action_Reset',
55             'id' => 98],
56             ['Wizard::Elem::BR'],
57             ['Wizard::Elem::Submit', 'value' => 'Exit Apache Wizard',
58             'id' => 99]);
59             }
60              
61              
62             sub Action_Preferences {
63             my($self, $wiz) = @_;
64             my $prefs = $self->init();
65              
66             # Return a list of input elements.
67             (['Wizard::Elem::Title', 'value' => 'Apache Wizard Preferences'],
68             ['Wizard::Elem::Text', 'name' => 'apache-prefs-basedir',
69             'value' => $prefs->{'apache-prefs-basedir'},
70             'descr' => 'Base Directory of the Apache Wizard'],
71             ['Wizard::Elem::Submit', 'name' => 'Action_PreferencesSave',
72             'value' => 'Save these settings', 'id' => 1],
73             ['Wizard::Elem::Submit', 'name' => 'Action_PreferencesReset',
74             'value' => 'Reset this form', 'id' => 98],
75             ['Wizard::Elem::Submit', 'name' => 'Action_Reset',
76             'value' => 'Return to top menu', 'id' => 99]);
77             }
78              
79              
80             sub Action_PreferencesSave {
81             my($self, $wiz) = @_;
82             my $prefs = $self->init();
83             foreach my $opt (qw(apache-prefs-basedir)) {
84             $prefs->{$opt} = $wiz->param($opt) if defined($wiz->param($opt));
85             }
86             $prefs->Modified(1);
87             $self->Store($wiz, 1);
88             $self->Action_Reset($wiz);
89             }
90              
91              
92             sub Action_PreferencesReset {
93             my($self, $wiz) = @_;
94             $self->Action_Reset($wiz);
95             $self->Action_Preferences($wiz);
96             }
97              
98              
99             1;