blib/lib/Perl/Structure/Graph/Tree/Binary.pm untested

filter: Statementstmt 0.0% 0 / 72 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 97 CC 3 SCAR 10.4
CC
3
Cov
0%
traverse_breadthfirst_queue
6.0
traverse_depthfirst_preorder
6.0
new_from_nested_arrayrefs
2.0
CRAP 2.8
1 package Perl::Structure::Graph::Tree::Binary;
2 use strict;
3 use warnings;
4 use Perl::Config; # don't use Perl::Types inside itself, in order to avoid circular includes
5 our $VERSION = 0.001_000;
6  
7 # NEED FIX: weird inheritance for these as-reference-only data structures
8 package Perl::Structure::Graph::Tree::BinaryReference;
9 use parent qw(Perl::Structure::Graph::TreeReference);
10 use Perl::Structure::Graph::Tree;
11  
12 # [[[ INCLUDES ]]]
13  
14 # trees are comprised of nodes
15 use Perl::Structure::Graph::Tree::Binary::Node;
16  
17 # coderef parameter accepted by traverse method(s)
18 use Perl::Structure::CodeReference;
19  
20 # must include here because we do not inherit data types
21 use Perl::Type::Unknown;
22 use Perl::Type::String;
23 use Perl::Structure::Array;
24 #use RPerl::CodeBlock::Subroutine::Method; # NEED ADD: explicit method declarations # NEED UPDATE, RPERL REFACTOR
25  
26 our hashref $properties =
27 {
28 root => my Perl::Structure::Graph::Tree::Binary::NodeReference $TYPED_root = undef, # start with root = undef so we can test for empty tree
29 };
30  
31 sub new_from_nested_arrayrefs {
32 { my Perl::Structure::Graph::Tree::BinaryReference $RETURN_TYPE };
33 (my string $class, my arrayref $input) = @ARG;
34 # Perl::diag("in ...Tree::BinaryReference::new_from_nested_arrayrefs(), received \$class = '$class', and \$input =\n" . Dumper($input) . "\n");
35 my unknown $output = $class->new();
36  
37 $output->{root} = binarytreenoderef->new_from_nested_arrayrefs($input);
38 return $output;
39 }
40  
41 # much happens in the Node class, provide wrapper methods
42 sub traverse_breadthfirst_queue { { my unknown $RETURN_TYPE };(my Perl::Structure::Graph::Tree::BinaryReference $self, my Perl::Structure::CodeReference $callback) = @ARG; return $self->{root}->traverse_breadthfirst_queue($callback) if defined($self->{root}); }
43 sub traverse_depthfirst_preorder { { my unknown $RETURN_TYPE };(my Perl::Structure::Graph::Tree::BinaryReference $self, my Perl::Structure::CodeReference $callback) = @ARG; return $self->{root}->traverse_depthfirst_preorder($callback) if defined($self->{root}); }
44 sub to_nested_arrayrefs { { my arrayref $RETURN_TYPE };(my Perl::Structure::Graph::Tree::BinaryReference $data) = @ARG; return $data->{root}->to_nested_arrayrefs(); }
45  
46  
47 # [[[ BINARY TREES ]]]
48  
49 # ref to binary tree
50 # DEV NOTE: for naming conventions, see DEV NOTE in same code section of LinkedList.pm
51 package # hide from PAUSE indexing
52 binarytreeref;
53 use parent qw(Perl::Structure::Graph::Tree::BinaryReference);
54 use Perl::Structure::Graph::Tree::Binary;
55 our $properties = $properties; our $new_from_nested_arrayrefs = $new_from_nested_arrayrefs; our $traverse_depthfirst_preorder = $traverse_depthfirst_preorder; our $to_nested_arrayrefs = $to_nested_arrayrefs; our $traverse_breadthfirst_queue = $traverse_breadthfirst_queue;
56  
57 # [[[ INT BINARY TREES ]]]
58  
59 # (ref to binary tree) of integers
60 package # hide from PAUSE indexing
61 integer_binarytreeref;
62 use parent qw(binarytreeref);
63 our $properties = $properties; our $new_from_arrayref = $new_from_arrayref; our $binarytree_unshift = $binarytree_unshift; our $DUMPER = $DUMPER;
64  
65 # NEED ADD: remaining sub-types
66  
67 1; # end of class