File Coverage

blib/lib/Apache/Htpasswd/Perishable.pm
Criterion Covered Total %
statement 12 43 27.9
branch 0 18 0.0
condition n/a
subroutine 4 7 57.1
pod 1 3 33.3
total 17 71 23.9


line stmt bran cond sub pod time code
1             package Apache::Htpasswd::Perishable;
2              
3 1     1   7397 use strict;
  1         3  
  1         49  
4 1     1   8 use warnings;
  1         2  
  1         38  
5 1     1   942 use Apache::Htpasswd;
  1         14977  
  1         81  
6 1     1   1097 use Date::Simple qw(today);
  1         10104  
  1         447  
7              
8             our @ISA = qw(Apache::Htpasswd);
9              
10             our $VERSION = '1.00';
11              
12              
13             # Preloaded methods go here.
14              
15             sub new {
16 0     0 1   my $class = shift;
17 0           my $file = shift;
18              
19 0           my $self = bless {}, $class;
20              
21 0 0         system("touch $file") unless -f $file;
22 0 0         unless(-f $file){
23 0           $self->{'ERROR'} = __PACKAGE__. "::new Cannot create $file: $!";
24 0           croak $self->error();
25             }
26              
27             #i hope he cleans this up.
28 0           $self->{'PASSWD'} = $file;
29 0           $self->{'ERROR'} = "";
30 0           $self->{'LOCK'} = 0;
31 0           $self->{'OPEN'} = 0;
32              
33 0           return $self;
34             }
35              
36             sub extend {
37 0     0 0   my ($self,$login,$days) = @_;
38              
39 0 0         die "provide a login" unless $login;
40 0 0         die "provide a login" unless $days;
41              
42 0           $self->fetchInfo($login);
43 0           my $current = Date::Simple->new($self->fetchInfo($login));
44 0 0         die "Invalid date already exists. Cannot extend: $!" unless $current;
45              
46 0           my $extended = $current + $days;
47              
48 0 0         $self->writeInfo($login,$extended) or die "couldn't set expiration date: ".$self->error;
49 0           return 1;
50             }
51              
52             sub expire {
53 0     0 0   my ($self,$login,$days) = @_;
54              
55 0 0         die "provide a login" unless $login;
56 0 0         unless(defined $days){
57 0           my $expires = $self->fetchInfo($login);
58 0           my $today = today();
59 0           return $expires - $today;
60             }
61              
62 0           my $date = today();
63 0           my $expire = $date + $days;
64              
65 0 0         $self->writeInfo($login,$expire) or die "couldn't set expiration date: ".$self->error;
66 0           return 1;
67             }
68              
69             # Autoload methods go after =cut, and are processed by the autosplit program.
70              
71             1;
72             __END__