| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
Debconf::DbDriver::Debug - debug db requests |
| 6 |
|
| 7 |
=cut |
| 8 |
|
| 9 |
package Debconf::DbDriver::Debug; |
| 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 useful only for debugging other drivers. It makes each |
| 18 |
method call output rather verbose debugging output. |
| 19 |
|
| 20 |
=cut |
| 21 |
|
| 22 |
=head1 FIELDS |
| 23 |
|
| 24 |
=over 4 |
| 25 |
|
| 26 |
=item db |
| 27 |
|
| 28 |
All requests are passed to this database, with logging. |
| 29 |
|
| 30 |
=back |
| 31 |
|
| 32 |
=cut |
| 33 |
|
| 34 |
use fields qw(db); |
| 35 |
|
| 36 |
=head1 METHODS |
| 37 |
|
| 38 |
=head2 init |
| 39 |
|
| 40 |
Validate the db field. |
| 41 |
|
| 42 |
=cut |
| 43 |
|
| 44 |
sub init { |
| 45 |
my $this=shift; |
| 46 |
|
| 47 |
# Handle value from config file. |
| 48 |
if (! ref $this->{db}) { |
| 49 |
$this->{db}=$this->driver($this->{db}); |
| 50 |
unless (defined $this->{db}) { |
| 51 |
$this->error("could not find db"); |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
# Ignore. |
| 57 |
sub DESTROY {} |
| 58 |
|
| 59 |
# All other methods just pass on to db with logging. |
| 60 |
sub AUTOLOAD { |
| 61 |
my $this=shift; |
| 62 |
(my $command = our $AUTOLOAD) =~ s/.*://; |
| 63 |
|
| 64 |
debug "db $this->{name}" => "running $command(".join(",", map { "'$_'" } @_).") .."; |
| 65 |
if (wantarray) { |
| 66 |
my @ret=$this->{db}->$command(@_); |
| 67 |
debug "db $this->{name}" => "$command returned (".join(", ", @ret).")"; |
| 68 |
return @ret if @ret; |
| 69 |
} |
| 70 |
else { |
| 71 |
my $ret=$this->{db}->$command(@_); |
| 72 |
if (defined $ret) { |
| 73 |
debug "db $this->{name}" => "$command returned \'$ret\'"; |
| 74 |
return $ret; |
| 75 |
} |
| 76 |
else { |
| 77 |
debug "db $this->{name}" => "$command returned undef"; |
| 78 |
} |
| 79 |
} |
| 80 |
return; # failure |
| 81 |
} |
| 82 |
|
| 83 |
=head1 AUTHOR |
| 84 |
|
| 85 |
Joey Hess <[email protected]> |
| 86 |
|
| 87 |
=cut |
| 88 |
|
| 89 |
1 |