lib/App/Tel/Passwd/PWSafe.pm

filter: Statementstmt 77.4% 24 / 31 Branchbran 33.3% 2 / 6 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 83.3% 5 / 6 Podpod 100% 2 / 2 totaltotal 60.3% 35 / 58 CC 8 SCAR 19.8
CC
8
Cov
62%
passwd
12.0
new
9.1
BEGIN
1.0
CRAP 7.3
« lib/App/Tel/HostRange.pm ↑ Summary lib/App/Tel/Merge.pm »
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
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless (defined $self->{"file"} and -r $self->{"file"}) 0 2 2
Condition33%1/3
defined $self->{"file"} and -r $self->{"file"}
!ll&&!rl&&r
002
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"}
ABresult
0X0
100
111
39 0 ▶ $self->{file} ||= '<undefined>';
Condition0%0/2
$self->{"file"} ||= "<undefined>"
l!l
00
MC/DC0%0/1
$self->{"file"} ||= "<undefined>"
$self->{"file"}
Truth table0%0/2
A
A= $self->{"file"}
Aresult
11
00
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
BranchTrueFalseTotal
if ($@) 2 0 2
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
BranchTrueFalseTotal
if ($record->title eq $entry) 0 0 0
69 0 return $record->passwd;
70 }
71 }
72 }
73  
74 2 1;
« lib/App/Tel/HostRange.pm ↑ Summary lib/App/Tel/Merge.pm »