line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sman::IndexVersion; |
2
|
1
|
|
|
1
|
|
649
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
701
|
use fields qw( config ); |
|
1
|
|
|
|
|
1292
|
|
|
1
|
|
|
|
|
6
|
|
5
|
|
|
|
|
|
|
#use Data::Dumper; # tmp, for debugging |
6
|
|
|
|
|
|
|
#$Id: IndexVersion.pm,v 1.7 2008/06/03 15:38:48 joshr Exp $ |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# call like my $versions = new Sman::IndexVersion( $sman_config_obj ) |
9
|
|
|
|
|
|
|
# appends .version to determine the version file. |
10
|
|
|
|
|
|
|
sub new { |
11
|
1
|
|
|
1
|
0
|
433
|
my $proto = shift; |
12
|
1
|
|
33
|
|
|
16
|
my $class = ref($proto) || $proto; |
13
|
1
|
|
|
|
|
2
|
my $self = {}; |
14
|
1
|
|
|
|
|
3
|
bless ($self, $class); |
15
|
1
|
|
50
|
|
|
8
|
$self->{config} = shift || |
16
|
|
|
|
|
|
|
die "$0: must pass a config object to Sman::IndexVersion::new()"; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
4
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
# uses the $self->{config} object to figure out the .version filename |
21
|
|
|
|
|
|
|
sub get_version_filename { |
22
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
23
|
0
|
|
|
|
|
|
my $config = $self->{config}; |
24
|
0
|
|
0
|
|
|
|
my $index = $config->GetConfigData("SWISHE_IndexFile") || |
25
|
|
|
|
|
|
|
die "$0: no indexfile specified in configuration"; |
26
|
0
|
|
|
|
|
|
return "$index.version"; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
sub set_versions { |
29
|
0
|
|
|
0
|
0
|
|
my ($self, $href) = @_; |
30
|
|
|
|
|
|
|
#print "$0: debug: set_versions() called\n"; |
31
|
0
|
|
|
|
|
|
my $version_filename = $self->get_version_filename(); |
32
|
0
|
0
|
|
|
|
|
open(VFILE, "> $version_filename") || |
33
|
|
|
|
|
|
|
die "$0: can't open to write: $version_filename\n"; |
34
|
0
|
|
|
|
|
|
for my $k (keys( %$href ) ) { |
35
|
0
|
|
|
|
|
|
print VFILE "$k $href->{$k}\n"; |
36
|
|
|
|
|
|
|
} |
37
|
0
|
0
|
|
|
|
|
close(VFILE) || |
38
|
|
|
|
|
|
|
die "$0: can't close: $version_filename\n"; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# returns a hashref of NAME=>VALUE info |
42
|
|
|
|
|
|
|
sub get_versions { |
43
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
my %hash; |
45
|
0
|
|
|
|
|
|
my $version_filename = $self->get_version_filename(); |
46
|
|
|
|
|
|
|
#print "$0: debug: get_versions() called, opening $version_filename\n"; |
47
|
0
|
0
|
|
|
|
|
return \%hash unless -f $version_filename; |
48
|
0
|
0
|
|
|
|
|
open(VFILE, "< $version_filename") || |
49
|
|
|
|
|
|
|
die "$0: can't open to read: $version_filename\n"; |
50
|
0
|
|
|
|
|
|
while( defined( my $line = ) ) { |
51
|
0
|
|
|
|
|
|
chomp($line); |
52
|
0
|
|
|
|
|
|
my ($k, $v) = split(/ /, $line, 2); |
53
|
0
|
0
|
0
|
|
|
|
if ($k && $v) { |
54
|
0
|
|
|
|
|
|
$hash{$k} = $v; |
55
|
|
|
|
|
|
|
#print "$0: Sman::IndexVersion::get_versions(): got $k, $v\n"; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
0
|
0
|
|
|
|
|
close(VFILE) || |
59
|
|
|
|
|
|
|
die "$0: can't close $version_filename\n"; |
60
|
0
|
|
|
|
|
|
return \%hash; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
__END__ |