Data::...er::OO(3pm)

πŸ’– Data::TreeDumper::OO β€” the object-oriented glow-up of Data::TreeDumper πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation, and it's literally the manual for Data::TreeDumper::OO, which is the object-oriented era of the whole TreeDumper situation. she's giving main character energy, she's on CPAN, she's ready to dump your data structures in the prettiest way possible. let's get into it πŸŽ€


✨ NAME ✨

Data::TreeDumper::OO β€” Object oriented interface to Data::TreeDumper

like, an actual interface. with objects. we love to see it πŸ’…


🌸 SYNOPSIS 🌸

here's the whole vibe, verbatim, no notes:

  use Data::TreeDumper ;
  use Data::TreeDumper::OO ;

  my $sub = sub {} ;

  my $s =
  {
  A =>
        {
        a =>
                {
                }
        , bbbbbb => $sub
        , c123 => $sub
        , d => \$sub
        }

  , C =>
        {
        b =>
                {
                a =>
                        {
                        a =>
                                {
                                }

                        , b => sub
                                {
                                }
                        , c => 42
                        }

                }
        }
  , ARRAY => [qw(elment_1 element_2 element_3)]
  } ;

  my $dumper = new Data::TreeDumper::OO() ;
  $dumper->UseAnsi(1) ;
  $dumper->SetMaxDepth(2) ;
  $dumper->SetFilter(\&Data::TreeDumper::HashKeysSorter) ;

  print $dumper->Dump($s, "Using OO interface") ;
  print $dumper->DumpMany
          (
            [$s, "title", MAX_DEPTH => 1]
          , [$s2, "other_title", DISPLAY_ADDRESS => 0]
          , USE_ASCII => 1
          , MAX_DEPTH => 5
          ) ;

πŸ¦‹ Output πŸ¦‹

and here's what that actually prints, because the output is honestly kind of iconic:

  title:
  |- A [H1]
  |  |- a [H2]
  |  |- bbbbbb = CODE(0x8139fa0) [C3]
  |  |- c123 [C4 -> C3]
  |  `- d [R5]
  |     `- REF(0x8139fb8) [R5 -> C3]
  |- ARRAY [A6]
  |  |- 0 [S7] = elment_1
  |  |- 1 [S8] = element_2
  |  `- 2 [S9] = element_3
  `- C [H10]
     `- b [H11]
        `- a [H12]
           |- a [H13]
           |- b = CODE(0x81ab130) [C14]
           `- c [S15] = 42

look at those little box-drawing branches. tree. so satisfying. 🌈


πŸ‘‘ DESCRIPTION πŸ‘‘

Object oriented interface to Data::TreeDumper.

that's the whole pitch, fr fr. it's Data::TreeDumper but you hold a $dumper object and call methods on it instead of passing a million arguments around like a feral gremlin. slay.

πŸ’œ Object oriented Methods πŸ’œ

okay this is the good part, the whole menu of things you can call. copy-paste this energy:

  # constructor
  my $dumper = new Data::TreeDumper::OO(MAX_DEPTH => 1) ;

  $dumper->UseAnsi(1) ;
  $dumper->UseAscii(1) ;
  $dumper->SetMaxDepth(2) ;
  $dumper->SetIndentation('   ') ;
  $dumper->SetVirtualWidth(80) ;
  $dumper->SetFilter(\&Data::TreeDumper::HashKeysSorter) ;
  $dumper->SetLevelFilters({1 => \&Filter_1, 5 => \&Filter_5) ;
  $dumper->SetStartLevel(0) ;
  $dumper->QuoteHashKeys(1) ;
  $dumper->QuoteValues(0) ;
  $dumper->DisplayNoElements(1) ;
  $dumper->DisplayRootAddress(1) ;
  $dumper->DisplayAddress(0) ;
  $dumper->DisplayObjectType(0) ;
  $dumper->Displayinheritance(0) ;
  $dumper->DisplayAutoload(0) ;
  $dumper->DisplayTie(0) ;
  $dumper->DisplayPerlAddress(1) ;
  $dumper->DisplayPerlSize(0) ;
  $dumper->NumberLevels(2) ;
  $dumper->ColorLevels(\&ColorLevelSub) ;
  $dumper->SetGlyphs(['.  ', '.  ', '.  ', '.  ']) ;
  $dumper->NoOutput(1) ;
  $dumper->SetRenderer('DHTML') ;

  $dumper->Dump($s, "Using OO interface", %OVERRIDES) ;
  $dumper->DumpMany
            (
              [$s, "dump1", %OVERRIDES]
            , [$s, "dump2", %OVERRIDES]
            , %OVERRIDES
            ) ;

so yeah β€” you make a $dumper, you set all your settings with method calls (ansi or ascii, max depth, indentation, virtual width, filters, level filters, start level, quoting, all the Display* toggles, perl address, perl size, numbering, colors, glyphs, no-output, renderer...), and then you Dump one thing or DumpMany a whole list of things with per-item %OVERRIDES and global %OVERRIDES on top. chef's kiss. 🫢


πŸŽ€ DEPENDENCY πŸŽ€

Data::TreeDumper.

that's it. she needs her base class to exist. that's the whole relationship. πŸ’–


🧚 EXPORT 🧚

None.

nothing. zero. we don't do that here. it's OO, babes. you call methods. πŸ™ˆ


⭐ SEE ALSO ⭐

  • Data::TreeDumper β€” the base class for this module. that's the mothership, the blueprint, the OG.
  • Data::Dumper β€” convert perl data values or variables to equivalent Perl syntax.
  • Data::Dumper::GUI β€” a graphical interface on top of Data::Dumper.
  • Data::Dumper::Sorted β€” like Data::Dumper but sorts hash keys into alphabetic order.
  • Data::Dumper::HTML β€” dump data into HTML with syntax highlighting.
  • Data::Dumper::Simple and Data::Dumper::Names work like Data::Dumper but include the original variable names in the output.
  • Data::Dumper::Perltidy β€” combines Data::Dumper and Perl::Tidy to stringify data in a pretty-printed format.
  • Text::Tree::Indented β€” format tree data in an indented tree format, using ASCII or box-rule characters.

a whole family reunion. the Data::Dumper cinematic universe. πŸ“


🌈 REPOSITORY 🌈

the code lives over at:

<https://github.com/neilbowers/Data-TreeDumper-OO>

go say hi, maybe star it, iykyk ⭐


πŸ’œ AUTHOR πŸ’œ

Khemir Nadim ibn Hamouda. <nadim@khemir.net>


Copyright (c) 2003-2014 Nadim Ibn Hamouda el Khemir. All rights reserved.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

If you find any value in this module, mail me! All hints, tips, flames and wishes are welcome at <nadim@khemir.net>.

not the author personally asking for flames in the year of our lord 😭 respect though, honestly, that's transparency.


okay so that's the whole page bestie, you're basically a Data::TreeDumper::OO expert now, no cap πŸ’…βœ¨

perl v5.32.1 Β· 2021-09-26 β€” that's the version and date this page was last touched, so if you're reading this on a newer perl, consider that your official timestamped sign-off. bye babes, go dump some trees πŸ¦‹πŸ’–πŸŒΈ

πŸ“¦ where this page comes from