show_tree -- generate a visualisation of a datatree
use show_tree;
my $tree=[
{
'work' => [ "Do a litte work", "just for funn" ],
'types' => [ "hand", "mashine", "brain" ],
'TREEINFO' => {
'add' => ['work', 'types'],
'name' => 'Do some Work'
}
}
];
show_tree->new($tree)->show();
This modules provides a method to display a DataTree
Example of the structure:
[
{
'tests' => [ "many", "good", "tests" ],
'info' => [ "this is only an test", "you know what i mean" ],
'data' => [
{
'pre' => ["init1", "init2", "init3"],
'after' => ["cleana", "cleanb", "cleanc", "cleand"],
'runn' => ["work1 = OK", "work2 = OK"],
'TREEINFO' => {
'add' => ['pre', 'runn', 'after' ],
'name' => 'TestDATA 1'
}
},
{
'pre' => ["init1", "init2"],
'after' => ["cleanb", "cleanc", "cleand"],
'runn' => ["work1 = FAILD", "work2 = OK"],
'TREEINFO' => {
'add' => ['pre', 'runn', 'after' ],
'name' => 'TestDATA 2'
}
},
],
'TREEINFO' => {
'add' => ['tests', 'info', 'data' ],
'name' => 'Important tests'
}
},
{
'work' => [ "Do a litte work", "just for funn" ],
'types' => [ "hand", "mashine", "brain" ],
'TREEINFO' => {
'add' => ['work', 'types'],
'name' => 'Do some Work'
}
},
]
the example above generates an tree looks like:
+-> Important tests
| +-> tests
| | +-> many
| | +-> good
| | `-> tests
| |
| +-> info
| | +-> this is only an test
| | `-> you know what i mean
| |
| `-> data
| +-> TestDATA 1
| | +-> pre
| | | +-> init1
| | | +-> init2
| | | `-> init3
| | |
| | +-> runn
| | | +-> work1 = OK
| | | `-> work2 = OK
| | |
| | `-> after
| | +-> cleana
| | +-> cleanb
| | +-> cleanc
| | `-> cleand
| |
| |
| `-> TestDATA 2
| +-> pre
| | +-> init1
| | `-> init2
| |
| +-> runn
| | +-> work1 = FAILD
| | `-> work2 = OK
| |
| `-> after
| +-> cleanb
| +-> cleanc
| `-> cleand
|
|
|
|
`-> Do some Work
+-> work
| +-> Do a litte work
| `-> just for funn
|
`-> types
+-> hand
+-> mashine
`-> brain
create an new show_tree object. The only optional option is a AoH refence.
As you can see in the example above the structure is quite variable. The only required Hashelent is "TREEINFO" with a Hashreference as value. The required inherit elemets are "add" and "name" an optional elemnt is "code".
"add" holds a list of names, who should be displaied.
"name" is the Text who is shown as the subtree title.
When "code" is set and the Hashrefrence holds a key, namend same as an elemnt in "add" and the value is a codereference, the value of the namend element will be pased to this code as second paramter. The first parameter is the show_tree object. The "shift line" is the text that stand bevor the new generatet text. This is usefull to change the visualisation.
Example: use Data::Dumper; use show_tree; use strict; use warings;
my $tree=
[
{
'work' => [ "Do a litte work", "just for funn" ],
'data' => [
{
'pre' => ["init1", "init2", "init3"],
'after' => ["cleana", "cleanb", "cleanc", "cleand"],
'runn' => ["work1 = OK", "work2 = OK"],
},
{
'pre' => ["init1", "init2"],
'after' => ["cleanb", "cleanc", "cleand"],
'runn' => ["work1 = FAILD", "work2 = OK"],
},
],
'TREEINFO' => {
'add' => [ 'data', 'work' ],
'name' => 'Look at this',
'code' => { data => sub{
my $self=shift;
my $ref=shift;
return "Data::Dumper: \n".Dumper($ref);
}}
}
}
];
show_tree->new($tree)->show();
this generates an tree like this:
`-> Look at this
+-> Data::Dumper:
| $VAR1 = [
| {
| 'after' => [
| 'cleana',
| 'cleanb',
| 'cleanc',
| 'cleand'
| ],
| 'runn' => [
| 'work1 = OK',
| 'work2 = OK'
| ],
| 'pre' => [
| 'init1',
| 'init2',
| 'init3'
| ]
| },
| {
| 'after' => [
| 'cleanb',
| 'cleanc',
| 'cleand'
| ],
| 'runn' => [
| 'work1 = FAILD',
| 'work2 = OK'
| ],
| 'pre' => [
| 'init1',
| 'init2'
| ]
| }
| ];
|
`-> work
+-> Do a litte work
`-> just for funn
Render the tree. The only optional option is the an string, who is printed at first in evrey line
Set the tree who should be rendered
Set/Get the ASCII elements who are usesd to render the tree.
Allowed names are:
"stepin", "last", "cross", "line", "none" and "child"
the default values are:
stepin = ' ' last = '`' cross = '+' line = '|' none = ' ' child = '-> '
Originally written in 2005 rewrite in 2008 Documentation 2009
Tobias Grönhagen (ToPeG)<mail@topeg.de>
Copyright (C) 2005-2009 ToPeG. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.