File Coverage

lib/App/Tel/Passwd/PWSafe.pm
Criterion Covered Total %
statement 12 30 40.0
branch 0 6 0.0
condition 0 8 0.0
subroutine 4 6 66.6
pod 2 2 100.0
total 18 52 34.6


line stmt bran cond sub pod time code
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     2   1784 use strict;
  2         17  
  2         57  
10 2     2   10 use warnings;
  2         4  
  2         57  
11 2     2   10 use Carp;
  2         5  
  2         136  
12 2     2   10 use Module::Load;
  2         4  
  2         13  
13              
14             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             sub new {
28 0     0 1   my $proto = shift;
29 0   0       my $class = ref($proto) || $proto;
30              
31 0           my %args = @_;
32 0           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 0 0 0       if (!defined($self->{file}) || ! -r $self->{file} ) {
39 0   0       $self->{file} ||= '<undefined>';
40 0           croak "$class: Can't read file " . $self->{file};
41             }
42              
43 0           $self->{vault} = eval {
44 0           load Crypt::PWSafe3;
45 0           return Crypt::PWSafe3->new( file => $self->{file}, password => $self->{passwd} );
46             };
47              
48 0 0         if ($@) {
49 0           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             sub passwd {
65 0     0 1   my $self = shift;
66 0           my $entry = shift;
67              
68 0           foreach my $record ($self->{vault}->getrecords()) {
69 0 0         if ($record->title eq $entry) {
70 0           return $record->passwd;
71             }
72             }
73             }
74              
75             1;