|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Tree::Simple::Visitor::ToNestedArray;  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
3
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
 
 | 
20689
 | 
 use strict;  | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
24
 | 
    | 
| 
4
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
 
 | 
4
 | 
 use warnings;  | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
32
 | 
    | 
| 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $VERSION = '0.14';  | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
8
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
 
 | 
5
 | 
 use Scalar::Util qw(blessed);  | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
148
 | 
    | 
| 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
10
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
 
 | 
6
 | 
 use base qw(Tree::Simple::Visitor);  | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
533
 | 
    | 
| 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub new {  | 
| 
13
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
  
1
  
 | 
4162
 | 
     my ($_class) = @_;  | 
| 
14
 | 
5
 | 
 
 | 
  
 33
  
 | 
 
 | 
 
 | 
23
 | 
     my $class = ref($_class) || $_class;  | 
| 
15
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
     my $visitor = {};  | 
| 
16
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     bless($visitor, $class);  | 
| 
17
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
20
 | 
     $visitor->_init();  | 
| 
18
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
33
 | 
     return $visitor;  | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub visit {  | 
| 
22
 | 
8
 | 
 
 | 
 
 | 
  
8
  
 | 
  
1
  
 | 
8248
 | 
 	my ($self, $tree) = @_;  | 
| 
23
 | 
8
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
92
 | 
 	(blessed($tree) && $tree->isa("Tree::Simple"))  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		|| die "Insufficient Arguments : You must supply a valid Tree::Simple object";  | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # grab our filter (if we have one)  | 
| 
26
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13
 | 
     my $filter = $self->getNodeFilter();  | 
| 
27
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
14
 | 
     my @results;  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # get the array  | 
| 
29
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11
 | 
     $self->_buildArray($tree, \@results, $filter);  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # add the trunk if we need to  | 
| 
31
 | 
4
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
10
 | 
     @results = (  | 
| 
 
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             ((defined($filter)) ?  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     $filter->($tree)  | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     :  | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     $tree->getNodeValue()),  | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             [ @results ]  | 
| 
37
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         ) if $self->includeTrunk();  | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # set results  | 
| 
39
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
43
 | 
     $self->setResults(\@results);  | 
| 
40
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _buildArray {  | 
| 
43
 | 
8
 | 
 
 | 
 
 | 
  
8
  
 | 
 
 | 
10
 | 
     my ($self, $tree, $accumulator, $filter) = @_;  | 
| 
44
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
16
 | 
     foreach my $child ($tree->getAllChildren()) {  | 
| 
45
 | 
16
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
53
 | 
         push @{$accumulator} => (defined($filter) ? $filter->($child) : $child->getNodeValue());  | 
| 
 
 | 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
38
 | 
    | 
| 
46
 | 
16
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
63
 | 
         push @{$accumulator} => $self->_buildArray($child, [], $filter) unless $child->isLeaf();  | 
| 
 
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
33
 | 
    | 
| 
47
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
48
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
43
 | 
     return $accumulator;  | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |