Treemap/Strip.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 70 CC 3 SCAR 16.7
CC
3
Cov
0%
map
12.0
new
2.0
BEGIN
2.0
CRAP 5.3
1 package Treemap::Strip;
2  
3 use 5.006;
4 use strict;
5 use warnings;
6 use Carp;
7  
8 require Exporter;
9  
10 our @ISA = qw(Exporter Treemap);
11 our @EXPORT_OK = ( );
12 our @EXPORT = qw( );
13 our $VERSION = '0.01';
14  
15  
16 # ------------------------------------------
17 # Methods:
18 # ------------------------------------------
19  
20  
21 # ------------------------------------------
22 # new() - Create and return new Treemap
23 # object:
24 # ------------------------------------------
25 sub new
26 {
27 my $proto = shift;
28 my $class = ref( $proto ) || $proto;
29 my $self = {};
30  
31 # set default "draw" functions
32 $self->{ RECT } = \▭
33 $self->{ TEXT } = \&text;
34  
35 bless $self, $class;
36 return $self;
37 }
38  
39 sub map
40 {
41 my $self = shift;
42 my ( @p, @q, $tree, $o );
43 ( $tree, $p[0], $p[1], $q[0], $q[1], $o ) = @_;
44 $o = $o || 0; # Orientation of our slicing
45  
46 # Draw our rectangle
47 &{$self->{ RECT }}( $p[0], $p[1], $q[0], $q[1], $tree->{colour} );
48  
49 # Non-empty Set, Descend
50 if( $tree->{children} )
51 {
52 my @r = @p;
53 my @s = @q;
54 my $width = abs($p[$o] - $q[$o]);
55 my $size = $tree->{size};
56  
57 # Process each child
58 foreach my $child( @{$tree->{children}} )
59 {
60 # Give this child a percentage of the parent's space, based on
61 # parent's size (make sure we don't cause divide by zero errors)
62 $s[$o] = $r[$o] + $width * ( $child->{size} / $size ) if ( $size > 0 );
63  
64 # Rotate the space by 90 degrees, by xor'ing the 'o'rientation
65 $self->map( $child, $r[0], $r[1], $s[0], $s[1], ($o xor 1) );
66 $r[$o] = $s[$o];
67 }
68 }
69 # Draw label
70 # &{ $self->{ TEXT } }( $tree->{name} );
71 }
72  
73  
74 1;
75  
76 __END__