| 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 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | package Wizard; | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 1 | $Wizard::VERSION = '0.1006'; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | =pod | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | =head1 NAME | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | Wizard - A framework for building wizard-style applications. | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | =head1 SYNOPSIS | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | # Create a new Wizard | ||||||||||||||||||||
| 51 | use Wizard (); | ||||||||||||||||||||
| 52 | my $wiz = Wizard->new(%attr); | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | # Let the wizard create a form | ||||||||||||||||||||
| 55 | my $form = $wiz->Form(%attr); | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | # Start the wizard, by running the form | ||||||||||||||||||||
| 58 | $wiz->Run($form); | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =head1 DESCRIPTION | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | The Wizard package enables you to create simple input forms in the | ||||||||||||||||||||
| 64 | style of Windows wizards and combine them into a complete application, | ||||||||||||||||||||
| 65 | typically for system administration. The users input form is handled | ||||||||||||||||||||
| 66 | in a single sub, the so-called I<action>. Any action consists of 3 | ||||||||||||||||||||
| 67 | phases: | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | =over 8 | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =item 1.) | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | Processing the input data. | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | =item 2.) | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | Saving the input data. | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =item 3.) | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | Returning data describing the next input form. | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =back | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | You typically only need to setup the actions, the Wizard system should | ||||||||||||||||||||
| 86 | do anything else for you. | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | The framework is based on the wizard object. Different wizard classes | ||||||||||||||||||||
| 89 | are available, for example Form::Wiz::Shell for running the wizard | ||||||||||||||||||||
| 90 | within a shell or Form::Wiz::HTML for running within a web browser. | ||||||||||||||||||||
| 91 | See also L<Wizard::Shell(3)> and L<Wizard::HTML(3)> | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | =head1 CLASS INTERFACE | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | In all cases errors are handled by throwing Perl exceptions, thus we | ||||||||||||||||||||
| 97 | won't talk about errors at all in what follows. | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | =head2 Creating a wizard | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | my $wiz = Wizard->new(\%attr); | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | (Class method) The I<new> method will create a wizard object for you. | ||||||||||||||||||||
| 105 | It receives a hash ref of attributes as arguments. Currently known | ||||||||||||||||||||
| 106 | attributes are: | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =over 8 | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | =item formClass | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | The wizards form class. For example, the Wizard::Shell class will | ||||||||||||||||||||
| 113 | have Wizard::Form::Shell as form class. L<Wizard::Form(3)>. | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | =back | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 0 | ▶ | sub new ($$) { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 120 | 0 | my $class = shift; my $attr = shift; | |||||||||||||||||||
| 121 | 0 | my $self = {%$attr}; | |||||||||||||||||||
| 122 | 0 | ▶ | bless($self, (ref($class) || $class)); | ||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 123 | 0 | $self; | |||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | =pod | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | =head2 Working with input forms | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | # Create a new form | ||||||||||||||||||||
| 132 | my $form = $wiz->Form(%attr); | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | # Fetch the current form | ||||||||||||||||||||
| 135 | $form = $wiz->Form(); | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | (Instance methods) The I<Form> method will create a new form for you. The | ||||||||||||||||||||
| 138 | form is an instance of the wizards I<formClass>, see above. There's always | ||||||||||||||||||||
| 139 | a single form associated to the wizard: The previous form is removed by | ||||||||||||||||||||
| 140 | creating the next one. The action returns a list of input elements that | ||||||||||||||||||||
| 141 | will be used for creating the next form. L<Wizard::Elem(3)>. | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 0 | ▶ | sub Form { | ||||||||||||||||||
|
Subroutine
Form: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 146 | 0 | my $self = shift; | |||||||||||||||||||
| 147 | 0 | ▶ | if (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 148 | 0 | my $class = $self->{'formClass'}; | |||||||||||||||||||
| 149 | 0 | $self->{'form'} = $class->new($self, @_); | |||||||||||||||||||
| 150 | } | ||||||||||||||||||||
| 151 | 0 | $self->{'form'} | |||||||||||||||||||
| 152 | } | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | =pod | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | =head2 Running the wizard | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | $form = $wiz->Run($data); | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | (Instance method) This method is running a single action. The action will | ||||||||||||||||||||
| 162 | read input from $data (typically a CGI or Apache::Request object) by calling | ||||||||||||||||||||
| 163 | its I<param> method. The action returns a list of form elements that will | ||||||||||||||||||||
| 164 | be used for creating the next form. This form will be methods return value. | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | =cut | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | 0 | ▶ | sub Action { | ||||||||||||||||||
|
Subroutine
Action: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 169 | 0 | my $self = shift; | |||||||||||||||||||
| 170 | 0 | ▶ | $self->{'_action'} = shift if @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 171 | 0 | $self->{'_action'}; | |||||||||||||||||||
| 172 | } | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | 0 | ▶ | sub Run { | ||||||||||||||||||
|
Subroutine
Run: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 175 | 0 | my($self, $state) = @_; | |||||||||||||||||||
| 176 | 0 | my $action = "Action_Reset"; | |||||||||||||||||||
| 177 | 0 | my $class; | |||||||||||||||||||
| 178 | 0 | foreach my $key ($self->param()) { | |||||||||||||||||||
| 179 | 0 | ▶ | if ($key =~ /^((.*)\:\:)?(Action_.*)/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 180 | 0 | $class = $2; | |||||||||||||||||||
| 181 | 0 | $action = $3; | |||||||||||||||||||
| 182 | 0 | $self->Action($action); | |||||||||||||||||||
| 183 | 0 | last; | |||||||||||||||||||
| 184 | } | ||||||||||||||||||||
| 185 | } | ||||||||||||||||||||
| 186 | 0 | ▶ | $class ||= ref($state); | ||||||||||||||||||
|
Condition0%0/3
$class ||= ref $state
MC/DC0%0/2
$class ||= ref $state
$class
ref $state
Truth table0%0/3
A ||= B
A= $classB= ref $state
| |||||||||||||||||||||
| 187 | 0 | my $file = $class; | |||||||||||||||||||
| 188 | 0 | $file =~ s/\:\:/\//g; | |||||||||||||||||||
| 189 | 0 | require "$file.pm"; | |||||||||||||||||||
| 190 | 0 | bless $state, $class; | |||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | 0 | my @elems = $state->$action($self); | |||||||||||||||||||
| 193 | 0 | my $form = $self->Form('elems' => \@elems); | |||||||||||||||||||
| 194 | 0 | $form->Display($self, $state); | |||||||||||||||||||
| 195 | 0 | $state; | |||||||||||||||||||
| 196 | } | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | 1 | 1; | |||||||||||||||||||
| 200 | |||||||||||||||||||||
| 201 | __END__ | ||||||||||||||||||||