$value = $default;
} elsif ( -f $path ) {
$value = read_file $path;
+ chomp $value;
} else {
warn "# $name missing $path\n" if $debug;
}
my $ip = shift;
my $path = ip_path $ip || return;
my $conf;
- foreach my $file ( glob("$path/*") ) {
+ foreach my $file ( glob("$path/*"), glob("$path/*/*") ) {
my $name = $file;
- $name =~ s{^.+/([^/]+)$}{$1};
- $conf->{ $name } = read_file $file;
+ $name =~ s{^$path/+}{} || die "can't remove $path from $name";
+ $conf->{ $name } = read_file $file if -f $file;
}
return $conf;
}
sub remove {
my $ip = shift;
- unlink $_ foreach grep { -e $_ } ( glob "$server::conf/ip/$ip/*" );
if ( my $mac = mac_from_ip $ip ) {
unlink "$server::conf/mac/$mac";
}
use strict;
use autodie;
-use Test::More tests => 20;
+use Test::More tests => 22;
use Data::Dump qw/dump/;
use English;
ok( client::conf( $host => 'test' => 'value' ), 'conf set' );
cmp_ok( client::conf( $host => 'test' ), 'eq', 'value', 'value' );
+ok( client::conf( $host => 'dir/test' => 'in_dir' ), 'conf test/dir' );
+cmp_ok( client::conf( $host => 'dir/test' ), 'eq', 'in_dir', 'value' );
+
ok( ! client::conf( $host => 'non-existing' ), 'conf non-existing' );
ok( client::remove( $host ), "remove $host" );