line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tree::Simple::Visitor::VariableDepthClone; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
18227
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
2
|
use Scalar::Util 'blessed'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
121
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.15'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use base qw(Tree::Simple::Visitor); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
475
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
13
|
|
|
13
|
1
|
8893
|
my ($_class) = @_; |
14
|
13
|
|
33
|
|
|
61
|
my $class = ref($_class) || $_class; |
15
|
13
|
|
|
|
|
14
|
my $visitor = {}; |
16
|
13
|
|
|
|
|
18
|
bless($visitor, $class); |
17
|
13
|
|
|
|
|
23
|
$visitor->_init(); |
18
|
13
|
|
|
|
|
65
|
return $visitor; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _init { |
22
|
13
|
|
|
13
|
|
12
|
my ($self) = @_; |
23
|
13
|
|
|
|
|
23
|
$self->{clone_depth} = undef; |
24
|
13
|
|
|
|
|
29
|
$self->SUPER::_init(); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub setCloneDepth { |
28
|
13
|
|
|
13
|
1
|
5453
|
my ($self, $clone_depth) = @_; |
29
|
13
|
100
|
|
|
|
38
|
(defined($clone_depth)) |
30
|
|
|
|
|
|
|
|| die "Insufficient Arguments : you must supply a clone depth"; |
31
|
12
|
|
|
|
|
19
|
$self->{clone_depth} = $clone_depth; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub getClone { |
35
|
12
|
|
|
12
|
1
|
65
|
my ($self) = @_; |
36
|
12
|
|
|
|
|
21
|
return $self->getResults()->[0]; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub visit { |
40
|
16
|
|
|
16
|
1
|
1456
|
my ($self, $tree) = @_; |
41
|
16
|
100
|
100
|
|
|
128
|
(blessed($tree) && $tree->isa("Tree::Simple")) |
42
|
|
|
|
|
|
|
|| die "Insufficient Arguments : You must supply a valid Tree::Simple object"; |
43
|
|
|
|
|
|
|
|
44
|
12
|
|
|
|
|
29
|
my $filter = $self->getNodeFilter(); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# get a new instance of the root tree type |
47
|
12
|
|
|
|
|
67
|
my $new_root = blessed($tree)->new($tree->ROOT); |
48
|
12
|
|
|
|
|
271
|
my $new_tree = $new_root; |
49
|
|
|
|
|
|
|
|
50
|
12
|
100
|
|
|
|
22
|
if ($self->includeTrunk()) { |
51
|
5
|
|
|
|
|
33
|
my $cloned_trunk = blessed($tree)->new(); |
52
|
5
|
|
|
|
|
87
|
$cloned_trunk->setNodeValue( |
53
|
|
|
|
|
|
|
Tree::Simple::_cloneNode($tree->getNodeValue()) |
54
|
|
|
|
|
|
|
); |
55
|
5
|
100
|
|
|
|
57
|
$filter->($tree, $cloned_trunk) if defined $filter; |
56
|
5
|
|
|
|
|
15
|
$new_tree->addChild($cloned_trunk); |
57
|
5
|
|
|
|
|
253
|
$new_tree = $cloned_trunk; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
12
|
|
|
|
|
48
|
$self->_cloneTree($tree, $new_tree, $self->{clone_depth}, $filter); |
61
|
|
|
|
|
|
|
|
62
|
12
|
|
|
|
|
52
|
$self->setResults($new_root); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _cloneTree { |
66
|
33
|
|
|
33
|
|
132
|
my ($self, $tree, $clone, $depth, $filter) = @_; |
67
|
33
|
100
|
|
|
|
56
|
return if $depth <= 0; |
68
|
21
|
|
|
|
|
32
|
foreach my $child ($tree->getAllChildren()) { |
69
|
55
|
|
|
|
|
301
|
my $cloned_child = blessed($child)->new(); |
70
|
55
|
|
|
|
|
876
|
$cloned_child->setNodeValue( |
71
|
|
|
|
|
|
|
Tree::Simple::_cloneNode($child->getNodeValue()) |
72
|
|
|
|
|
|
|
); |
73
|
55
|
100
|
|
|
|
407
|
$filter->($child, $cloned_child) if defined $filter; |
74
|
55
|
|
|
|
|
120
|
$clone->addChild($cloned_child); |
75
|
55
|
100
|
|
|
|
2292
|
$self->_cloneTree($child, $cloned_child, $depth - 1, $filter) unless $child->isLeaf(); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |