line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MogileFS::Plugin::MultiHook; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
34
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
449
|
use MogileFS::Server; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
MogileFS::Plugin::MultiHook - MogileFS plugins for using multiple hooks |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
version 0.03 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
In the mogilefsd config, |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
plugins = MultiHook Foo |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
In "MogileFS::Plugin::Foo" plugin, |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
MogileFS::register_global_hook("cmd_create_open", sub { Mgd::log("info", "begin cmd_create_open") }); |
29
|
|
|
|
|
|
|
### Some process |
30
|
|
|
|
|
|
|
MogileFS::register_global_hook("cmd_create_open", sub { Mgd::log("info", "end cmd_create_open") }); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
This module is plugin for L to register and use multiple hooks. |
35
|
|
|
|
|
|
|
For using this plugin, you should set plugin name at head of plugins, such as: |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
plugins = MultiHook FilePaths |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
When this module is loaded, MogileFS::register_global_hook() and MogileFS::run_global_hook() will be replaced to what is available to register and use multiple hooks from original. |
40
|
|
|
|
|
|
|
But the arguments has not changed from an original in consideration. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
In addition, The register_global_hook() method simpley push a hook to the list of callbacks of each hook and |
43
|
|
|
|
|
|
|
run_global_hook() method will call hooks in order of pushed. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Calling MogileFS::unregister_global_hook() will delete all of callbacks of each specified hook. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 METHODS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 load() |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Calling by MogileFS::Config::load_config() method. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
our %hooks; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub load { |
58
|
|
|
|
|
|
|
Mgd::log("info", "MultiHook plugin load : begin") if ($MogileFS::Server::DEBUG); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
{ |
61
|
|
|
|
|
|
|
no strict 'refs'; |
62
|
|
|
|
|
|
|
no warnings 'redefine'; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
*{"MogileFS::register_global_hook"} = sub { |
65
|
|
|
|
|
|
|
my ($hookname, $callback) = @_; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
unless (exists $MogileFS::Plugin::MultiHook::hooks{$hookname} && ref $MogileFS::Plugin::MultiHook::hooks{$hookname} eq 'ARRAY') { |
68
|
|
|
|
|
|
|
$MogileFS::Plugin::MultiHook::hooks{$hookname} = []; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
push(@{$MogileFS::Plugin::MultiHook::hooks{$hookname}}, $callback); |
72
|
|
|
|
|
|
|
return 1; |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
*{"MogileFS::run_global_hook"} = sub { |
76
|
|
|
|
|
|
|
my ($hookname) = shift; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
return undef unless (exists $MogileFS::Plugin::MultiHook::hooks{$hookname} && ref $MogileFS::Plugin::MultiHook::hooks{$hookname} eq 'ARRAY'); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $ret = 1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Mgd::log("info", "Run global hook : " . $hookname) if ($MogileFS::Server::DEBUG); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
for my $callback (@{$MogileFS::Plugin::MultiHook::hooks{$hookname}}) { |
85
|
|
|
|
|
|
|
$ret = $ret && $callback->(@_) if (defined $callback && ref $callback eq 'CODE'); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
return $ret; |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
### for debug |
91
|
|
|
|
|
|
|
*{"MogileFS::global_hook"} = sub { |
92
|
|
|
|
|
|
|
my ($hookname) = shift; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
return \%MogileFS::Plugin::MultiHook::hooks unless ($hookname); |
95
|
|
|
|
|
|
|
return undef unless (exists $MogileFS::Plugin::MultiHook::hooks{$hookname} && ref $MogileFS::Plugin::MultiHook::hooks{$hookname} eq 'ARRAY'); |
96
|
|
|
|
|
|
|
return wantarray ? @{$MogileFS::Plugin::MultiHook::hooks{$hookname}} : $MogileFS::Plugin::MultiHook::hooks{$hookname}; |
97
|
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
}; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Mgd::log("info", "MultiHook plugin load : end") if ($MogileFS::Server::DEBUG); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SEE ALSO |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=over 4 |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item L |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item L |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item L |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item L |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item L |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=back |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 AUTHOR |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Toru Yamaguchi, C<< >> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 BUGS |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
128
|
|
|
|
|
|
|
C, or through the web interface at |
129
|
|
|
|
|
|
|
L. I will be notified, and then you'll automatically be |
130
|
|
|
|
|
|
|
notified of progress on your bug as I make changes. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Copyright 2007 Toru Yamaguchi, All Rights Reserved. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
137
|
|
|
|
|
|
|
under the same terms as Perl itself. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; # End of MogileFS::Plugin::MultiHook |