-
Notifications
You must be signed in to change notification settings - Fork 10
/
CachedUrls.pm
executable file
·74 lines (62 loc) · 1.56 KB
/
CachedUrls.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package CachedUrls;
use strict;
#constructor
sub new {
my $class = shift;
my %param = @_;
my $self = {
_origUrl => $param{-origUrl}, # URL before be canonicalized
_repoName => $param{-repoName},
_urlCache => $param{-urlCache},
_cacheDate => $param{-cacheDate} #setDate($param{-cacheDate})
};
bless $self, $class;
return $self;
}
sub origUrl {
my ( $self, $origUrl ) = @_;
$self->{_origUrl} = $origUrl if defined($origUrl);
return $self->{_origUrl};
}
sub repoName {
my ( $self, $repoName ) = @_;
$self->{_repoName} = $repoName if defined($repoName);
return $self->{_repoName};
}
sub urlCache {
my ( $self, $urlCache ) = @_;
$self->{_urlCache} = $urlCache if defined($urlCache);
return $self->{_urlCache};
}
sub setDate {
my $cacheDate = shift;
return if !defined $cacheDate;
# See if number is in format YYYY-MM-DD
if ($cacheDate !~ /^\d\d\d\d-\d\d-\d\d$/) {
print STDERR "ERROR in CachedUrls.pm : Stored date [$cacheDate] is not in YYYY-MM-DD format.\n";
return;
}
else {
# Remove dashes if present
$cacheDate =~ s/-//g;
return $cacheDate;
}
}
sub cacheDate {
my ( $self, $cacheDate ) = @_;
$self->{_cacheDate} = $cacheDate if defined($cacheDate);
return $self->{_cacheDate};
}
sub storedDateFormatted {
my ( $self ) = @_;
# convert to yyyy-mm-dd
my $date = $self->{_cacheDate};
if (!defined $date) {
print STDERR "ERROR in CachedUrls.pm : The _cacheDate is not defined!\n";
}
else {
$date =~ s/(\d\d\d\d)(\d\d)(\d\d)/$1-$2-$3/;
}
return $date;
}
1;