MKDoc::Setup - Generic user setup for MKDoc products.


MKDoc::Setup provides a generic base class to make user-friendly installation procedures for applications which are meant to integrate in the MKDoc::Core framework.

Although this class stands on its two feet, it is a mockup class. It is meant to be subclassed for different installations.

MKDoc::Setup doesn't do anything useful on it's own, however you can run it 'as is' for testing purposes, e.g:

  perl -MMKDoc::Setup -e mockup

If you want to see actual subclasses, look at MKDoc::Setup::MKDoc and MKDoc::Setup::Site.

Methods which you should know about

Other methods / functions


Just a bit of syntaxic sugar to ease command line usage, i.e.

  perl -MMKDoc::Setup -e mockup

re-write main::mockup() to main::somethingelse() in your sub-classes.

  sub main::another { __PACKAGE__->new()->process() }

You can then do:

  perl -MMKDoc::Setup -e another


You MUST subclass this method.

In this method you define a list of keys which you want configuration values for and in the order in which you want them displayed. For example:

  sub keys
      my $self = shift;
      return qw /foo bar baz/;

Might display something like this once run:

  1. Foo: Carrot
  2. Bar: Tomato
  3. Baz: Banana

$self->label ($key);

You MUST subclass this method.

Returns a human readable label for a given key. In the example above, the menu displays 'Foo' (notice the capital letter) for a key 'foo'. This is done as follows:

  sub label
      my $self = shift;

      $_ = shift;
      /foo/ and return 'Foo';
      /bar/ and return 'Bar';
      /baz/ and return 'Baz';


You MUST subclass this method - assuming you want your installer to actually install things :-)

  sub install
      # some install code here...
      print "\n\nDone.\n";
      exit (0);


You MAY subclass this method.

Initializes $self, the setup object. $self is a hash which contains key / value pairs for setup config. This method gives you a chance to initialize your object with sensible, default values before those values are presented to the user.


You MAY subclass this method.

If you must do any tests on the data to make sure it complies witch whichever validation rules you choose to implement, you can do it by subclassing validate().

Returns TRUE if the object validates, FALSE otherwise.

I suggest your validate method looks like this:

  sub validate
      my $self = shift;
      $self->validate_xxx() &
      $self->validate_yyy() &

  sub validate_xxx
      my $self = shift;
      $self->some_failure_condition() and do {
          print "Meaningful error message;
          return 0;

      return 1;

$self->display_value ($key);

Returns the same as $self->{$key}, except when $self->{$key} is undef.

When $self->{$key} is undef, the string "(undef") is sent back rather than the value itself.

This is used by the menu as a way to display the information 'undef' to the user.


When the object does not validate, this method displays a message error and waits for a keystroke before re-displaying the main menu.

$class->new (%args);

Constructor - Creates a new MKDoc::Setup object.


Method which initializes the state of the object to 'display_menu' and starts the FSM mechanism.


Displays the main user menu with a list of options to choose from.


When the user chooses to set a given value to another value, this method is invoked. It basically prompts the user for the new value.


When the user chooses to delete some value, this method is invoked. It basically prompts the user for which value to delete / undefine.

$self->message_prompt ($message, $default_value);

Prompts the user for a value by displaying $message. If the user just hits 'enter', $default_value is returned instead.


Cancels the installation process, exits to system.


Invokes $self->validate() first. If there are errors, invokes $self->display_error().

Otherwise if everything's OK invokes $self->install() which performs the installation.


Reads one line from <STDIN>, chomps it, and returns it.


Copyright 2003 - MKDoc Holdings Ltd.

Author: Jean-Michel Hiver

This module is free software and is distributed under the same license as Perl itself. Use it at your own risk.


  L<Petal> TAL for perl

Help us open-source MKDoc. Join the mkdoc-modules mailing list: