t/lib/Aux.pm
branchfoerste
changeset 152 1ed33114d87f
parent 148 b0fd381a4b53
parent 150 3db363880766
child 153 af27be0a326b
equal deleted inserted replaced
149:44183c6b78b6 152:1ed33114d87f
     4 use warnings;
     4 use warnings;
     5 
     5 
     6 use File::Temp;
     6 use File::Temp;
     7 use base "Exporter";
     7 use base "Exporter";
     8 
     8 
     9 our $VERSION = 0.0;
     9 our $VERSION   = 0.0;
    10 our @EXPORT_OK = qw(make_config);
    10 our @EXPORT_OK = qw(make_config);
    11 
    11 
    12 sub make_config {
    12 sub make_config($) {
    13 
    13 
    14     my ($c) = @_;
    14     my ($c) = @_;
    15 
    15 
    16     my $f = File::Temp->new or die "Config file creation failed\n";
    16     my $f = File::Temp->new or die "Config file creation failed\n";
    17 
    17 
    18     if (ref $c eq 'HASH') {
    18     if ( ref $c eq 'HASH' ) {
    19         map { print $f "$_ = $c->{$_}\n" } keys %{$c};
    19         map { print $f "$_ = $c->{$_}\n" } keys %{$c};
    20     } elsif (defined $c) {
    20     }
       
    21     elsif ( defined $c ) {
       
    22 
    21         # assuming just a string
    23         # assuming just a string
    22         print $f $c;
    24         print $f $c;
    23     } else {
    25     }
       
    26     else {
       
    27 
    24         # make a default configuration
    28         # make a default configuration
    25         $_ = File::Temp::tempdir CLEANUP => 1 or die "Can't make temporary directory" for my ($bd, $md, $cd);
    29         $_ = File::Temp::tempdir CLEANUP => 1 or die "Can't make temporary directory" for my ($bd, $md, $cd);
    26 
    30 
    27         print $f <<__EOF;
    31         print $f <<__EOF;
    28 bind_dir = $bd
    32 bind_dir = $bd