-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Item12952: many changes for new confgure architecture
- Loading branch information
crawford
committed
Aug 27, 2014
1 parent
fe0ffeb
commit 81475ce
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# See bottom of file for license and copyright information | ||
package Foswiki::Configure::Wizard; | ||
|
||
=begin TML | ||
---++ package Foswiki::Configure::Wizard | ||
A Wizard is module that performs one or more configuration functions. | ||
For example, you might have a wizard that helps set up email; | ||
when you have all the email settings done, you invoke the wizard | ||
to attempt to complete the configuration. | ||
Any number of callable functions may be defined in a wizard. | ||
Each function _fn_ has the signature: | ||
=ObjectMethod _fn_ ($reporter) -> $boolean= | ||
Wizards can accept | ||
values from callers using the =$this->param()= method. Error messages | ||
etc are reported via the =Foswiki::Configure::Reporter $reporter=. | ||
Wizard functions may modify =$Foswiki::cfg=, but must report | ||
any such changes that have to persist using the | ||
=$reporter->CHANGED= method. | ||
It's up to the UI how wizards are called, and their results returned. | ||
See the documentation for the UI for more information. | ||
=cut | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Assert; | ||
|
||
=begin TML | ||
---++ StaticMethod loadWizard($name, $param_source) -> $wizard | ||
Loads the Foswiki::Configure::Wizards subclass identified | ||
by $name. =$param_source= is a reference to an object that | ||
supports the =param()= method for getting parameter values. | ||
=cut | ||
|
||
sub loadWizard { | ||
my ( $name, $param_source ) = @_; | ||
|
||
ASSERT( $name =~ /^[A-Za-z][A-Za-z0-9]+$/ ) if DEBUG; | ||
|
||
my $class = 'Foswiki::Configure::Wizards::' . $name; | ||
my @packages = Foswiki::Configure::FileUtil::findPackages($class); | ||
|
||
eval "require $class"; | ||
die "Failed to load wizard $class: $@" if $@; | ||
|
||
return $class->new($param_source); | ||
} | ||
|
||
sub new { | ||
my ( $class, $ps ) = @_; | ||
return bless( { param_source => $ps }, $class ); | ||
} | ||
|
||
=begin TML | ||
---++ ObjectMethod param($name) -> $value | ||
Returns the value of a parameter that was given when the wizard was invoked. | ||
=cut | ||
|
||
sub param { | ||
my ( $this, $param ) = @_; | ||
return $this->{param_source}->{$param}; | ||
} | ||
|
||
1; |