Debian Codegraph @

Debconf/DbDriver/Copy.pm

raw
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 Debconf::DbDriver::Copy - class that can make copies
6
7 =cut
8
9 package Debconf::DbDriver::Copy;
10 use warnings;
11 use strict;
12 use Debconf::Log qw{:all};
13 use base 'Debconf::DbDriver';
14
15 =head1 DESCRIPTION
16
17 This driver is not useful on its own, it is just the base of other classes
18 that need to be able to copy entire database items around.
19
20 =head1 METHODS
21
22 =item copy(item, src, dest)
23
24 Copies the given item from the source database to the destination database.
25 The item is assumed to not already exist in dest.
26
27 =cut
28
29 sub copy {
30 my $this=shift;
31 my $item=shift;
32 my $src=shift;
33 my $dest=shift;
34
35 debug "db $this->{name}" => "copying $item from $src->{name} to $dest->{name}";
36
37 # First copy the owners, which makes sure $dest has the item.
38 my @owners=$src->owners($item);
39 if (! @owners) {
40 @owners=("unknown");
41 }
42 foreach my $owner (@owners) {
43 my $template = Debconf::Template->get($src->getfield($item, 'template'));
44 my $type="";
45 $type = $template->type if $template;
46 $dest->addowner($item, $owner, $type);
47 }
48 # Now the fields.
49 foreach my $field ($src->fields($item)) {
50 $dest->setfield($item, $field, $src->getfield($item, $field));
51 }
52 # Now the flags.
53 foreach my $flag ($src->flags($item)) {
54 $dest->setflag($item, $flag, $src->getflag($item, $flag));
55 }
56 # And finally the variables.
57 foreach my $var ($src->variables($item)) {
58 $dest->setvariable($item, $var, $src->getvariable($item, $var));
59 }
60 }
61
62 =head1 AUTHOR
63
64 Joey Hess <[email protected]>
65
66 =cut
67
68 1