line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
28128
|
use 5.008; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
46
|
|
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
65
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Hook::Modular::Builder; |
6
|
|
|
|
|
|
|
BEGIN { |
7
|
1
|
|
|
1
|
|
39
|
$Hook::Modular::Builder::VERSION = '1.101050'; |
8
|
|
|
|
|
|
|
} |
9
|
|
|
|
|
|
|
# ABSTRACT: Domain-specific language for building configurations |
10
|
1
|
|
|
1
|
|
6
|
use Exporter qw(import); |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
55
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw(builder enable global log_level cache_base); |
12
|
1
|
|
|
1
|
|
6
|
use Carp (); |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
901
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
1
|
|
|
1
|
1
|
4
|
my $class = shift; |
16
|
1
|
|
|
|
|
5
|
bless { config => {} }, $class; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub do_enable { |
20
|
1
|
|
|
1
|
1
|
8
|
my ($self, $plugin, %args) = @_; |
21
|
1
|
|
50
|
|
|
17
|
$self->{config}{plugins} ||= []; |
22
|
1
|
|
|
|
|
2
|
push @{ $self->{config}{plugins} }, |
|
1
|
|
|
|
|
6
|
|
23
|
|
|
|
|
|
|
{ module => $plugin, |
24
|
|
|
|
|
|
|
config => \%args |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub do_global (&) { |
29
|
0
|
|
|
0
|
1
|
0
|
my ($self, $global) = @_; |
30
|
0
|
|
|
|
|
0
|
$self->{config}{global} = $global; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# convenience subs to get at more specific but often used config locations |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub do_log_level { |
36
|
1
|
|
|
1
|
1
|
4
|
my ($self, $log_level) = @_; |
37
|
1
|
|
|
|
|
12
|
$self->{config}{global}{log}{level} = $log_level; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub do_cache_base { |
41
|
1
|
|
|
1
|
1
|
3
|
my ($self, $cache_base) = @_; |
42
|
1
|
|
|
|
|
7
|
$self->{config}{global}{cache}{base} = $cache_base; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
our $_enable = sub { |
46
|
|
|
|
|
|
|
Carp::croak("enable should be called inside builder {} block"); |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
our $_global = sub { |
49
|
|
|
|
|
|
|
Carp::croak("global should be called inside builder {} block"); |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
our $_log_level = sub { |
52
|
|
|
|
|
|
|
Carp::croak("log_level should be called inside builder {} block"); |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
our $_cache_base = sub { |
55
|
|
|
|
|
|
|
Carp::croak("cache_base should be called inside builder {} block"); |
56
|
|
|
|
|
|
|
}; |
57
|
1
|
|
|
1
|
1
|
8
|
sub enable { $_enable->(@_) } |
58
|
0
|
|
|
0
|
1
|
0
|
sub global { $_global->(@_) } |
59
|
1
|
|
|
1
|
1
|
8
|
sub log_level { $_log_level->(@_) } |
60
|
1
|
|
|
1
|
1
|
8
|
sub cache_base { $_cache_base->(@_) } |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub builder(&) { |
63
|
1
|
|
|
1
|
1
|
15
|
my $block = shift; |
64
|
1
|
|
|
|
|
11
|
my $self = __PACKAGE__->new; |
65
|
|
|
|
|
|
|
local $_enable = sub { |
66
|
1
|
|
|
1
|
|
4
|
$self->do_enable(@_); |
67
|
1
|
|
|
|
|
7
|
}; |
68
|
|
|
|
|
|
|
local $_global = sub { |
69
|
0
|
|
|
0
|
|
0
|
$self->do_global(@_); |
70
|
1
|
|
|
|
|
4
|
}; |
71
|
|
|
|
|
|
|
local $_log_level = sub { |
72
|
1
|
|
|
1
|
|
6
|
$self->do_log_level(@_); |
73
|
1
|
|
|
|
|
5
|
}; |
74
|
|
|
|
|
|
|
local $_cache_base = sub { |
75
|
1
|
|
|
1
|
|
5
|
$self->do_cache_base(@_); |
76
|
1
|
|
|
|
|
5
|
}; |
77
|
1
|
|
|
|
|
5
|
$block->(); |
78
|
1
|
|
|
|
|
15
|
$self->{config}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__END__ |