line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Class::AbstractLogic::Manager - Manages Abstract Logic Modules |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=cut |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Class::AbstractLogic::Manager; |
8
|
2
|
|
|
2
|
|
24799
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
58
|
|
9
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
85
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
763
|
use Carp::Clan qr/^Class::AbstractLogic::/; |
|
2
|
|
|
|
|
4318
|
|
|
2
|
|
|
|
|
17
|
|
12
|
2
|
|
|
2
|
|
236
|
use aliased 'Class::Inspector'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
16
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This module does the loading, fetching and similar actions of your declared |
17
|
|
|
|
|
|
|
logic modules. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 METHODS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head2 new(%args) |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Constructor, creates new Management Object and initializes the C<%args>. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
28
|
|
|
|
|
|
|
my ($class, %args) = @_; |
29
|
|
|
|
|
|
|
my $self = bless {} => $class; |
30
|
|
|
|
|
|
|
$self->_initialize(%args); |
31
|
|
|
|
|
|
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 load_logic($name, $logic_class) |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Loads the specified C<$logic_class> and registers it under the $name in |
37
|
|
|
|
|
|
|
itself. The C hashes value for the key C<$name> will be passed |
38
|
|
|
|
|
|
|
as C for the module. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub load_logic { |
43
|
|
|
|
|
|
|
my ($self, $name, $logic_class) = @_; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
unless (Inspector->loaded($logic_class)) { |
46
|
|
|
|
|
|
|
require(Inspector->filename($logic_class)); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
my $logic_object = $logic_class->new( |
49
|
|
|
|
|
|
|
config => $self->_config->{$name} ); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$self->_register_logic_object($name, $logic_object); |
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 logic($name) |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Retrieves a logic module registered under C<$name>. Croaks if none found or |
58
|
|
|
|
|
|
|
no name supplied. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub logic { |
63
|
|
|
|
|
|
|
my ($self, $name) = @_; |
64
|
|
|
|
|
|
|
croak 'No logic name supplied' |
65
|
|
|
|
|
|
|
unless $name; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return $self->_fetch_logic($name); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 _register_logic_object($name, $object) |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Registers the passed C<$object> under the specified C<$name> in this manager. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _register_logic_object { |
77
|
|
|
|
|
|
|
my ($self, $name, $object) = @_; |
78
|
|
|
|
|
|
|
$self->{logics}{$name} = $object; |
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 _fetch_logic($name) |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Returns logic module if exists, croaks otherwise. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _fetch_logic { |
89
|
|
|
|
|
|
|
my ($self, $name) = @_; |
90
|
|
|
|
|
|
|
unless ($self->_logic_exists($name)) { |
91
|
|
|
|
|
|
|
croak "No logic module with name '$name' registered"; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
my $logic = $self->{logics}{$name}; |
94
|
|
|
|
|
|
|
$logic->set_manager($self); |
95
|
|
|
|
|
|
|
return $logic; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 _logic_exists($name) |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Returns a boolean value depending on the existance of a module registered |
101
|
|
|
|
|
|
|
as C<$name>. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _logic_exists { |
106
|
|
|
|
|
|
|
my ($self, $name) = @_; |
107
|
|
|
|
|
|
|
return exists $self->{logics}{$name}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 _initialize(%args) |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Initializes the arguments. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub _initialize { |
117
|
|
|
|
|
|
|
my ($self, %args) = @_; |
118
|
|
|
|
|
|
|
$self->{config} = $args{config} || {}; |
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 _config() |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Config Accessor. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _config { |
129
|
|
|
|
|
|
|
my ($self) = @_; |
130
|
|
|
|
|
|
|
return $self->{config}; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SEE ALSO |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
L |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 AUTHOR |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Robert 'phaylon' Sedlacek Cphaylon@dunkelheit.atE> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
144
|
|
|
|
|
|
|
the same terms as Perl itself. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |