home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / perl5 / Debconf / DbDriver / Pipe.pm < prev    next >
Encoding:
Perl POD Document  |  2006-07-24  |  1.7 KB  |  91 lines

  1. #!/usr/bin/perl -w
  2. # This file was preprocessed, do not edit!
  3.  
  4.  
  5. package Debconf::DbDriver::Pipe;
  6. use strict;
  7. use Debconf::Log qw(:all);
  8. use base 'Debconf::DbDriver::Cache';
  9.  
  10.  
  11. use fields qw(infd outfd format);
  12.  
  13.  
  14. sub init {
  15.     my $this=shift;
  16.  
  17.     $this->{format} = "822" unless exists $this->{format};
  18.  
  19.     $this->error("No format specified") unless $this->{format};
  20.     eval "use Debconf::Format::$this->{format}";
  21.     if ($@) {
  22.         $this->error("Error setting up format object $this->{format}: $@");
  23.     }
  24.     $this->{format}="Debconf::Format::$this->{format}"->new;
  25.     if (not ref $this->{format}) {
  26.         $this->error("Unable to make format object");
  27.     }
  28.  
  29.     my $fh;
  30.     if (defined $this->{infd}) {
  31.         if ($this->{infd} ne 'none') {
  32.             open ($fh, "<&=$this->{infd}") or
  33.                 $this->error("could not open file descriptor #$this->{infd}: $!");
  34.         }
  35.     }
  36.     else {    
  37.         open ($fh, '-');
  38.     }
  39.  
  40.     $this->SUPER::init(@_);
  41.  
  42.     debug "db $this->{name}" => "loading database";
  43.  
  44.     if (defined $fh) {
  45.         while (! eof $fh) {
  46.             my ($item, $cache)=$this->{format}->read($fh);
  47.             $this->{cache}->{$item}=$cache;
  48.         }
  49.         close $fh;
  50.     }
  51. }
  52.  
  53.  
  54. sub shutdown {
  55.     my $this=shift;
  56.  
  57.     return if $this->{readonly};
  58.  
  59.     my $fh;
  60.     if (defined $this->{outfd}) {
  61.         if ($this->{outfd} ne 'none') {
  62.             open ($fh, ">&=$this->{outfd}") or
  63.                 $this->error("could not open file descriptor #$this->{outfd}: $!");
  64.         }
  65.     }
  66.     else {
  67.         open ($fh, '>-');
  68.     }
  69.     
  70.     if (defined $fh) {
  71.         $this->{format}->beginfile;
  72.         foreach my $item (sort keys %{$this->{cache}}) {
  73.             next unless defined $this->{cache}->{$item}; # skip deleted
  74.             $this->{format}->write($fh, $this->{cache}->{$item}, $item)
  75.                 or $this->error("could not write to pipe: $!");
  76.         }
  77.         $this->{format}->endfile;
  78.         close $fh or $this->error("could not close pipe: $!");
  79.     }
  80.  
  81.     return 1;
  82. }
  83.  
  84.  
  85. sub load {
  86.     return undef;
  87. }
  88.  
  89.  
  90. 1
  91.