File Coverage

blib/lib/Tree/Visualize/ASCII/Layouts/Binary.pm
Criterion Covered Total %
statement 30 30 100.0
branch 7 8 87.5
condition 4 9 44.4
subroutine 9 9 100.0
pod 3 3 100.0
total 53 59 89.8


line stmt bran cond sub pod time code
1              
2             package Tree::Visualize::ASCII::Layouts::Binary;
3              
4 3     3   1230 use strict;
  3         7  
  3         81  
5 3     3   15 use warnings;
  3         5  
  3         114  
6              
7             our $VERSION = '0.01';
8              
9 3     3   13 use base qw(Tree::Visualize::Layout::ILayout);
  3         12  
  3         1591  
10              
11 3     3   19 use Tree::Visualize::Exceptions;
  3         5  
  3         48  
12 3     3   524 use Tree::Visualize::ASCII::BoundingBox;
  3         5  
  3         67  
13 3     3   1135 use Tree::Visualize::Node::Factory;
  3         7  
  3         731  
14              
15             sub checkTree {
16 30     30 1 28 my ($self, $tree) = @_;
17 30 50 33     240 (defined($tree) && ref($tree) &&
      66        
      33        
18             (UNIVERSAL::isa($tree, "Tree::Binary") || UNIVERSAL::isa($tree, "Tree::Binary::Search")))
19             || throw Tree::Visualize::IncorrectObjectType
20             "binary tree argument must be a Tree::Binary or a Tree::Binary::Search object";
21 30 100       146 return $tree->getTree() if $tree->isa("Tree::Binary::Search");
22 28         58 return $tree;
23             }
24              
25             sub drawNode {
26 15     15 1 16 my ($self, $tree) = @_;
27 15         66 my $node = Tree::Visualize::Node::Factory->new()->get(output => 'ASCII', node_type => 'PlainBox', args => [ $tree ]);
28 15         110 return Tree::Visualize::ASCII::BoundingBox->new($node->draw());
29             }
30              
31             sub drawChildren {
32 30     30 1 34 my ($self, $tree) = @_;
33             # ready the children
34 30         34 my ($left, $right) = (undef, undef);
35             # get the left node, if we have one
36 30 100       68 $left = $self->draw($tree->getLeft()) if $tree->hasLeft();
37             # get the right node, if we have one
38 30 100       132 $right = $self->draw($tree->getRight()) if $tree->hasRight();
39             # and now return the children
40             # in our case we need to handle
41             # them postionally and let an
42             # undef value exist
43 30         159 return ($left, $right);
44             }
45              
46             1;
47              
48             __END__