File: Copy.pm

package info (click to toggle)
debconf 1.5.11etch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 3,364 kB
  • ctags: 714
  • sloc: perl: 8,347; sh: 286; makefile: 174; python: 117
file content (67 lines) | stat: -rw-r--r-- 1,491 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl -w

=head1 NAME

Debconf::DbDriver::Copy - class that can make copies

=cut

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

=head1 DESCRIPTION

This driver is not useful on its own, it is just the base of other classes
that need to be able to copy entire database items around.

=head1 METHODS

=item copy(item, src, dest)

Copies the given item from the source database to the destination database.
The item is assumed to not already exist in dest.

=cut

sub copy {
	my $this=shift;
	my $item=shift;
	my $src=shift;
	my $dest=shift;
	
	debug "db $this->{name}" => "copying $item from $src->{name} to $dest->{name}";
	
	# First copy the owners, which makes sure $dest has the item.
	my @owners=$src->owners($item);
	if (! @owners) {
		@owners=("unknown");
	}
	foreach my $owner (@owners) {
		my $template = Debconf::Template->get($src->getfield($item, 'template'));
		my $type="";
		$type = $template->type if $template;
		$dest->addowner($item, $owner, $type);
	}
	# Now the fields.
	foreach my $field ($src->fields($item)) {
		$dest->setfield($item, $field, $src->getfield($item, $field));
	}
	# Now the flags.
	foreach my $flag ($src->flags($item)) {
		$dest->setflag($item, $flag, $src->getflag($item, $flag));
	}
	# And finally the variables.
	foreach my $var ($src->variables($item)) {
		$dest->setvariable($item, $var, $src->getvariable($item, $var));
	}
}

=head1 AUTHOR

Joey Hess <joeyh@debian.org>

=cut

1