home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl_ste.zip / os2 / Net / Config.pm
Text File  |  1997-11-26  |  2KB  |  87 lines

  1. package Net::Config;
  2.  
  3. require Exporter;
  4. use vars qw(@ISA @EXPORT %NetConfig);
  5. use strict;
  6.  
  7. @EXPORT = qw(%NetConfig);
  8. @ISA = qw(Exporter);
  9.  
  10. sub set
  11. {
  12.  my $pkg = shift if @_ % 2;
  13.  my %cfg = @_;
  14.  
  15.  return unless @_;
  16.  
  17.  # Only require these modules if we need to
  18.  require Data::Dumper;
  19.  require IO::File;
  20.  require Carp;
  21.  require File::Copy;
  22.     
  23.  my $mod = $INC{'Net/Config.pm'} or
  24.     Carp::croak("Can't find myself");
  25.  
  26.  my $bak = $mod . "~";
  27.  
  28.  print "Updating $mod...\n";
  29.  
  30.  File::Copy::copy($mod,$bak) or
  31.     Carp::croak("Cannot create backup file $bak: $!");
  32.  
  33.  print "...backup at $bak\n";
  34.  
  35.  my $old = new IO::File $bak,"r" or
  36.     Carp::croak("Can't open $bak: $!");
  37.  
  38.  my $new = new IO::File $mod,"w" or
  39.     Carp::croak("Can't open $mod: $!");
  40.  
  41.  # If we fail below, then we must restore from backup
  42.  local $SIG{'__DIE__'} = sub {
  43.         print "Restoring $mod from backup!!\n";
  44.         unlink $mod;
  45.         rename $bak, $mod;
  46.         print "Done.\n";
  47.         exit 1;
  48.        };
  49.  
  50.  %NetConfig = (%NetConfig, %cfg);
  51.  
  52.  while (<$old>)
  53.   {
  54.    last if /^%NetConfig/;
  55.    $new->print($_);
  56.   }
  57.  
  58.  $new->print ( Data::Dumper->Dump([\%NetConfig],['*NetConfig']) );
  59.  
  60.  $new->print("\n1;\n");
  61.  
  62.  close $old;
  63.  close $new;
  64. }
  65.  
  66. # WARNING  WARNING  WARNING  WARNING  WARNING  WARNING  WARNING
  67. # WARNING  WARNING  WARNING  WARNING  WARNING  WARNING  WARNING
  68. #
  69. # Below this line is auto-generated, *ANY* changes will be lost
  70. %NetConfig = (
  71.     test_hosts => '1',
  72.     nntp_hosts => ['agate.berkeley.edu'],
  73.     snpp_hosts => ['agate.berkeley.edu'],
  74.     pop3_hosts => ['agate.berkeley.edu'],
  75.     ftp_ext_passive => '0',
  76.     smtp_hosts => ['agate.berkeley.edu'],
  77.     ftp_testhost => 'ftp.math.ohio-state.edu',
  78.     inet_domain => 'tusik.hip.berkeley.edu',
  79.     ph_hosts => ['agate.berkeley.edu'],
  80.     test_exist => '1',
  81.     daytime_hosts => ['agate.berkeley.edu'],
  82.     ftp_int_passive => '0',
  83.     ftp_firewall => undef,
  84.     time_hosts => ['agate.berkeley.edu'],
  85. );
  86. 1;
  87.