The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Data::Scan::Impl::Printer - Data::Scan printer implementation

VERSION

version 0.009

SYNOPSIS

    use strict;
    use warnings FATAL => 'all';
    use Data::Scan;
    use Data::Scan::Impl::Printer;

    my $this = bless([ 'var1', 'var2', {'a' => 'b', 'c' => 'd'}, \undef, \\undef, [], sub { return 'something' } ], 'TEST');
    my $consumer = Data::Scan::Impl::Printer->new(with_deparse => 1);
    Data::Scan->new(consumer => $consumer)->process($this);

DESCRIPTION

Data::Scan::Impl::Printer is an example of an implementation of the Data::Scan::Role::Consumer role.

CONSTRUCTOR OPTIONS

Here the list of supported options, every name is preceded by its type.

FileHandle handle

Handle for the output. Default is \*STDOUT.

Str indent

Indentation. Default is ' '.

PositiveOrZeroInt max_depth

Maximum unfold level. Default is 0, meaning no maximum.

Str undef

Representation of an undefined value. Default is 'undef'.

Str unknown

Representation of an unknown value. Default is '???'.

Str newline

Separator between lines. Default is "\n".

Bool with_ansicolor

Use ANSI colors. Default is a false value if $ENV{ANSI_COLORS_DISABLED} exists, else a true value if $ENV{ANSI_COLORS_ENABLED} exists, else a false value if Win32::Console::ANSI cannot be loaded and you are on Windows, else a true value.

Str array_start

Representation of the start of an array. Default is '['.

Str array_next

Representation of separator between array elements. Default is ','.

Str array_end

Representation of the end of an array. Default is ']'.

Str hash_start

Representation of the start of a hash. Default is '{'.

Str hash_next

Representation of separator between hash elements, where an element is the tuple {key,value}. Default is ','.

Str hash_end

Representation of the end of a hash. Default is '}'.

Str hash_separator

Representation of hash separator between a key and a value. Default is '=>'.

Str indice_start

Representation of internal indice count start. Default is '['.

Str indice_end

Representation of internal indice count end. Default is ']'.

Bool with_indices_full

Use full internal indice representation, i.e. show indices from the top level up to current level, as if the tree would have been only composed of array references to array references, and so on. Default is a false value.

Str address_start

Representation of the start of an address. Default is '('.

Str address_format

Format of an address. Default is '0x%x'.

Str address_end

Representation of the end of an address. Default is ')'.

Str ref_start

Representation of the start of a reference. Default is '\'.

Str ref_end

Representation of the end of a reference. Default is the empty string.

Bool with_address

Show address of any reference. Default is a false value.

Bool with_array_indice

Show array indices. Default is a true value.

Bool with_hash_indice

Show hash indices. Default is a true value.

Bool with_deparse

Show deparsed subroutine references. Default is a false value.

If deparse raise an exception, the current item is shown as if with_deparse would be off, i.e. a classic stringification resulting in something like e.g. CODE(0x...).

Bool with_methods

Show public, private and inherited methods. Default is a false value.

Bool with_filename

Show loaded or resolved filename. Default is a false value.

Bool buffered

If a true value, bufferize the output and print it only at the end of the processing, otherwise print it item per item, the later is less efficient but also memory-friendly in case of large data. Default is a false value.

HashRef[Str] colors

Explicit ANSI color per functionality. The absence of a color definition means the corresponding value will be printed as-is. A color is defined following the Term::ANSIColor specification, as a string.

Supported keys of this hash and their eventual default setup is:

string => undef

Generic stringified value.

blessed => 'bold'

Blessed name.

regexp => undef

Stringified regexp.

array_start => 'blue'

Array start.

array_next => 'blue'

Separator between array elements.

array_end => 'blue'

Array end.

hash_start => 'blue'

Hash start.

hash_separator => 'blue'

Separator between hash key and value.

hash_next => 'blue'

Separator between a hash value and the next hash key.

hash_end => 'blue'

Hash end.

ref_start => undef

Reference start.

ref_end => undef

Reference end.

indice_full => 'magenta'

Full indice.

indice_start => 'magenta'

Indice start.

indice_value => 'magenta'

Indice value.

indice_end => 'magenta'

Indice end.

undef => 'red'

The undefined value.

unknown => 'bold red'

An unknown value.

address_start => 'magenta'

Address start.

address_value => 'magenta'

Address value.

address_end => 'magenta'

Address end.

code => 'yellow'

Deparsed or stringified code reference.

already_scanned => 'green'

Already scanned reference. Such item will always be represented using "var[...]", where [...] is the full indice representation.

SUBROUTINES/METHODS

dsstart

Will be called when scanning is starting. It is resetting all internal attributes used to keep the context.

dsend

Will be called when scanning is ending. Returns a true value.

dsopen

Called when an unfolded content is opened.

dsclose

Called when an unfolded content is closed.

dsread

Called when an unfolded content is read. Returns eventual unfolded content.

NOTES

If with_methods option is on, Class::Inspector (and not Package::Stash like what does Data::Printer) is used to get public, private and other (labelled inherited, then) methods. Thus, notion of methods, usage of @ISA etc, could look different to what Data::Printer say.

SEE ALSO

B::Deparse, Class::Inspector, Data::Scan::Printer, Term::ANSIColor, Win32::Console::ANSI

AUTHOR

Jean-Damien Durand <jeandamiendurand@free.fr>

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Jean-Damien Durand.

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