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
|
|
47726
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
73
|
|
6
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
74
|
|
7
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
208
|
|
8
|
2
|
|
|
2
|
|
1316
|
use GeNUScreen::Config::Diff; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
69
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
1910
|
use version; our $VERSION = qv('0.0.10'); |
|
2
|
|
|
|
|
4907
|
|
|
2
|
|
|
|
|
16
|
|
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
|
|
382
|
use Class::Std; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
14
|
|
18
|
|
|
|
|
|
|
{ |
19
|
|
|
|
|
|
|
# storage for attributes |
20
|
|
|
|
|
|
|
my %cfg : ATTR; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub BUILD { |
23
|
2
|
|
|
2
|
0
|
135
|
my ($self, $ident, $args_ref) = @_; |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
10
|
$cfg{$ident} = {}; # nothing more for now |
26
|
|
|
|
|
|
|
} # BUILD() |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub read_config { |
29
|
2
|
|
|
2
|
1
|
31
|
my ($self,$filename) = @_; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
4
|
my %gs_cfg; |
32
|
2
|
|
|
|
|
4
|
my $prefix = ''; |
33
|
|
|
|
|
|
|
|
34
|
2
|
50
|
|
|
|
88
|
open my $fh, '<', $filename |
35
|
|
|
|
|
|
|
or croak("Could not open $filename for reading"); |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
55
|
while (<$fh>) { |
38
|
964
|
|
|
|
|
1164
|
chomp; |
39
|
964
|
100
|
|
|
|
8565
|
if (/^\s*($re_cfgpath)\s*=\s*($re_cfgval)?$/) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
40
|
520
|
|
|
|
|
3131
|
$gs_cfg{$prefix . $1} = $2; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
elsif (/^\s*($re_cfgpath)\s*<<\s*($re_marker)$/) { |
43
|
4
|
|
|
|
|
8
|
my $cfgpath = $1; |
44
|
4
|
|
|
|
|
7
|
my $marker = $2; |
45
|
4
|
|
|
|
|
6
|
my $cfgval = ''; |
46
|
4
|
|
|
|
|
50
|
while (<$fh>) { |
47
|
124
|
100
|
|
|
|
336
|
last if (/^$marker$/); |
48
|
120
|
|
|
|
|
328
|
$cfgval .= $_; |
49
|
|
|
|
|
|
|
} |
50
|
4
|
|
|
|
|
75
|
$gs_cfg{$prefix . $cfgpath} = $cfgval; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif (/^\s*($re_cfgvar)\s*\{\s*$/) { |
53
|
220
|
|
|
|
|
1043
|
$prefix .= $1 . "."; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
elsif (/^\s*\}\s*$/) { |
56
|
220
|
|
|
|
|
749
|
my @path_elements = split /[.]/, $prefix; |
57
|
220
|
|
|
|
|
588
|
$#path_elements--; |
58
|
220
|
|
|
|
|
1286
|
$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
|
|
|
|
|
11
|
$cfg{ident $self} = \%gs_cfg; |
66
|
2
|
|
|
|
|
31
|
close $fh; |
67
|
|
|
|
|
|
|
} # read_config() |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_keys { |
70
|
3
|
|
|
3
|
1
|
10
|
my ($self) = @_; |
71
|
|
|
|
|
|
|
|
72
|
3
|
|
|
|
|
4
|
return keys %{$cfg{ident $self}}; |
|
3
|
|
|
|
|
140
|
|
73
|
|
|
|
|
|
|
} # get_keys() |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub get_value { |
76
|
525
|
|
|
525
|
1
|
1350
|
my ($self,$key) = @_; |
77
|
|
|
|
|
|
|
|
78
|
525
|
|
|
|
|
2068
|
return $cfg{ident $self}->{$key}; |
79
|
|
|
|
|
|
|
} # get_value() |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub diff { |
82
|
1
|
|
|
1
|
1
|
3
|
my ($self,$thatcfg) = @_; |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
|
|
11
|
my $diff = GeNUScreen::Config::Diff->new(); |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
35
|
$diff->compare($self,$thatcfg); |
87
|
1
|
|
|
|
|
4
|
return $diff; |
88
|
|
|
|
|
|
|
} # diff() |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} # package GeNUScreen::Config |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
93
|
|
|
|
|
|
|
__END__ |