line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Labyrinth::Plugins; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
2917
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
51
|
|
4
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
54
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Labyrinth::Plugins - Plugin Manager for Labyrinth |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
load_plugins(@plugins); |
13
|
|
|
|
|
|
|
my $plugin = get_plugin($class); |
14
|
|
|
|
|
|
|
my @plugins = get_plugins(); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Although loaded via the main Labyrinth module, this module is used by others |
19
|
|
|
|
|
|
|
to quickly reference all the available plugins. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
7
|
use vars qw($VERSION @ISA %EXPORT_TAGS @EXPORT @EXPORT_OK); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
180
|
|
24
|
|
|
|
|
|
|
$VERSION = '5.32'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# ------------------------------------- |
27
|
|
|
|
|
|
|
# Export Details |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
require Exporter; |
30
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
33
|
|
|
|
|
|
|
'all' => [ qw(load_plugins get_plugin get_plugins) ], |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
@EXPORT_OK = ( @{$EXPORT_TAGS{'all'}} ); |
37
|
|
|
|
|
|
|
@EXPORT = ( @{$EXPORT_TAGS{'all'}} ); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# ------------------------------------- |
40
|
|
|
|
|
|
|
# Library Modules |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
2
|
|
8
|
use Labyrinth::Audit; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
205
|
|
43
|
2
|
|
|
2
|
|
63
|
use Labyrinth::Variables; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# ------------------------------------- |
46
|
|
|
|
|
|
|
# Variables |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my (%plugins,%classes); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# ------------------------------------- |
51
|
|
|
|
|
|
|
# The Program |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 FUNCTIONS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=over |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item load_plugins() |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Loads plugins found under the plugins directory. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item get_plugin($class) |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Returns the appropriate plugin for the given class. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item get_plugins() |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Returns all available plugins. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=back |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub load_plugins { |
74
|
|
|
|
|
|
|
$classes{$_} = 1 for(@_); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub get_plugin { |
78
|
|
|
|
|
|
|
my $class = shift; |
79
|
|
|
|
|
|
|
my $method = 'new'; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
return $plugins{$class} if($plugins{$class}); |
82
|
|
|
|
|
|
|
return unless($classes{$class}); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
eval { |
85
|
|
|
|
|
|
|
eval "CORE::require $class"; |
86
|
|
|
|
|
|
|
$plugins{$class} = $class->$method(@_); |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
if($@) { |
90
|
|
|
|
|
|
|
$tvars{errcode} = 'ERROR'; |
91
|
|
|
|
|
|
|
LogError("action: class=$class, method=new, FAULT: $@"); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
return $plugins{$class} || undef; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub get_plugins { |
98
|
|
|
|
|
|
|
return values %plugins; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |