line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
2598
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
116
|
|
2
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
156
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Data::Remember::Hybrid; |
5
|
|
|
|
|
|
|
{ |
6
|
|
|
|
|
|
|
$Data::Remember::Hybrid::VERSION = '0.140490'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
# ABSTRACT: a brain for Data::Remember with multiple personalities |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
15
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
242
|
|
11
|
|
|
|
|
|
|
use Data::Remember::Util |
12
|
3
|
|
|
|
|
28
|
process_que => { -as => '_process_que' }, |
13
|
3
|
|
|
3
|
|
16
|
init_brain => { -as => '_init_brain' }; |
|
3
|
|
|
|
|
4
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
3
|
|
|
3
|
1
|
4
|
my $class = shift; |
18
|
3
|
|
|
|
|
10
|
my @table = @_; |
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
|
|
13
|
my $self = bless { root => undef, mounts => {} }, $class; |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
63
|
while (my ($que, $config) = splice @table, 0, 2) { |
23
|
8
|
|
|
|
|
26
|
$self->register_brain($que, $config); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
3
|
50
|
|
|
|
14
|
croak 'No root brain was registered!' |
27
|
|
|
|
|
|
|
unless defined $self->{root}; |
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
|
|
10
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub register_brain { |
34
|
8
|
|
|
8
|
1
|
12
|
my $self = shift; |
35
|
8
|
|
|
|
|
9
|
my $que = shift; |
36
|
8
|
|
|
|
|
11
|
my $config = shift; |
37
|
|
|
|
|
|
|
|
38
|
8
|
50
|
|
|
|
27
|
croak "You must give a que." unless defined $que; |
39
|
8
|
50
|
|
|
|
17
|
croak "You must give a configuration." unless defined $config; |
40
|
|
|
|
|
|
|
|
41
|
8
|
|
|
|
|
21
|
$que = _process_que($que); |
42
|
8
|
100
|
|
|
|
27
|
$config = [ $config ] unless ref $config; |
43
|
|
|
|
|
|
|
|
44
|
8
|
100
|
|
|
|
18
|
if (scalar(@$que) == 0) { |
45
|
3
|
|
|
|
|
18
|
$self->{root} = _init_brain(@$config); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
else { |
49
|
5
|
|
|
|
|
10
|
my $object = $self->{mounts}; |
50
|
5
|
|
|
|
|
10
|
for my $que_entry (@$que) { |
51
|
7
|
50
|
|
|
|
19
|
croak 'You ran amuck of my secret special que name "__BRAIN". ' |
52
|
|
|
|
|
|
|
. 'I cannot work with such a que name.' |
53
|
|
|
|
|
|
|
if $que_entry eq '__BRAIN'; |
54
|
|
|
|
|
|
|
|
55
|
7
|
100
|
|
|
|
18
|
if (defined $object->{$que_entry}) { |
56
|
1
|
|
|
|
|
2
|
$object = $object->{$que_entry}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
6
|
|
|
|
|
21
|
$object = $object->{$que_entry} = {}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
5
|
|
|
|
|
20
|
$object->{__BRAIN} = _init_brain(@$config); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub unregister_brain { |
69
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
70
|
0
|
|
|
|
|
0
|
my $que = shift; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
0
|
croak "You must give a que." unless defined $que; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
$que = _process_que($que); |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
0
|
if (scalar(@$que) == 0) { |
77
|
0
|
|
|
|
|
0
|
croak 'You cannot unregister the root. You may, however, replace it ' |
78
|
|
|
|
|
|
|
. 'using register_brain()'; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
my $object = $self->{mounts}; |
82
|
0
|
|
|
|
|
0
|
for my $que_entry (@$que) { |
83
|
0
|
0
|
|
|
|
0
|
croak 'You ran amuck of my secret special que name "__BRAIN". ' |
84
|
|
|
|
|
|
|
. 'I cannot work with such a que name.' |
85
|
|
|
|
|
|
|
if $que_entry eq '__BRAIN'; |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
0
|
if (defined $object->{$que_entry}) { |
88
|
0
|
|
|
|
|
0
|
$object = $object->{$que_entry}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
0
|
|
|
|
|
0
|
return; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
0
|
return scalar defined delete $object->{__BRAIN}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub brain_for { |
100
|
8
|
|
|
8
|
1
|
11
|
my $self = shift; |
101
|
8
|
|
|
|
|
10
|
my $que = shift; |
102
|
|
|
|
|
|
|
|
103
|
8
|
|
|
|
|
22
|
$que = Data::Remember::Class::_process_que($que); |
104
|
8
|
|
|
|
|
16
|
push @$que, 'X'; |
105
|
|
|
|
|
|
|
|
106
|
8
|
|
|
|
|
23
|
my ($best_brain) = $self->_best_brain($que); |
107
|
8
|
|
|
|
|
49
|
return scalar $best_brain; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _best_brain { |
112
|
94
|
|
|
94
|
|
105
|
my $self = shift; |
113
|
94
|
|
|
|
|
160
|
my $que = shift; |
114
|
|
|
|
|
|
|
|
115
|
94
|
|
|
|
|
165
|
my @sub_que = @$que; |
116
|
94
|
|
|
|
|
116
|
my $last_que = pop @sub_que; |
117
|
94
|
|
|
|
|
155
|
my $object = $self->{mounts}; |
118
|
|
|
|
|
|
|
|
119
|
94
|
|
|
|
|
150
|
my $best_brain = $self->{root}; |
120
|
94
|
|
|
|
|
182
|
my $best_que = [ @$que ]; |
121
|
|
|
|
|
|
|
|
122
|
94
|
|
|
|
|
241
|
while (my $que_entry = shift @sub_que) { |
123
|
67
|
100
|
|
|
|
135
|
if (defined $object->{$que_entry}) { |
124
|
37
|
|
|
|
|
49
|
$object = $object->{$que_entry}; |
125
|
|
|
|
|
|
|
|
126
|
37
|
100
|
|
|
|
107
|
if (defined $object->{__BRAIN}) { |
127
|
26
|
|
|
|
|
35
|
$best_brain = $object->{__BRAIN}; |
128
|
26
|
|
|
|
|
104
|
$best_que = [ @sub_que, $last_que ]; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
else { |
132
|
30
|
|
|
|
|
43
|
last; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
94
|
|
|
|
|
210
|
return ($best_brain, $best_que); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub remember { |
140
|
23
|
|
|
23
|
1
|
28
|
my $self = shift; |
141
|
23
|
|
|
|
|
26
|
my $que = shift; |
142
|
23
|
|
|
|
|
31
|
my $fact = shift; |
143
|
|
|
|
|
|
|
|
144
|
23
|
|
|
|
|
44
|
my ($best_brain, $best_que) = $self->_best_brain($que); |
145
|
23
|
|
|
|
|
80
|
return $best_brain->remember($best_que, $fact); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub recall { |
150
|
58
|
|
|
58
|
1
|
75
|
my $self = shift; |
151
|
58
|
|
|
|
|
66
|
my $que = shift; |
152
|
|
|
|
|
|
|
|
153
|
58
|
|
|
|
|
116
|
my ($best_brain, $best_que) = $self->_best_brain($que); |
154
|
58
|
|
|
|
|
174
|
return $best_brain->recall($best_que); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub forget { |
159
|
5
|
|
|
5
|
1
|
315
|
my $self = shift; |
160
|
5
|
|
|
|
|
6
|
my $que = shift; |
161
|
|
|
|
|
|
|
|
162
|
5
|
|
|
|
|
11
|
my ($best_brain, $best_que) = $self->_best_brain($que); |
163
|
5
|
|
|
|
|
22
|
return $best_brain->forget($best_que); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
1 |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
__END__ |