line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (C) 2006, David Muir Sharnoff |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Plugins::Style1; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
2063
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
7
|
1
|
|
|
1
|
|
828
|
use Plugins; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
13
|
|
8
|
1
|
|
|
1
|
|
1379
|
use Hash::Util qw(lock_keys); |
|
1
|
|
|
|
|
3185
|
|
|
1
|
|
|
|
|
7
|
|
9
|
1
|
|
|
1
|
|
112
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
348
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Plugins); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $prefix_generator = "PREFIX_000000"; |
14
|
|
|
|
|
|
|
our $debug = 0; |
15
|
|
|
|
|
|
|
our %sequence; |
16
|
|
|
|
|
|
|
our $VERSION = $Plugins::VERSION; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new |
19
|
|
|
|
|
|
|
{ |
20
|
2
|
|
|
2
|
1
|
30
|
my ($pkg, %args) = @_; |
21
|
2
|
|
|
|
|
32
|
my $self = $pkg->SUPER::new(%args); |
22
|
2
|
|
50
|
|
|
17
|
my $context = $self->{context} || {}; |
23
|
2
|
|
100
|
|
|
23
|
$self->{prefixes_done} = $context->{prefixes_done} || {}; |
24
|
2
|
|
|
|
|
6
|
$self->{parse_config_line} = $args{parse_config_line}; |
25
|
2
|
|
|
|
|
5
|
$self->{config_prefix} = $context->{config_prefix}; |
26
|
2
|
|
50
|
|
|
17
|
$self->{plugin_directories} = $context->{plugin_directories} || [ '.' ]; |
27
|
2
|
50
|
|
|
|
18
|
lock_keys(%$self) |
28
|
|
|
|
|
|
|
if $pkg eq __PACKAGE__; |
29
|
2
|
|
|
|
|
29
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub parseconfig |
33
|
|
|
|
|
|
|
{ |
34
|
2
|
|
|
2
|
1
|
6
|
my ($self, $configfile, %args) = @_; |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
4
|
my $caller = $args{self}; |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
50
|
|
|
31
|
$configfile ||= $args{configfile} || $args{context}{configfile} || $self->{configfile} || die "no config file"; |
|
|
|
66
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
2
|
|
50
|
|
|
15
|
my $package = ref($caller) || scalar(caller()); |
41
|
2
|
|
|
|
|
4
|
my $rdebug = $debug; |
42
|
|
|
|
|
|
|
{ |
43
|
1
|
|
|
1
|
|
39
|
no strict qw(refs); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2039
|
|
|
2
|
|
|
|
|
2
|
|
44
|
2
|
|
|
|
|
3
|
$rdebug = ${"${package}::debug"}; |
|
2
|
|
|
|
|
15
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
2
|
50
|
|
|
|
6
|
printf STDERR "Reading %s for %s\n", $configfile, scalar(caller()) if $rdebug; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
10
|
my $combined_prefix = ''; |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
66
|
|
|
38
|
my $prefix = first_defined( |
|
|
|
66
|
|
|
|
|
52
|
|
|
|
|
|
|
$args{config_prefix}, |
53
|
|
|
|
|
|
|
$self->{config_prefix}, |
54
|
|
|
|
|
|
|
($caller && $caller->can('config_prefix') && $caller->config_prefix()), |
55
|
|
|
|
|
|
|
($self->{context}{requestor} && $prefix_generator++), |
56
|
|
|
|
|
|
|
''); |
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
5
|
my %prefixes_done = %{$self->{prefixes_done}}; |
|
2
|
|
|
|
|
7
|
|
59
|
2
|
50
|
|
|
|
12
|
$prefixes_done{$configfile}{$prefix} = ref($caller) ? ref($caller) : $caller; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $unknown = $args{parse_config_line} |
62
|
|
|
|
|
|
|
|| $self->{parse_config_line} |
63
|
|
|
|
|
|
|
|| ($caller && $caller->can('parse_config_line')) |
64
|
2
|
|
50
|
0
|
|
35
|
|| sub { die "unknown line in $configfile: '$_' (currently: shortname='$prefix', combined_prefix='$combined_prefix'" }; |
|
0
|
|
|
|
|
0
|
|
65
|
|
|
|
|
|
|
|
66
|
2
|
|
33
|
|
|
10
|
my $plugin_directories = $args{plugin_directories} || $self->{plugin_directories}; |
67
|
2
|
|
|
|
|
6
|
$plugin_directories = [ @$plugin_directories ]; |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
3
|
my %active_prefixes; |
70
|
|
|
|
|
|
|
my %known_prefixes; |
71
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
7
|
my $seqno = ++$sequence{$configfile}; |
73
|
|
|
|
|
|
|
|
74
|
2
|
50
|
|
|
|
138
|
open(CONFIG, "<$configfile") or croak "Could not open config file $configfile: $!"; |
75
|
2
|
|
|
|
|
41
|
while() { |
76
|
14
|
100
|
|
|
|
61
|
next if /^$/; |
77
|
10
|
50
|
|
|
|
25
|
next if /^#/; |
78
|
10
|
50
|
|
|
|
29
|
next if /^\s/; |
79
|
10
|
|
|
|
|
11
|
chomp; |
80
|
10
|
100
|
33
|
|
|
145
|
if (/^(.+_)?plugin\s+(\S+)(?:\s+as\s+(\w+)$)?/) { |
|
|
50
|
0
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
81
|
8
|
|
|
|
|
18
|
my $pre = $1; |
82
|
8
|
|
|
|
|
22
|
my $pkg = $2; |
83
|
8
|
|
|
|
|
14
|
my $config_prefix = $3; |
84
|
8
|
|
|
|
|
9
|
my @args; |
85
|
8
|
|
|
|
|
13
|
my $redo = 0; |
86
|
8
|
|
|
|
|
34
|
while () { |
87
|
20
|
|
|
|
|
24
|
$redo = 1; # we haven't seen EOF |
88
|
20
|
|
|
|
|
30
|
chomp; |
89
|
20
|
100
|
|
|
|
76
|
last unless s/^\s+//; |
90
|
12
|
50
|
|
|
|
29
|
next if /^#/; |
91
|
12
|
|
|
|
|
55
|
while (s/(?:"(.*?)"|'(.*?)'|([^\s'"#][^\s#]*))\s*//) { |
92
|
24
|
50
|
|
|
|
92
|
my $word = defined($1) ? $1 : (defined $2 ? $2 : (defined $3 ? $3 : last)); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
93
|
24
|
|
|
|
|
94
|
push(@args, $word); |
94
|
24
|
50
|
|
|
|
133
|
last if /^#/; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
8
|
50
|
33
|
|
|
62
|
if ($pkg =~ m{/} || $pkg =~ /^\w+$/) { |
|
|
50
|
|
|
|
|
|
98
|
0
|
|
|
|
|
0
|
$pkg = $self->file_plugin($pkg, |
99
|
|
|
|
|
|
|
search_path => $plugin_directories, |
100
|
|
|
|
|
|
|
referenced => "(referenced at $configfile line $.)", |
101
|
|
|
|
|
|
|
); |
102
|
0
|
|
0
|
|
|
0
|
$config_prefix ||= ''; |
103
|
|
|
|
|
|
|
} elsif ($config_prefix) { |
104
|
8
|
|
|
|
|
33
|
$self->pkg_invoke($pkg); |
105
|
|
|
|
|
|
|
} else { |
106
|
0
|
|
0
|
|
|
0
|
$config_prefix = $self->pkg_invoke($pkg, 'config_prefix') || ''; |
107
|
|
|
|
|
|
|
} |
108
|
8
|
100
|
100
|
|
|
69
|
if (! defined($pre) && $prefix eq '' or $pre && $prefix && $pre eq $prefix) { |
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
109
|
4
|
50
|
|
|
|
44
|
my $context = $self->registerplugin( |
110
|
|
|
|
|
|
|
pkg => $pkg, |
111
|
|
|
|
|
|
|
new_args => \@args, |
112
|
|
|
|
|
|
|
config_prefix => $config_prefix, |
113
|
|
|
|
|
|
|
configfile => $configfile, |
114
|
|
|
|
|
|
|
lineno => $., |
115
|
|
|
|
|
|
|
seqno => $seqno, |
116
|
|
|
|
|
|
|
prefixes_done => \%prefixes_done, |
117
|
|
|
|
|
|
|
(ref($self) eq __PACKAGE__ ? () : (pkg_override => ref($self))), |
118
|
|
|
|
|
|
|
config_lines => [], |
119
|
|
|
|
|
|
|
); |
120
|
4
|
|
|
|
|
16
|
$prefixes_done{$configfile}{$config_prefix} = $prefixes_done{$configfile}{$prefix}; |
121
|
4
|
|
|
|
|
7
|
$active_prefixes{$config_prefix} = $context; |
122
|
4
|
50
|
|
|
|
9
|
print STDERR "Plugin $pkg registered\n" if $rdebug; |
123
|
|
|
|
|
|
|
} else { |
124
|
|
|
|
|
|
|
# this isn't our plugin so we'll ignore it for now |
125
|
4
|
50
|
|
|
|
10
|
print STDERR "Plugin $pkg ignored\n" if $rdebug; |
126
|
|
|
|
|
|
|
} |
127
|
8
|
50
|
|
|
|
17
|
if ($config_prefix) { |
128
|
8
|
50
|
|
|
|
17
|
croak "config_prefix '$config_prefix' is used twice: first for at $configfile line $. and again at $known_prefixes{$config_prefix}" |
129
|
|
|
|
|
|
|
if $known_prefixes{$config_prefix}; |
130
|
8
|
|
|
|
|
24
|
$known_prefixes{$config_prefix} = "$pkg at line $."; |
131
|
8
|
100
|
|
|
|
14
|
if ($combined_prefix) { |
132
|
6
|
|
|
|
|
215
|
$combined_prefix = qr/(?:$combined_prefix|\Q$config_prefix\E)/; |
133
|
|
|
|
|
|
|
} else { |
134
|
2
|
|
|
|
|
29
|
$combined_prefix = qr/\Q$config_prefix\E/; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
8
|
50
|
33
|
|
|
85
|
redo if $redo && $_; |
138
|
|
|
|
|
|
|
} elsif (/^plugin_directory\s+(\S.*)/) { |
139
|
0
|
|
0
|
|
|
0
|
push(@$plugin_directories, grep($_ && -d $_, split(' ', $1))); |
140
|
|
|
|
|
|
|
} elsif ($combined_prefix && /^($combined_prefix)/) { |
141
|
2
|
100
|
|
|
|
11
|
push(@{$active_prefixes{$1}{config_lines}}, { |
|
1
|
|
|
|
|
18
|
|
142
|
|
|
|
|
|
|
config_prefix => $1, |
143
|
|
|
|
|
|
|
configfile => $configfile, |
144
|
|
|
|
|
|
|
seqno => $seqno, |
145
|
|
|
|
|
|
|
lineno => $., |
146
|
|
|
|
|
|
|
line => $_, |
147
|
|
|
|
|
|
|
}) if $active_prefixes{$1}; |
148
|
|
|
|
|
|
|
} elsif ($prefix && $self->{prefixes_done} && $self->{prefixes_done}{$configfile}{''}) { |
149
|
0
|
0
|
0
|
|
|
0
|
if (/^$prefix/ && ! $self->{prefixes_done}{$configfile}{$prefix}) { |
150
|
0
|
|
|
|
|
0
|
s/((?:[^'"]|".*?"|'.*?')*#.*)/$1/; |
151
|
0
|
|
|
|
|
0
|
&$unknown($caller, $prefix, $configfile, $_, $., $seqno); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} else { |
154
|
0
|
|
|
|
|
0
|
s/((?:[^'"]|".*?"|'.*?')*#.*)/$1/; |
155
|
0
|
|
|
|
|
0
|
&$unknown($caller, $prefix, $configfile, $_, $.); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
2
|
|
|
|
|
18
|
return (); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub genkey |
162
|
|
|
|
|
|
|
{ |
163
|
4
|
|
|
4
|
1
|
6
|
my ($self, $context) = @_; |
164
|
4
|
|
|
|
|
15
|
my $key = "$context->{pkg}/$context->{config_prefix}/$context->{configfile}"; |
165
|
4
|
|
|
|
|
11
|
return $key; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub post_initialize |
169
|
|
|
|
|
|
|
{ |
170
|
4
|
|
|
4
|
1
|
7
|
my ($self, $context, $plugin) = @_; |
171
|
4
|
|
|
|
|
6
|
for my $l (@{$context->{config_lines}}) { |
|
4
|
|
|
|
|
18
|
|
172
|
1
|
|
|
|
|
19
|
$plugin->invoke('parse_config_line', $l->{config_prefix}, $l->{configfile}, $l->{line}, $l->{lineno}, $l->{seqno}); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub first_defined |
177
|
|
|
|
|
|
|
{ |
178
|
2
|
|
|
2
|
0
|
43
|
for my $i (@_) { |
179
|
5
|
100
|
|
|
|
17
|
return $i if defined $i; |
180
|
|
|
|
|
|
|
} |
181
|
0
|
|
|
|
|
|
return undef; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub file_plugin |
185
|
|
|
|
|
|
|
{ |
186
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
187
|
0
|
|
|
|
|
|
my $pkg = $self->SUPER::file_plugin(@_, isa => 'Plugins::Style1::Plugin'); |
188
|
0
|
0
|
|
|
|
|
unless ($pkg->can('config_prefix')) { |
189
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
284
|
|
190
|
0
|
|
|
0
|
|
|
*{"${pkg}::config_prefix"} = sub { print STDERR "USING CONFIG_PREFIX\n"; ''; }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
} |
192
|
0
|
|
|
|
|
|
return $pkg; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
package Plugins::Style1::Plugin; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
our @ISA = qw(Plugins::Plugin); |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
1; |