<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
# This file was preprocessed, do not edit!


package Debconf::DbDriver::Cache;
use strict;
use Debconf::Log qw{:all};
use base 'Debconf::DbDriver';


use fields qw(cache dirty);


sub iterator {
	my $this=shift;
	my $subiterator=shift;

	my @items=keys %{$this-&gt;{cache}};
	my $iterator=Debconf::Iterator-&gt;new(callback =&gt; sub {
		while (my $item = pop @items) {
			next unless defined $this-&gt;{cache}-&gt;{$item};
			return $item;
		}
		return unless $subiterator;
		my $ret;
		do {
			$ret=$subiterator-&gt;iterate;
		} while defined $ret and exists $this-&gt;{cache}-&gt;{$ret};
		return $ret;
	});
	return $iterator;
}


sub exists {
	my $this=shift;
	my $item=shift;

	return $this-&gt;{cache}-&gt;{$item}
		if exists $this-&gt;{cache}-&gt;{$item};
	return 0;
}


sub init {
	my $this=shift;

	$this-&gt;{cache} = {} unless exists $this-&gt;{cache};
}


sub cacheadd {
	my $this=shift;
	my $item=shift;
	my $entry=shift;

	return if exists $this-&gt;{cache}-&gt;{$item};

	$this-&gt;{cache}-&gt;{$item}=$entry;
	$this-&gt;{dirty}-&gt;{$item}=0;
}


sub cachedata {
	my $this=shift;
	my $item=shift;
	
	return $this-&gt;{cache}-&gt;{$item};
}


sub cached {
	my $this=shift;
	my $item=shift;

	unless (exists $this-&gt;{cache}-&gt;{$item}) {
		debug "db $this-&gt;{name}" =&gt; "cache miss on $item";
		$this-&gt;load($item);
	}
	return $this-&gt;{cache}-&gt;{$item};
}


sub shutdown {
	my $this=shift;
	
	return if $this-&gt;{readonly};

	my $ret=1;
	foreach my $item (keys %{$this-&gt;{cache}}) {
		if (not defined $this-&gt;{cache}-&gt;{$item}) {
			$ret=undef unless defined $this-&gt;remove($item);
			delete $this-&gt;{cache}-&gt;{$item};
		}
		elsif ($this-&gt;{dirty}-&gt;{$item}) {
			$ret=undef unless defined $this-&gt;save($item, $this-&gt;{cache}-&gt;{$item});
			$this-&gt;{dirty}-&gt;{$item}=0;
		}
	}
	return $ret;
}


sub addowner {
	my $this=shift;
	my $item=shift;
	my $owner=shift;
	my $type=shift;

	return if $this-&gt;{readonly};
	$this-&gt;cached($item);

	if (! defined $this-&gt;{cache}-&gt;{$item}) {
		return if ! $this-&gt;accept($item, $type);
		debug "db $this-&gt;{name}" =&gt; "creating in-cache $item";
		$this-&gt;{cache}-&gt;{$item}={
			owners =&gt; {},
			fields =&gt; {},
			variables =&gt; {},
			flags =&gt; {},
		}
	}

	if (! exists $this-&gt;{cache}-&gt;{$item}-&gt;{owners}-&gt;{$owner}) {
		$this-&gt;{cache}-&gt;{$item}-&gt;{owners}-&gt;{$owner}=1;
		$this-&gt;{dirty}-&gt;{$item}=1;
	}
	return $owner;
}


sub removeowner {
	my $this=shift;
	my $item=shift;
	my $owner=shift;

	return if $this-&gt;{readonly};
	return unless $this-&gt;cached($item);

	if (exists $this-&gt;{cache}-&gt;{$item}-&gt;{owners}-&gt;{$owner}) {
		delete $this-&gt;{cache}-&gt;{$item}-&gt;{owners}-&gt;{$owner};
		$this-&gt;{dirty}-&gt;{$item}=1;
	}
	unless (keys %{$this-&gt;{cache}-&gt;{$item}-&gt;{owners}}) {
		$this-&gt;{cache}-&gt;{$item}=undef;
		$this-&gt;{dirty}-&gt;{$item}=1;
	}
	return $owner;
}


sub owners {
	my $this=shift;
	my $item=shift;

	return unless $this-&gt;cached($item);
	return keys %{$this-&gt;{cache}-&gt;{$item}-&gt;{owners}};
}


sub getfield {
	my $this=shift;
	my $item=shift;
	my $field=shift;
	
	return unless $this-&gt;cached($item);
	return $this-&gt;{cache}-&gt;{$item}-&gt;{fields}-&gt;{$field};
}


sub setfield {
	my $this=shift;
	my $item=shift;
	my $field=shift;
	my $value=shift;

	return if $this-&gt;{readonly};
	return unless $this-&gt;cached($item);
	$this-&gt;{dirty}-&gt;{$item}=1;
	return $this-&gt;{cache}-&gt;{$item}-&gt;{fields}-&gt;{$field} = $value;	
}


sub removefield {
	my $this=shift;
	my $item=shift;
	my $field=shift;

	return if $this-&gt;{readonly};
	return unless $this-&gt;cached($item);
	$this-&gt;{dirty}-&gt;{$item}=1;
	return delete $this-&gt;{cache}-&gt;{$item}-&gt;{fields}-&gt;{$field};
}


sub fields {
	my $this=shift;
	my $item=shift;
	
	return unless $this-&gt;cached($item);
	return keys %{$this-&gt;{cache}-&gt;{$item}-&gt;{fields}};
}


sub getflag {
	my $this=shift;
	my $item=shift;
	my $flag=shift;
	
	return unless $this-&gt;cached($item);
	return $this-&gt;{cache}-&gt;{$item}-&gt;{flags}-&gt;{$flag}
		if exists $this-&gt;{cache}-&gt;{$item}-&gt;{flags}-&gt;{$flag};
	return 'false';
}


sub setflag {
	my $this=shift;
	my $item=shift;
	my $flag=shift;
	my $value=shift;

	return if $this-&gt;{readonly};
	return unless $this-&gt;cached($item);
	$this-&gt;{dirty}-&gt;{$item}=1;
	return $this-&gt;{cache}-&gt;{$item}-&gt;{flags}-&gt;{$flag} = $value;
}


sub flags {
	my $this=shift;
	my $item=shift;

	return unless $this-&gt;cached($item);
	return keys %{$this-&gt;{cache}-&gt;{$item}-&gt;{flags}};
}


sub getvariable {
	my $this=shift;
	my $item=shift;
	my $variable=shift;

	return unless $this-&gt;cached($item);
	return $this-&gt;{cache}-&gt;{$item}-&gt;{variables}-&gt;{$variable};
}


sub setvariable {
	my $this=shift;
	my $item=shift;
	my $variable=shift;
	my $value=shift;

	return if $this-&gt;{readonly};
	return unless $this-&gt;cached($item);
	$this-&gt;{dirty}-&gt;{$item}=1;
	return $this-&gt;{cache}-&gt;{$item}-&gt;{variables}-&gt;{$variable} = $value;
}


sub variables {
	my $this=shift;
	my $item=shift;

	return unless $this-&gt;cached($item);
	return keys %{$this-&gt;{cache}-&gt;{$item}-&gt;{variables}};
}


1
</pre></body></html>