t/lib/Aux.pm
changeset 150 3db363880766
parent 144 be90bcd14ae1
child 152 1ed33114d87f
equal deleted inserted replaced
146:a3860111db49 150:3db363880766
     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         my ($bd, $md, $cd);
    29         my ( $bd, $md, $cd );
    26         for ($bd, $md, $cd) {
    30         for ( $bd, $md, $cd ) {
    27             my $d = File::Temp::tempdir CLEANUP => 1 or die "Can't make temporary directory";
    31             my $d = File::Temp::tempdir CLEANUP => 1
       
    32               or die "Can't make temporary directory";
    28             $_ = $d->filename;
    33             $_ = $d->filename;
    29         }
    34         }
    30 
    35 
    31         print $f <<__EOF;
    36         print $f <<__EOF;
    32 bind_dir = $bd
    37 bind_dir = $bd