line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Forest::Tree::Loader::SimpleUIDLoader; |
2
|
3
|
|
|
3
|
|
7015
|
use Moose; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
29
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
5
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with 'Forest::Tree::Loader'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'row_parser' => ( |
10
|
|
|
|
|
|
|
is => 'ro', |
11
|
|
|
|
|
|
|
isa => 'CodeRef', |
12
|
|
|
|
|
|
|
default => sub { |
13
|
|
|
|
|
|
|
sub { |
14
|
|
|
|
|
|
|
my $row = shift; |
15
|
|
|
|
|
|
|
$row->{node}, $row->{uid}, $row->{parent_uid} |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
}, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub load { |
21
|
2
|
|
|
2
|
0
|
86
|
my ($self, $table) = @_; |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
|
|
83
|
my $root = $self->tree; |
24
|
2
|
|
|
|
|
97
|
my $row_parser = $self->row_parser; |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
4
|
my %index; |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
8
|
foreach my $row (@$table) { |
29
|
20
|
|
|
|
|
45
|
my ($node, $uid, undef) = $row_parser->($row); |
30
|
|
|
|
|
|
|
# NOTE: uids MUST be true values ... |
31
|
20
|
50
|
|
|
|
48
|
if ($uid) { |
32
|
20
|
|
|
|
|
233
|
my $t = $self->create_new_subtree( |
33
|
|
|
|
|
|
|
node => $node, |
34
|
|
|
|
|
|
|
uid => $uid, |
35
|
|
|
|
|
|
|
); |
36
|
20
|
|
|
|
|
74
|
$index{ $uid } = $t; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
5
|
my @orphans; |
41
|
2
|
|
|
|
|
8
|
foreach my $row (@$table) { |
42
|
20
|
|
|
|
|
38
|
my (undef, $uid, $parent_uid) = $row_parser->($row); |
43
|
|
|
|
|
|
|
# NOTE: uids MUST be true values ... |
44
|
20
|
50
|
|
|
|
48
|
if ($uid) { |
45
|
20
|
|
|
|
|
45
|
my $tree = $index{ $uid }; |
46
|
20
|
100
|
|
|
|
42
|
if (my $parent = $index{ $parent_uid }) { |
47
|
12
|
|
|
|
|
48
|
$parent->add_child($tree); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
8
|
|
|
|
|
20
|
push @orphans => $tree; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
2
|
50
|
|
|
|
10
|
if (@orphans) { |
56
|
2
|
|
|
|
|
16
|
$root->add_children(@orphans); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
0
|
|
|
|
|
0
|
$root->add_child( $index{ (sort keys %index)[0] } ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
27
|
$root; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
3
|
|
31641
|
no Moose; 1; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
24
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=pod |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 NAME |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Forest::Tree::Loader::SimpleUIDLoader - Loads a Forest::Tree heirarchy using UIDs |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 DESCRIPTION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 METHODS |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=over 4 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item B<> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=back |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 BUGS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
All complex software has bugs lurking in it, and this module is no |
90
|
|
|
|
|
|
|
exception. If you find a bug please either email me, or add the bug |
91
|
|
|
|
|
|
|
to cpan-RT. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AUTHOR |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Stevan Little E<lt>stevan.little@iinteractive.comE<gt> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Copyright 2008-2014 Infinity Interactive, Inc. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
L<http://www.iinteractive.com> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
104
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |