Data-TreeDraw
view release on metacpan or search on metacpan
lib/Data/TreeDraw.pm view on Meta::CPAN
$flag_long_struc = 1 if (scalar @{$ref} > 1);
$flag_indent_record[$flag_ind_current_iter] = scalar @{$ref};
}
elsif (ref $ref eq q{HASH}) {
$flag_long_struc = 1 if (scalar (keys %{$ref}) > 1);
$flag_indent_record[$flag_ind_current_iter] = scalar (keys %{$ref});
}
elsif (ref $ref eq q{REF} || ref $ref eq q{SCALAR} || blessed $ref) {
$flag_indent_record[$flag_ind_current_iter] = 1;
}
#y initialise a structure: -1 is ignored on printing but also means that by incrementing we have 0... with all subdata entries
$flag_HowTo[$flag_ind_current_iter] = -1;
my $ref_type = ref $ref;
#y if hash prepend key
my $start = ($key) ? qq{\x27$key\x27=>} : qq{}; # this always gets put in - just is generally empty
#y if list-of-scalars of list-of-lists append appropriate info
my $end = ($flag_lol == 1 && $options{lol} > 0 ) ? &_array_ending($ref,1) # $ending($ref,1) #$end_c_ref->($ref, 1)
: ($flag_long_array == 1 && $options{long_array} == 1) ? &_array_ending($ref,0)
: q{};
#y the basic info for all but REF
my $middle = ($ref_type eq q{REF}) ? q{REFERENCE-TO-REFERENCE} : qq{$ref_type REFERENCE};
$current = qq{${start}$middle ($next_element)$end};
#b set here as the sub iterates multiple times through an array - we only change it back under these circumstances
$flag_now = q{a} ;
$flag_root = q{}.$ref if $count <= 2;
}
}
sub _array_ending {
my ($ref, $which) = @_;
my $rows = scalar @{$ref};
my $end;
#y this is a LoL
if ($which) {
my $col_max = &_lol_max_columns($ref);
$end = qq{ ---LIST OF LISTS--- [ rows = $rows and longest nested list length = $col_max ]};
}
#y this is a long Array of scalars
else {
local $" = q{, };
$end = $rows < $options{array_limit}+1 ? qq{ ---LONG_LIST_OF_SCALARS--- [ length = $rows ]: @{$ref}} : qq{ ---LONG_LIST_OF_SCALARS--- [ length = $rows ] e.g. 0..2: @{$ref}[0..2]};
}
return $end;
}
# incrementation of indent happens here - with $next_element = $ind{$ref}; - $flag_ind_current_iter is simply this value for ease of use
# however they are updated in different places!!! so for short periods are different. $flag_ind_next_iter also same again update at different point
sub _more_flags {
my $ref = shift;
$id{q{}.$ref} = 1;
#y set next_element to the next iterations value
$next_element = $ind{$ref};
$flag_ind_next_iter = $next_element;
$flag_ind_last = $indent;
$last_name = q{}.$ref;
}
# just the same lengh for all atm - should really iterate through columns - i.e. reverse r and c or take transpose...
sub _lol_max_length {
my $max = 0;
my $temp = shift;
for my $r (@{$lol}) {
for my $val (@{$r}) {
$max = length $val if ( length $val > $max)
}
}
return $max;
}
sub _array_max_length {
my $max = 0;
my $temp = shift;
for my $i (@{$temp}) {
$max = length $i if ( length $i > $max)
}
return $max;
}
sub _lol_max_columns {
my $temp = shift;
my @lol_lengths = map { scalar @{$_} } @{$temp};
my $max = shift @lol_lengths;
for (@lol_lengths) { $max = $_ if ($_ > $max) }
return $max;
}
sub _adjust_indent {
my ($ref, $key) = @_;
if ( ( $count > 2 ) && ( ( $flag_long_array == 1 ) || ( $flag_lol == 1 ) ) ) {
for my $i (0..$#flag_indent_record) { $IndArray[$i] = $flag_indent_record[$i] > 0 ? $unit3 : $unit1; }
$IndArray[$flag_ind_next_iter] = $unit2;
}
$flag_long_array = 0;
#y wipe used vars
$lol = undef;
$flag_lol = 0;
$flag_class = undef;
$flag_object = 0;
#y decrement the actual array holding the branch numbers
$flag_indent_record[$flag_ind_next_iter-1]-- if $count > 1;
$count++;
$current = 0;
#b remove old excess parts of the array - i.e. it should never have more entries than the current indent level
if ($count > 2 && $flag_dec == 1 ) {
local $" = q{-};
( run in 0.653 second using v1.01-cache-2.11-cpan-71847e10f99 )