File Coverage

lib/App/Tel/Passwd/KeePass.pm
Criterion Covered Total %
statement 12 36 33.3
branch 0 8 0.0
condition 0 8 0.0
subroutine 4 6 66.6
pod 2 2 100.0
total 18 60 30.0


line stmt bran cond sub pod time code
1             package App::Tel::Passwd::KeePass;
2              
3             =head1 name
4              
5             App::Tel::Passwd::KeePass - Passwd module for KeePass
6              
7             =cut
8              
9 2     2   2218 use strict;
  2         11  
  2         47  
10 2     2   8 use warnings;
  2         4  
  2         47  
11 2     2   8 use Module::Load;
  2         2  
  2         12  
12 2     2   97 use Carp;
  2         3  
  2         678  
13              
14             our $_debug = 0;
15              
16             =head1 METHODS
17              
18             =head2 new
19              
20             my $passwd = App::Tel::Passwd::KeePass->new( file => $filename, passwd => $password );
21              
22             Initializes a new passwdobject. This will return a Passwd::KeePass Object if the module
23             exists and return undef if it doesn't.
24              
25             Requires filename and password for the file.
26              
27             =cut
28              
29             sub new {
30 0     0 1   my $proto = shift;
31 0   0       my $class = ref($proto) || $proto;
32 0           my %args = @_;
33 0           my $self = { debug => $_debug,
34             %args
35             };
36              
37 0 0 0       if (!defined($self->{file}) || ! -r $self->{file} ) {
38 0   0       $self->{file} ||= '<undefined>';
39 0           croak "$class: Can't read file $self->{file}";
40             }
41              
42              
43 0           $self->{keepass} = eval {
44 0           load File::KeePass;
45 0           return File::KeePass->new();
46             };
47              
48 0 0         if ($@) {
49 0           croak $@;
50             }
51              
52             # load failure on bad password or bad filename
53 0           my $k = eval { $self->{keepass}->load_db($self->{file}, $self->{passwd}); };
  0            
54 0 0         if ($@) {
55 0           croak $@;
56             }
57 0           $k->unlock;
58 0           $self->{k} = $k;
59              
60 0           return bless( $self, $class );
61             }
62              
63             =head2 passwd
64              
65             $passwd->passwd($entry);
66              
67             This takes the entry for a key database and returns the password. It returns
68             a blank string if the entry wasn't found.
69              
70             =cut
71              
72             sub passwd {
73 0     0 1   my $self = shift;
74 0           my $k = $self->{k};
75 0           my $entry = shift;
76              
77 0           my $e = $k->find_entry({title => $entry});
78 0 0         return !defined($e->{'password'}) ? '' : $e->{'password'};
79             }
80              
81             1;