<% include( '/elements/header.html', 'Developer Documentation' ) %> <& /elements/menubar.html, 'Freeside Perl Modules' => $fsurl.'docs/library/FS.html', 'Complete Index' => $fsurl.'docs/library/index.html', &>

Devscripts::Config

NAME

Devscripts::Config - devscripts Perl scripts configuration object

SYNOPSIS

  # Configuration module
  package Devscripts::My::Config;
  use Moo;
  extends 'Devscripts::Config';
  
  use constant keys => [
    [ 'text1=s', 'MY_TEXT', qr/^\S/, 'Default_text' ],
    # ...
  ];
  
  has text1 => ( is => 'rw' );
  
  # Main package or script
  package Devscripts::My;
  
  use Moo;
  my $config = Devscripts::My::Config->new->parse;
  1;

DESCRIPTION

Devscripts Perl scripts configuration object. It can scan configuration files (/etc/devscripts.conf and ~/.devscripts) and command line arguments.

A devscripts configuration package has just to declare:

keys constant: array ref (see below)
rules constant: hash ref (see below)

KEYS

Each element of keys constant is an array containing four elements which can be undefined:

the string to give to Getopt::Long
the name of the devscripts.conf key
the rule to check value. It can be:
regexp ref: will be applied to the value. If it fails against the devscripts.conf value, Devscripts::Config will warn. If it fails against the command line argument, Devscripts::Config will die.
sub ref: function will be called with 2 arguments: current config object and proposed value. Function must return a true value to continue or 0 to stop. This is not simply a "check" function: Devscripts::Config will not do anything else than read the result to continue with next argument or stop.
"bool" string: means that value is a boolean. devscripts.conf value can be either "yes", 1, "no", 0.
the default value

RULES

It is possible to declare some additional rules to check the logic between options:

  use constant rules => [
    sub {
      my($self)=@_;
      # OK
      return 1 if( $self->a < $self->b );
      # OK with warning
      return ( 1, 'a should be lower than b ) if( $self->a > $self->b );
      # NOK with an error
      return ( 0, 'a must not be equal to b !' );
    },
    sub {
      my($self)=@_;
      # ...
      return 1;
    },
  ];

METHODS

new()

Constructor

parse()

Launches parse_conf_files(), parse_command_line() and check_rules

parse_conf_files()

Reads values in /etc/devscripts.conf and ~/.devscripts

parse_command_line()

Parse command line arguments

SEE ALSO

devscripts

AUTHOR

Xavier Guimard <yadd@debian.org>

COPYRIGHT AND LICENSE

Copyright 2018 by Xavier Guimard <yadd@debian.org>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

<% include ('/elements/footer.html' ) %>