summaryrefslogtreecommitdiff
path: root/lib/SlackBuild/Config.pm
blob: 2d9fbb2e7e6ab5da4e771e944cad2e79579c1754 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package SlackBuild::Config;
use strict;
use warnings;
use parent 'Config::Parser::Ini';
use File::Spec;
use feature 'state';

sub new {
    my $class = shift;
    state $level;

    $level++;
    my $self = $class->SUPER::new(@_);

    if ($level == 1) {
	my $rootdir = $self->get(qw(dir root));
	foreach my $kw ($self->names_of('dir')) {
	    next if $kw eq 'root';
	    my $subdir = $self->get('dir', $kw);
	    unless (File::Spec->file_name_is_absolute($subdir)) {
		$self->set('dir', $kw, File::Spec->catfile($rootdir, $subdir));
	    }
	}
    }
    
    $level--;
    return $self;
}

sub check_dir {
    my ($self, $valref, $prev_value, $locus) = @_;
    my $val = $$valref;
    unless (-d $val) {
	$self->error("$val: directory does not exist", locus => $locus);
	return 0;
    }
    return 1;
}

1;
__DATA__
[core]
    image = STRING :mandatory
    verbose = NUMBER :mandatory 0
    logging = STRING :mandatory /etc/slackbuilder/logging.conf
[dir]
    root = STRING :check=check_dir :mandatory /srv/slackbuild
    tmp = STRING :mandatory tmp
    log = STRING :mandatory log
    pkg = STRING :mandatory pkg
    spool = STRING :mandatory spool

    

Return to:

Send suggestions and report system problems to the System administrator.