line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
10
|
|
|
10
|
|
5146
|
use strict; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
456
|
|
2
|
10
|
|
|
10
|
|
58
|
use warnings; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
820
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Data::Remember::Memory; |
5
|
|
|
|
|
|
|
{ |
6
|
|
|
|
|
|
|
$Data::Remember::Memory::VERSION = '0.140490'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
# ABSTRACT: a short-term memory brain plugin for Data::Remember |
9
|
|
|
|
|
|
|
|
10
|
10
|
|
|
10
|
|
57
|
use Scalar::Util qw/ reftype /; |
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
6074
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
9
|
|
|
9
|
1
|
13
|
my $class = shift; |
15
|
9
|
|
|
|
|
48
|
bless { brain => {} }, $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub remember { |
20
|
104
|
|
|
104
|
1
|
149
|
my $self = shift; |
21
|
104
|
|
|
|
|
136
|
my $que = shift; |
22
|
104
|
|
|
|
|
144
|
my $fact = shift; |
23
|
|
|
|
|
|
|
|
24
|
104
|
|
|
|
|
159
|
my $last_que = pop @$que; |
25
|
104
|
|
|
|
|
160
|
my $que_remaining = scalar @$que; |
26
|
|
|
|
|
|
|
|
27
|
104
|
|
|
|
|
203
|
my $object = $self->{brain}; |
28
|
104
|
|
|
|
|
248
|
for my $que_entry (@$que) { |
29
|
97
|
100
|
|
|
|
861
|
if (defined $object->{$que_entry}) { |
30
|
|
|
|
|
|
|
|
31
|
42
|
100
|
66
|
|
|
8846
|
if ($que_remaining == 0 |
|
|
|
33
|
|
|
|
|
32
|
|
|
|
|
|
|
or (ref $object->{$que_entry} |
33
|
|
|
|
|
|
|
and reftype $object->{$que_entry} eq 'HASH')) { |
34
|
41
|
|
|
|
|
12707
|
$object = $object->{$que_entry}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# overwrite previous non-hash fact with something more agreeable |
38
|
|
|
|
|
|
|
else { |
39
|
1
|
|
|
|
|
3
|
$object = $object->{$que_entry} = {} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
else { |
44
|
55
|
|
|
|
|
4444
|
$object = $object->{$que_entry} = {}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
97
|
|
|
|
|
43415
|
$que_remaining--; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
104
|
|
|
|
|
758
|
$object->{$last_que} = $fact; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub recall { |
55
|
296
|
|
|
296
|
1
|
443
|
my $self = shift; |
56
|
296
|
|
|
|
|
382
|
my $que = shift; |
57
|
|
|
|
|
|
|
|
58
|
296
|
|
|
|
|
683
|
my $object = $self->{brain}; |
59
|
296
|
|
|
|
|
573
|
for my $que_entry (@$que) { |
60
|
532
|
100
|
66
|
|
|
52532
|
return unless ref $object and reftype $object eq 'HASH'; |
61
|
|
|
|
|
|
|
|
62
|
531
|
100
|
|
|
|
1515
|
if (defined $object->{$que_entry}) { |
63
|
496
|
|
|
|
|
119871
|
$object = $object->{$que_entry}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
else { |
67
|
35
|
|
|
|
|
5513
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
260
|
|
|
|
|
63560
|
return scalar $object; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub forget { |
76
|
26
|
|
|
26
|
1
|
1476
|
my $self = shift; |
77
|
26
|
|
|
|
|
57
|
my $que = shift; |
78
|
|
|
|
|
|
|
|
79
|
26
|
|
|
|
|
102
|
my $last_que = pop @$que; |
80
|
|
|
|
|
|
|
|
81
|
26
|
|
|
|
|
52
|
my $object = $self->{brain}; |
82
|
26
|
|
|
|
|
69
|
for my $que_entry (@$que) { |
83
|
0
|
0
|
|
|
|
0
|
if (defined $object->{$que_entry}) { |
84
|
0
|
|
|
|
|
0
|
$object = $object->{$que_entry}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { |
87
|
0
|
|
|
|
|
0
|
return; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
26
|
|
|
|
|
126
|
delete $object->{$last_que}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |