| 1 | package App::Tel::Passwd::PWSafe; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 name | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | App::Tel::Passwd::PWSafe - module for accessing PWSafe objects | ||||||||||||||||||||||||||||
| 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 Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Module::Load; | ||||||||||||||||||||||||||
|
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::PWSafe->new( file => $filename, passwd => $password ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | Initializes a new passwd object. This will return a Passwd::PWSafe Object if the module | ||||||||||||||||||||||||||||
| 23 | exists and return undef if it doesn't. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 2 | my $proto = shift; | |||||||||||||||||||||||||||
| 29 | 2 | ▶ | 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
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 2 | my %args = @_; | |||||||||||||||||||||||||||
| 32 | 2 | my $self = { debug => $_debug, | |||||||||||||||||||||||||||
| 33 | %args | ||||||||||||||||||||||||||||
| 34 | }; | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # unknown or non-existant file returns undef. Crypt::PWSafe3 will | ||||||||||||||||||||||||||||
| 37 | # otherwise attempt to generate a new safe with this filename. | ||||||||||||||||||||||||||||
| 38 | 2 | ▶ | if (!defined($self->{file}) || ! -r $self->{file} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"file"} and -r $self->{"file"}
MC/DC0%0/2
defined $self->{"file"} and -r $self->{"file"}
defined $self->{"file"}
-r $self->{"file"}
Truth table33%1/3
A and B
A= defined $self->{"file"}B= -r $self->{"file"}
| |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $self->{file} ||= '<undefined>'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"file"} ||= "<undefined>"
MC/DC0%0/1
$self->{"file"} ||= "<undefined>"
$self->{"file"}
Truth table0%0/2
A
A= $self->{"file"}
| |||||||||||||||||||||||||||||
| 40 | 0 | croak "$class: Can't read file " . $self->{file}; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | $self->{vault} = eval { | |||||||||||||||||||||||||||
| 44 | 2 | load Crypt::PWSafe3; | |||||||||||||||||||||||||||
| 45 | 2 | return Crypt::PWSafe3->new( file => $self->{file}, password => $self->{passwd} ); | |||||||||||||||||||||||||||
| 46 | }; | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 2 | croak $@; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 0 | return bless( $self, $class ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =head2 passwd | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | $passwd->passwd($entry); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | This takes the entry for a database key and returns a password. It returns a | ||||||||||||||||||||||||||||
| 59 | blank string if the entry wasn't found. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =cut | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub passwd { | ||||||||||||||||||||||||||
|
Subroutine
passwd: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 0 | my ($self, $entry) = @_; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | foreach my $record ($self->{vault}->getrecords()) { | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($record->title eq $entry) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | return $record->passwd; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | 1; | |||||||||||||||||||||||||||