line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
10
|
|
|
10
|
|
8724
|
use 5.008; |
|
10
|
|
|
|
|
39
|
|
|
10
|
|
|
|
|
414
|
|
2
|
10
|
|
|
10
|
|
56
|
use strict; |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
300
|
|
3
|
10
|
|
|
10
|
|
50
|
use warnings; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
518
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Hook::Modular::Plugin; |
6
|
|
|
|
|
|
|
BEGIN { |
7
|
10
|
|
|
10
|
|
341
|
$Hook::Modular::Plugin::VERSION = '1.101050'; |
8
|
|
|
|
|
|
|
} |
9
|
|
|
|
|
|
|
# ABSTRACT: Base class for plugins |
10
|
10
|
|
|
10
|
|
65
|
use File::Find::Rule (); # don't import rule() |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
201
|
|
11
|
10
|
|
|
10
|
|
62
|
use File::Spec; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
93
|
|
12
|
10
|
|
|
10
|
|
253
|
use File::Basename; |
|
10
|
|
|
|
|
35
|
|
|
10
|
|
|
|
|
897
|
|
13
|
10
|
|
|
10
|
|
60
|
use Hook::Modular; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
150
|
|
14
|
10
|
|
|
10
|
|
6818
|
use Hook::Modular::Crypt; |
|
10
|
|
|
|
|
36
|
|
|
10
|
|
|
|
|
132
|
|
15
|
10
|
|
|
10
|
|
6510
|
use Hook::Modular::Rule; |
|
10
|
|
|
|
|
32
|
|
|
10
|
|
|
|
|
117
|
|
16
|
10
|
|
|
10
|
|
6118
|
use Hook::Modular::Rules; |
|
10
|
|
|
|
|
31
|
|
|
10
|
|
|
|
|
156
|
|
17
|
10
|
|
|
10
|
|
303
|
use Scalar::Util qw(blessed); |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
664
|
|
18
|
10
|
|
|
10
|
|
56
|
use parent qw( Class::Accessor::Fast ); |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
92
|
|
19
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(rule_hook cache)); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
16
|
|
|
16
|
1
|
47
|
my ($class, $opt) = @_; |
23
|
16
|
|
100
|
|
|
292
|
my $self = bless { |
|
|
|
50
|
|
|
|
|
24
|
|
|
|
|
|
|
conf => $opt->{config} || {}, |
25
|
|
|
|
|
|
|
rule => $opt->{rule}, |
26
|
|
|
|
|
|
|
rule_op => $opt->{rule_op} || 'AND', |
27
|
|
|
|
|
|
|
rule_hook => '', |
28
|
|
|
|
|
|
|
meta => {}, |
29
|
|
|
|
|
|
|
}, $class; |
30
|
16
|
|
|
|
|
95
|
$self->init; |
31
|
16
|
|
|
|
|
59
|
$self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub init { |
35
|
16
|
|
|
16
|
1
|
32
|
my $self = shift; |
36
|
16
|
100
|
|
|
|
165
|
if (my $rule = $self->{rule}) { |
37
|
6
|
50
|
|
|
|
30
|
$rule = [$rule] if ref $rule eq 'HASH'; |
38
|
6
|
|
|
|
|
11
|
my $op = $self->{rule_op}; |
39
|
6
|
|
|
|
|
32
|
$self->{rule} = Hook::Modular::Rules->new($op, @$rule); |
40
|
|
|
|
|
|
|
} else { |
41
|
10
|
|
|
|
|
160
|
$self->{rule} = Hook::Modular::Rule->new({ module => 'Always' }); |
42
|
|
|
|
|
|
|
} |
43
|
16
|
100
|
|
|
|
111
|
$self->walk_config_encryption |
44
|
|
|
|
|
|
|
if Hook::Modular->context->{conf}{should_rewrite_config}; |
45
|
|
|
|
|
|
|
} |
46
|
24
|
|
|
24
|
1
|
211
|
sub conf { $_[0]->{conf} } |
47
|
17
|
|
|
17
|
1
|
85
|
sub rule { $_[0]->{rule} } |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub walk_config_encryption { |
50
|
3
|
|
|
3
|
1
|
5
|
my $self = shift; |
51
|
3
|
|
|
|
|
13
|
my $conf = $self->conf; |
52
|
3
|
|
|
|
|
14
|
$self->do_walk($conf); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub do_walk { |
56
|
15
|
|
|
15
|
1
|
26
|
my ($self, $data) = @_; |
57
|
15
|
100
|
66
|
|
|
73
|
return unless defined($data) && ref $data; |
58
|
3
|
50
|
|
|
|
15
|
if (ref $data eq 'HASH') { |
|
|
0
|
|
|
|
|
|
59
|
3
|
|
|
|
|
11
|
for my $key (keys %$data) { |
60
|
12
|
100
|
|
|
|
28
|
if ($key =~ /password/) { |
61
|
3
|
|
|
|
|
15
|
$self->decrypt_config($data, $key); |
62
|
|
|
|
|
|
|
} |
63
|
12
|
|
|
|
|
32
|
$self->do_walk($data->{$key}); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} elsif (ref $data eq 'ARRAY') { |
66
|
0
|
|
|
|
|
0
|
$self->do_walk($_) for @$data; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub decrypt_config { |
71
|
3
|
|
|
3
|
1
|
79
|
my ($self, $data, $key) = @_; |
72
|
3
|
|
|
|
|
29
|
my $decrypted = Hook::Modular::Crypt->decrypt($data->{$key}); |
73
|
3
|
50
|
|
|
|
13
|
if ($decrypted eq $data->{$key}) { |
74
|
3
|
|
|
|
|
14
|
Hook::Modular->context->add_rewrite_task($key, $decrypted, |
75
|
|
|
|
|
|
|
Hook::Modular::Crypt->encrypt($decrypted, 'base64')); |
76
|
|
|
|
|
|
|
} else { |
77
|
0
|
|
|
|
|
0
|
$data->{$key} = $decrypted; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub dispatch_rule_on { |
82
|
4
|
|
|
4
|
1
|
8
|
my ($self, $hook) = @_; |
83
|
4
|
50
|
|
|
|
12
|
$self->rule_hook && $self->rule_hook eq $hook; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub class_id { |
87
|
16
|
|
|
16
|
1
|
32
|
my $self = shift; |
88
|
16
|
|
|
|
|
74
|
my $ns = Hook::Modular->context->{conf}{plugin_namespace}; |
89
|
16
|
|
33
|
|
|
73
|
my $pkg = ref($self) || $self; |
90
|
16
|
|
|
|
|
187
|
$pkg =~ s/$ns//; |
91
|
16
|
|
|
|
|
94
|
my @pkg = split /::/, $pkg; |
92
|
16
|
|
|
|
|
199
|
return join '-', @pkg; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# subclasses may overload to avoid cache sharing |
96
|
|
|
|
|
|
|
sub plugin_id { |
97
|
16
|
|
|
16
|
1
|
35
|
my $self = shift; |
98
|
16
|
|
|
|
|
94
|
$self->class_id; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub assets_dir { |
102
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
103
|
0
|
|
|
|
|
|
my $context = Hook::Modular->context; |
104
|
0
|
0
|
|
|
|
|
if ($self->conf->{assets_path}) { |
105
|
0
|
|
|
|
|
|
return $self->conf->{assets_path}; # look at config:assets_path first |
106
|
|
|
|
|
|
|
} |
107
|
0
|
|
0
|
|
|
|
my $assets_base = $context->conf->{assets_path} || # or global:assets_path |
108
|
|
|
|
|
|
|
File::Spec->catfile($FindBin::Bin, "assets") |
109
|
|
|
|
|
|
|
; # or "assets" under current script |
110
|
0
|
|
|
|
|
|
return File::Spec->catfile($assets_base, "plugins", $self->class_id,); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub log { |
114
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
115
|
0
|
|
|
|
|
|
Hook::Modular->context->log(@_, caller => ref $self); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub load_assets { |
119
|
0
|
|
|
0
|
1
|
|
my ($self, $rule, $callback) = @_; |
120
|
0
|
0
|
0
|
|
|
|
unless (blessed($rule) && $rule->isa('File::Find::Rule')) { |
121
|
0
|
|
|
|
|
|
$rule = File::Find::Rule->name($rule); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# ignore .svn directories |
125
|
0
|
|
|
|
|
|
$rule->or($rule->new->directory->name('.svn')->prune->discard, $rule->new,); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# $rule isa File::Find::Rule |
128
|
0
|
|
|
|
|
|
for my $file ($rule->in($self->assets_dir)) { |
129
|
0
|
|
|
|
|
|
my $base = File::Basename::basename($file); |
130
|
0
|
|
|
|
|
|
$callback->($file, $base); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |