line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# vim: set ts=4 sw=4 tw=78 et si: |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
package GeNUScreen::Config; |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
149423
|
use warnings; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
76
|
|
6
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
41
|
|
7
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
107
|
|
8
|
2
|
|
|
2
|
|
932
|
use GeNUScreen::Config::Diff; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
69
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
16
|
use version; our $VERSION = qv('v0.0.11'); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $re_cfgval = qr/\S.*/; |
13
|
|
|
|
|
|
|
my $re_cfgvar = qr/[0-9a-z_]+/i; |
14
|
|
|
|
|
|
|
my $re_cfgpath = qr/$re_cfgvar(?:\.$re_cfgvar)*/; |
15
|
|
|
|
|
|
|
my $re_marker = qr/[a-z]+/i; |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
2
|
|
308
|
use Class::Std; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
18
|
|
|
|
|
|
|
{ |
19
|
|
|
|
|
|
|
# storage for attributes |
20
|
|
|
|
|
|
|
my %cfg : ATTR; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub BUILD { |
23
|
2
|
|
|
2
|
0
|
245
|
my ($self, $ident, $args_ref) = @_; |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
8
|
$cfg{$ident} = {}; # nothing more for now |
26
|
|
|
|
|
|
|
} # BUILD() |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub read_config { |
29
|
2
|
|
|
2
|
1
|
42
|
my ($self,$filename) = @_; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
5
|
my %gs_cfg; |
32
|
2
|
|
|
|
|
3
|
my $prefix = ''; |
33
|
|
|
|
|
|
|
|
34
|
2
|
50
|
|
|
|
93
|
open my $fh, '<', $filename |
35
|
|
|
|
|
|
|
or croak("Could not open $filename for reading"); |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
91
|
while (<$fh>) { |
38
|
964
|
|
|
|
|
1467
|
chomp; |
39
|
964
|
100
|
|
|
|
5853
|
if (/^\s*($re_cfgpath)\s*=\s*($re_cfgval)?$/) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
40
|
520
|
|
|
|
|
2593
|
$gs_cfg{$prefix . $1} = $2; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
elsif (/^\s*($re_cfgpath)\s*<<\s*($re_marker)$/) { |
43
|
4
|
|
|
|
|
12
|
my $cfgpath = $1; |
44
|
4
|
|
|
|
|
6
|
my $marker = $2; |
45
|
4
|
|
|
|
|
8
|
my $cfgval = ''; |
46
|
4
|
|
|
|
|
31
|
while (<$fh>) { |
47
|
124
|
100
|
|
|
|
294
|
last if (/^$marker$/); |
48
|
120
|
|
|
|
|
273
|
$cfgval .= $_; |
49
|
|
|
|
|
|
|
} |
50
|
4
|
|
|
|
|
78
|
$gs_cfg{$prefix . $cfgpath} = $cfgval; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif (/^\s*($re_cfgvar)\s*\{\s*$/) { |
53
|
220
|
|
|
|
|
884
|
$prefix .= $1 . "."; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
elsif (/^\s*\}\s*$/) { |
56
|
220
|
|
|
|
|
633
|
my @path_elements = split /[.]/, $prefix; |
57
|
220
|
|
|
|
|
504
|
$#path_elements--; |
58
|
220
|
|
|
|
|
1089
|
$prefix = join('.', @path_elements) . '.'; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
0
|
|
|
|
|
0
|
croak("read_config could not parse" |
62
|
|
|
|
|
|
|
. " line $. in file $filename: '$_'"); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
2
|
|
|
|
|
14
|
$cfg{ident $self} = \%gs_cfg; |
66
|
2
|
|
|
|
|
33
|
close $fh; |
67
|
|
|
|
|
|
|
} # read_config() |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_keys { |
70
|
3
|
|
|
3
|
1
|
23
|
my ($self) = @_; |
71
|
|
|
|
|
|
|
|
72
|
3
|
|
|
|
|
6
|
return keys %{$cfg{ident $self}}; |
|
3
|
|
|
|
|
97
|
|
73
|
|
|
|
|
|
|
} # get_keys() |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub get_value { |
76
|
525
|
|
|
525
|
1
|
1526
|
my ($self,$key) = @_; |
77
|
|
|
|
|
|
|
|
78
|
525
|
|
|
|
|
1309
|
return $cfg{ident $self}->{$key}; |
79
|
|
|
|
|
|
|
} # get_value() |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub diff { |
82
|
1
|
|
|
1
|
1
|
3
|
my ($self,$thatcfg) = @_; |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
|
|
6
|
my $diff = GeNUScreen::Config::Diff->new(); |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
30
|
$diff->compare($self,$thatcfg); |
87
|
1
|
|
|
|
|
6
|
return $diff; |
88
|
|
|
|
|
|
|
} # diff() |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} # package GeNUScreen::Config |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
93
|
|
|
|
|
|
|
__END__ |