| 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 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Module::Load; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | 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 passwd object. 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 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=21.2
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 4 | my $proto = shift; | |||||||||||||||||||||||||||
| 31 | 4 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 32 | 4 | my %args = @_; | |||||||||||||||||||||||||||
| 33 | 4 | my $self = { debug => $_debug, | |||||||||||||||||||||||||||
| 34 | %args | ||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 4 | ▶ | if (!defined($self->{file}) || ! -r $self->{file} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"file"} and -r $self->{"file"}
MC/DC50%1/2
defined $self->{"file"} and -r $self->{"file"}
defined $self->{"file"}
-r $self->{"file"}
Truth table66%2/3
A and B
A= defined $self->{"file"}B= -r $self->{"file"}
| |||||||||||||||||||||||||||||
| 38 | 1 | ▶ | $self->{file} ||= '<undefined>'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"file"} ||= "<undefined>"
MC/DC0%0/1
$self->{"file"} ||= "<undefined>"
$self->{"file"}
Truth table50%1/2
A
A= $self->{"file"}
| |||||||||||||||||||||||||||||
| 39 | 1 | croak "$class: Can't read file $self->{file}"; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 3 | $self->{keepass} = eval { | |||||||||||||||||||||||||||
| 44 | 3 | load File::KeePass; | |||||||||||||||||||||||||||
| 45 | 3 | return File::KeePass->new(); | |||||||||||||||||||||||||||
| 46 | }; | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 3 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | croak $@; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # load failure on bad password or bad filename | ||||||||||||||||||||||||||||
| 53 | 3 | my $k = eval { $self->{keepass}->load_db($self->{file}, $self->{passwd}); }; | |||||||||||||||||||||||||||
| 54 | 3 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 3 | 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 | 0 | ▶ | sub passwd { | ||||||||||||||||||||||||||
|
Subroutine
passwd: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 0 | 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 | ▶ | return !defined($e->{'password'}) ? '' : $e->{'password'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 2 | 1; | |||||||||||||||||||||||||||