line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Tree::Simple::Manager::Index; |
3
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
38414
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
297
|
|
5
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
180
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
26
|
use Scalar::Util qw(blessed); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
506
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
3052
|
use Tree::Simple::Manager::Exceptions; |
|
5
|
|
|
|
|
21
|
|
|
5
|
|
|
|
|
2392
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
17
|
|
|
17
|
1
|
6726
|
my ($_class, $tree) = @_; |
15
|
17
|
|
33
|
|
|
143
|
my $class = ref($_class) || $_class; |
16
|
17
|
|
|
|
|
28
|
my $index = {}; |
17
|
17
|
|
|
|
|
49
|
bless($index, $class); |
18
|
17
|
|
|
|
|
59
|
$index->_init($tree); |
19
|
12
|
|
|
|
|
308
|
return $index; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _init { |
23
|
17
|
|
|
17
|
|
29
|
my ($self, $tree) = @_; |
24
|
17
|
100
|
100
|
|
|
171
|
(blessed($tree) && $tree->isa("Tree::Simple")) |
25
|
|
|
|
|
|
|
|| throw Tree::Simple::Manager::InsufficientArguments; |
26
|
|
|
|
|
|
|
# add our root |
27
|
13
|
|
|
|
|
65
|
$self->{root_tree} = $tree; |
28
|
13
|
|
|
|
|
40
|
$self->{index} = {}; |
29
|
|
|
|
|
|
|
# then add all its children on down |
30
|
13
|
|
|
|
|
50
|
$self->indexTree(); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub indexTree { |
34
|
13
|
|
|
13
|
1
|
29
|
my ($self) = @_; |
35
|
|
|
|
|
|
|
$self->{root_tree}->traverse(sub { |
36
|
148
|
|
|
148
|
|
2701
|
my ($tree) = @_; |
37
|
148
|
100
|
|
|
|
465
|
(!exists $self->{index}->{$tree->getUID()}) |
38
|
|
|
|
|
|
|
|| throw Tree::Simple::Manager::IllegalOperation "tree (" . $tree->getUID() . ") already exists in the index, cannot add a duplicate"; |
39
|
147
|
|
|
|
|
1144
|
$self->{index}->{$tree->getUID()} = $tree; |
40
|
13
|
|
|
|
|
113
|
}); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
10
|
|
|
10
|
1
|
1526
|
sub getRootTree { (shift)->{root_tree} } |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub getIndexKeys { |
46
|
3
|
|
|
3
|
1
|
2166
|
my ($self) = @_; |
47
|
3
|
|
|
|
|
6
|
my @keys = keys %{$self->{index}}; |
|
3
|
|
|
|
|
20
|
|
48
|
3
|
100
|
|
|
|
41
|
return wantarray ? @keys : \@keys; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub getTreeByID { |
52
|
10
|
|
|
10
|
1
|
55
|
my ($self, $id) = @_; |
53
|
10
|
100
|
|
|
|
71
|
(exists $self->{index}->{$id}) |
54
|
|
|
|
|
|
|
|| throw Tree::Simple::Manager::KeyDoesNotExist "tree ($id) does not exist in the index"; |
55
|
8
|
|
|
|
|
33
|
return $self->{index}->{$id}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub hasTreeAtID { |
59
|
2
|
|
|
2
|
1
|
4
|
my ($self, $id) = @_; |
60
|
2
|
100
|
|
|
|
13
|
exists $self->{index}->{$id} ? 1 : 0 |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |