home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Editores / Perl5 / perl / lib / site / Net / Config.pm < prev    next >
Encoding:
Perl POD Document  |  1997-08-10  |  1.8 KB  |  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 => '0',
  72.     nntp_hosts => ['news'],
  73.     snpp_hosts => [],
  74.     pop3_hosts => [],
  75.     ftp_ext_passive => '0',
  76.     smtp_hosts => ['mailhost'],
  77.     inet_domain => 'nowhere.com',
  78.     ph_hosts => ['dirserv'],
  79.     test_exist => '0',
  80.     daytime_hosts => [],
  81.     ftp_int_passive => '0',
  82.     ftp_firewall => undef,
  83.     time_hosts => [],
  84.  
  85. );
  86. 1;
  87.