Date::Dump::Tree::LayHorizontal - layout data in horizontal or column mode
NAME
Date::Dump::Tree::LayHorizontal - layout data in horizontal or column mode
SYNOPSIS
use Data::Dump::Tree ;
ddt $some_complex_data, :flat(Array) ;
See examples/flat.pl in the distribution for multiple examples
Renders data elements matching :flat conditions in a horizontal or columns layout ; this allows you to mix vertical and horizontal layout in the same rendering.
Horizontal layout
Vertical layout:
(6) @0
โ 0 = [3] @1
โ โ 0 = [2] @2
โ โ โ 0 = 1.Int
โ โ โ 1 = [2] @3
โ โ โ 0 = 2.Int
โ โ โ 1 = [2] @4
โ โ โ 0 = 3.Int
โ โ โ 1 = 4.Int
โ โ 1 = (1) @5
โ โ โ 0 = [2] @6
โ โ โ 0 = 6.Int
โ โ โ 1 = [1] @7
โ โ โ 0 = 3.Int
โ โ 2 = [2] ยง2
โ 1 = [2] @9
โ โ 0 = [2] ยง2
โ โ 1 = [2] ยง2
โ 2 = [2] @12
โ โ 0 = [2] @13
โ โ โ 0 = 1.Int
โ โ โ 1 = 2.Int
โ โ 1 = .Seq(11) @14
โ โ 0 = [2] ยง2
โ โ 1 = [2] ยง2
โ โ 2 = [2] ยง2
โ โ 3 = [2] ยง2
โ โ 4 = [2] ยง2
โ โ 5 = [2] ยง2
โ โ 6 = [2] ยง2
โ โ 7 = [2] ยง2
โ โ 8 = [2] ยง2
โ โ 9 = [2] ยง2
โ โ ...
โ 3 = [10] @25
โ โ 0 = [2] ยง2
โ โ 1 = [2] ยง2
โ โ 2 = [2] ยง13
โ โ 3 = [3] @29
โ โ โ 0 = 1.Int
โ โ โ 1 = 2.Int
โ โ โ 2 = 3.Int
โ โ 4 = [2] ยง2
โ โ 5 = [2] ยง2
โ โ 6 = [2] ยง2
โ โ 7 = [2] ยง2
โ โ 8 = [2] ยง2
โ โ 9 = [2] ยง2
โ 4 = [2] ยง12
โ 5 = 12345678.Str
dd's output for comparison:
$($[[1, [2, [3, 4]]], ([6, [3]],), [1, [2, [3, 4]]]], [[1, [2, [3, 4]]], [1, [2, [3
, 4]]]], $[[1, 2], ([1, [2, [3, 4]]], [1, [2, [3, 4]]], [1, [2, [3, 4]]], [1, [2, [
3, 4]]], [1, [2, [3, 4]]], [1, [2, [3, 4]]], [1, [2, [3, 4]]], [1, [2, [3, 4]]], [1
, [2, [3, 4]]], [1, [2, [3, 4]]], [1, [2, [3, 4]]]).Seq], [[1, [2, [3, 4]]], [1, [2
, [3, 4]]], [1, 2], [1, 2, 3], [1, [2, [3, 4]]], [1, [2, [3, 4]]], [1, [2, [3, 4]]]
, [1, [2, [3, 4]]], [1, [2, [3, 4]]], [1, [2, [3, 4]]]], $[[1, 2], ([1, [2, [3, 4]]
], [1, [2, [3, 4]]], [1, [2, [3, 4]]], [1, [2, [3, 4]]], [1, [2, [3, 4]]], [1, [2,
[3, 4]]], [1, [2, [3, 4]]], [1, [2, [3, 4]]], [1, [2, [3, 4]]], [1, [2, [3, 4]]], [
1, [2, [3, 4]]]).Seq], "12345678")
Rendered horizontally with :flat(0)
(6) @0
0 = [3] @1 1 = [2] @9 2 = [2] @12 3 = [10] @25
โ 0 = [2] @2 โ 0 = [2] ยง2 โ 0 = [2] @13 โ 0 = [2] ยง2
โ โ 0 = 1.Int โ 1 = [2] ยง2 โ โ 0 = 1.Int โ 1 = [2] ยง2
โ โ 1 = [2] @3 โ โ 1 = 2.Int โ 2 = [2] ยง13
โ โ 0 = 2.Int โ 1 = .Seq(11) @14 โ 3 = [3] @29
โ โ 1 = [2] @4 โ 0 = [2] ยง2 โ โ 0 = 1.Int
โ โ 0 = 3.Int โ 1 = [2] ยง2 โ โ 1 = 2.Int
โ โ 1 = 4.Int โ 2 = [2] ยง2 โ โ 2 = 3.Int
โ 1 = (1) @5 โ 3 = [2] ยง2 โ 4 = [2] ยง2
โ โ 0 = [2] @6 โ 4 = [2] ยง2 โ 5 = [2] ยง2
โ โ 0 = 6.Int โ 5 = [2] ยง2 โ 6 = [2] ยง2
โ โ 1 = [1] @7 โ 6 = [2] ยง2 โ 7 = [2] ยง2
โ โ 0 = 3.Int โ 7 = [2] ยง2 โ 8 = [2] ยง2
โ 2 = [2] ยง2 โ 8 = [2] ยง2 โ 9 = [2] ยง2
โ 9 = [2] ยง2
โ ...
4 = [2] ยง12 5 = 12345678.Str
Column layout
If you just flatten, the elements will be rendered after each other. If it reaches the maximum width, a new row is started.
In the example below you can see how the elements of the Array are listed after each other.
While listing Hashes is better horizontally, Arrays tend to look better in columns layout giving them a table look.
:flat(Array)
(3) @0
โ 0 = [10] @1
โ 0 = 1.Int 1 = 2.Int 2 = 3.Int 3 = 4.Int 4 = 5.Int 5 = 6.Int
โ 6 = 7.Int 7 = 8.Int 8 = 9.Int 9 = 10.Int
โ
โ 1 = [11] @2
โ 0 = 1.Int 1 = 2.Int 2 = 3.Int 3 = 4.Int 4 = 5.Int 5 = 6.Int
โ 6 = 7.Int 7 = 8.Int 8 = 9.Int 9 = 10.Int 10 = [10] @3
โ โ 0 = 1.Int
โ โ 1 = 2.Int
โ โ 2 = 3.Int
โ โ 3 = 4.Int
โ โ 4 = 5.Int
โ โ 5 = 6.Int
โ โ 6 = 7.Int
โ โ 7 = 8.Int
โ โ 8 = 9.Int
โ โ 9 = 10.Int
โ
โ 2 = {2} @4
โ a => 1 / "1".IntStr
โ b => 2 / "2".IntStr
Rather then listing all the elements after each other, you can ask for sets of elements to be rendered in columnar layout and then after each other.
:flat((Array,5),
(3) @0
โ 0 = [10] @1
โ 0 = 1.Int 5 = 6.Int
โ 1 = 2.Int 6 = 7.Int
โ 2 = 3.Int 7 = 8.Int
โ 3 = 4.Int 8 = 9.Int
โ 4 = 5.Int 9 = 10.Int
โ
โ 1 = [11] @2
โ 0 = 1.Int 5 = 6.Int 10 = [10] @3
โ 1 = 2.Int 6 = 7.Int โ 0 = 1.Int
โ 2 = 3.Int 7 = 8.Int โ 1 = 2.Int
โ 3 = 4.Int 8 = 9.Int โ 2 = 3.Int
โ 4 = 5.Int 9 = 10.Int โ 3 = 4.Int
โ โ 4 = 5.Int
โ โ 5 = 6.Int
โ โ 6 = 7.Int
โ โ 7 = 8.Int
โ โ 8 = 9.Int
โ โ 9 = 10.Int
โ
โ 2 = {2} @4
โ a => 1 / "1".IntStr
โ b => 2 / "2".IntStr
INTERFACE
:flat(...)
:flat takes a list of conditions and options to allow you to control what is flattened.
Conditions
blocks: :flat({ $_ ~~ Array && $_.elems > 15 }, ...)
You can pass Blocks to :flat, they are called for each object in your data structure,this lets you dynamically choose if you want the data in horizontal , columns or vertical layout.
In the above example Arrays with more than 15 elements are flattened.
Inside your block:
=over 2
$_ is a reference to the data being rendered
$*d is the depth at which the data is
=back
The pointy block returns list of three elements
=over 2
Bool, lay flat or not
Int, nuber of rows in a colums
Int, minimum width of an entry
=back
integer: :flat(0) or :flat
Will flatten at the given level in your data structure.
object: :flat($object, $object2, ..)
If $object, $object2, ... are found in the data structure, they will be flattened, this allows a selective flattening.
object type: :flat(Array, List, ...)
Will flatten any object in your data structure that matches one of the types passed as a condition. Flattening Hashes looks particularly good.
other conditions are smart-matched
Columns
Splitting uses the same interface as the conditions but rather than pass a condition, you pass a list consisting of a condition and split value.
ddt $data, :flat(Array) ;
ddt $data, :flat( (Array, 5) ) ;
Sub conditions can dynamically return a split value.
ddt $data, :flat( { $_ ~~ Array andthen True, 5} )
You can also pass a minimum column value:
ddt $data, :flat( { $_ ~~ Array andthen True, 5, 10} )
AUTHOR
Nadim ibn hamouda el Khemir https://github.com/nkh
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl6 itself.
SEE-ALSO
Data::Dump::Tree