As Texinfo tree elements are now blessed into the Texinfo::TreeElement
class, this class is output by Data::Dumper when used by
Texinfo::Common::debug_print_tree.  I use this fairly often when developing
and/or debugging.  Sample output:

$VAR1 = bless( {
  'cmdname' => 'node',
  'contents' => [
    bless( {
      'contents' => [
        bless( {
          'contents' => [
            bless( {
              'cmdname' => 'asis',
              'contents' => [
                bless( {
                  'type' => 'brace_container'
                }, 'Texinfo::TreeElement' )
              ]
            }, 'Texinfo::TreeElement' ),
            bless( {
              'text' => ' 2'
            }, 'Texinfo::TreeElement' )
          ],
          'info' => {
            'spaces_after_argument' => bless( {
              'text' => '
',
              'type' => 'spaces_after_argument'
            }, 'Texinfo::TreeElement' )
          },
          'type' => 'line_arg'
        }, 'Texinfo::TreeElement' )
      ],
      'type' => 'arguments_line'
    }, 'Texinfo::TreeElement' )
  ],
  'extra' => {},
  'info' => {
    'spaces_before_argument' => bless( {
      'text' => ' ',
      'type' => 'spaces_before_argument'
    }, 'Texinfo::TreeElement' )
  }
}, 'Texinfo::TreeElement' );

The "bless" function calls with the "Texinfo::TreeElement" arguments
are new.  I couldn't find a way to eliminate the usages of "bless"
by Data::Dumper.  The only way I can think of is to post-process the
output with regular expressions.

Maybe this is not a big problem, as I can use
Texinfo::ManipulateTree::tree_print_details instead (this is the function
used by the test suite, which uses a different, more concise format,
albeit one I'm less familiar with):

*@node C1 {@asis{} 2}
|INFO
|spaces_before_argument:
 |{spaces_before_argument: }
|EXTRA
|is_target:{1}
|node_number:{10}
|normalized:{-2}
 *arguments_line C1
  *line_arg C2
  |INFO
  |spaces_after_argument:
   |{spaces_after_argument:\n}
   *@asis C1
    *brace_container
   { 2}


Incidentally, it is a lot of typing to use Texinfo::Common::debug_print_tree
or Texinfo::ManipulateTree::tree_print_details when you are trying to debug
the program.  I remember that many years ago, print_tree was exported by
default by Texinfo::Common.  I found the following ChangeLog entry from
2022 (I thought it was older):

2022-09-14  Patrice Dumas  <[email protected]>

        * tp/Texinfo/Common.pm: more consistent export ok.  Do not
        export print_tree.  Rename print_tree() as debug_print_tree().
        Rename add_preamble_before_content as _add_preamble_before_content.
        Remove _collect_references, unused and doing something strange.

Although it may make sense from the perspective of abstraction and
encapsulation, it doesn't make sense from the sense of making it easy
to develop the program, in my opinion.  So I think we should consider
exporting a few basic functions by default, so we can again simply write
"warn print_tree($element);" rather than
"warn Texinfo::ManipulateTree::tree_print_details($element);".

Reply via email to