Jed Lund > Data-Walk-Extracted > Data::Walk::Print

Download:
Data-Walk-Extracted-0.024.004.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: v0.24.4   Source  

NAME ^

Data::Walk::Print - A data printing function

SYNOPSIS ^

        #!perl
        use YAML::Any;
        use Moose::Util qw( with_traits );
        use Data::Walk::Extracted;
        use Data::Walk::Print;

        #Use YAML to compress writing the data ref
        my  $firstref = Load(
                '---
                Someotherkey:
                        value
                Parsing:
                        HashRef:
                                LOGGER:
                                        run: INFO
                Helping:
                        - Somelevel
                        - MyKey:
                                MiddleKey:
                                        LowerKey1: lvalue1
                                        LowerKey2:
                                                BottomKey1: 12345
                                                BottomKey2:
                                                - bavalue1
                                                - bavalue2
                                                - bavalue3'
        );
        my  $secondref = Load(
                '---
                Someotherkey:
                        value
                Helping:
                        - Somelevel
                        - MyKey:
                                MiddleKey:
                                        LowerKey1: lvalue1
                                        LowerKey2:
                                                BottomKey2:
                                                - bavalue1
                                                - bavalue3
                                                BottomKey1: 12354'
        );
        my $AT_ST = with_traits( 
                        'Data::Walk::Extracted', 
                        ( 'Data::Walk::Print' ),
                )->new(
                        match_highlighting => 1,#This is the default
                );
        $AT_ST->print_data(
                print_ref       =>  $firstref,
                match_ref       =>  $secondref, 
                sorted_nodes =>{
                        HASH => 1, #To force order for demo purposes
                }
        );
    
        #################################################################################
        #     Output of SYNOPSIS
        # 01:{#<--- Ref Type Match
        # 02:   Helping => [#<--- Secondary Key Match - Ref Type Match
        # 03:           'Somelevel',#<--- Secondary Position Exists - Secondary Value Matches
        # 04:           {#<--- Secondary Position Exists - Ref Type Match
        # 05:                   MyKey => {#<--- Secondary Key Match - Ref Type Match
        # 06:                           MiddleKey => {#<--- Secondary Key Match - Ref Type Match
        # 07:                                   LowerKey1 => 'lvalue1',#<--- Secondary Key Match - Secondary Value Matches
        # 08:                                   LowerKey2 => {#<--- Secondary Key Match - Ref Type Match
        # 09:                                           BottomKey1 => '12345',#<--- Secondary Key Match - Secondary Value Does NOT Match
        # 10:                                           BottomKey2 => [#<--- Secondary Key Match - Ref Type Match
        # 11:                                                   'bavalue1',#<--- Secondary Position Exists - Secondary Value Matches
        # 12:                                                   'bavalue2',#<--- Secondary Position Exists - Secondary Value Does NOT Match
        # 13:                                                   'bavalue3',#<--- Secondary Position Does NOT Exist - Secondary Value Does NOT Match
        # 14:                                           ],
        # 15:                                   },
        # 16:                           },
        # 17:                   },
        # 18:           },
        # 19:   ],
        # 20:   Parsing => {#<--- Secondary Key Mismatch - Ref Type Mismatch
        # 21:           HashRef => {#<--- Secondary Key Mismatch - Ref Type Mismatch
        # 22:                   LOGGER => {#<--- Secondary Key Mismatch - Ref Type Mismatch
        # 23:                           run => 'INFO',#<--- Secondary Key Mismatch - Secondary Value Does NOT Match
        # 24:                   },
        # 25:           },
        # 26:   },
        # 27:   Someotherkey => 'value',#<--- Secondary Key Match - Secondary Value Matches
        # 28:},
        #################################################################################

DESCRIPTION ^

This Moose::Role is mostly written as a demonstration module for Data::Walk::Extracted. Both Data::Dumper - Dumper and YAML - Dump functions are more mature than the printing function included here.

USE

This is a Moose::Role specifically designed to be used with Data::Walk::Extracted . It can be combined traditionaly to the ~::Extracted class using Moose methods or for information on how to join this role to Data::Walk::Extracted at run time see Moose::Util or MooseX::ShortCut::BuildInstance for more information.

Attributes ^

Data passed to ->new when creating an instance. For modification of these attributes see Methods. The ->new function will either accept fat comma lists or a complete hash ref that has the possible attributes as the top keys. Additionally some attributes that have all the following methods; get_$attribute, set_$attribute, has_$attribute, and clear_$attribute, can be passed to print_data and will be adjusted for just the run of that method call. These are called 'one shot' attributes. The class and each role (where applicable) in this package have a list of supported one shot attributes .

match_highlighting

Definition: this determines if a comments string is added after each printed row that indicates how the 'print_ref' matches the 'match_ref'.

Default True (1)

Range This is a Boolean data type and generally accepts 1 or 0

to_string

Definition: this determines whether the output is sent to STDOUT or coallated into a final string and sent as a result of print_data .

Default True (1)

Range This is a Boolean data type and generally accepts 1 or 0

(see also)

Data::Walk::Extracted - Attributes

Methods ^

print_data( $arg_ref|%args|$data_ref )

Definition: this is the method used to print a data reference

Accepts: either a single data reference or named arguments in a fat comma list or hashref

named variable option - if data comes in a fat comma list or as a hash ref and the keys include a 'print_ref' key then the list is processed as follows.

print_ref - this is the data reference that should be printed in a perlish way - Required

match_ref - this is a reference used to compare against the 'print_ref' - Optional

[attribute name] - attribute names are accepted with temporary attribute settings. These settings are temporarily set for a single "print_data" call and then the original attribute values are restored. For this to work the the attribute must meet the necessary criteria. These attributes can include all attributes active for the constructed class not just this role.

single variable option - if only one data_ref is sent and it fails the test for "exists $data_ref->{print_ref}" then the program will attempt to name it as print_ref => $data_ref and then process the data as a fat comma list.

Returns: 1 (And prints out the data ref) or a string - see to_string

set_match_highlighting( $bool )

Definition: this is a way to change the match_highlighting attribute

Accepts: a Boolean value

Returns: ''

get_match_highlighting

Definition: this is a way to view the state of the match_highlighting attribute

Accepts: nothing

Returns: The current 'match_highlighting' state

has_match_highlighting

Definition: this is a way to know if the match_highlighting attribute is active

Accepts: nothing

Returns: 1 if the attribute is active (not just if it == 1)

clear_match_highlighting

Definition: this clears the match_highlighting attribute

Accepts: nothing

Returns: '' (always successful)

set_to_string( $bool )

Definition: this is a way to change the to_string attribute

Accepts: a Boolean value

Returns: ''

get_to_string

Definition: this is a way to view the state of the to_string attribute

Accepts: nothing

Returns: The current 'to_string' state

has_to_string

Definition: this is a way to know if the to_string attribute is active

Accepts: nothing

Returns: 1 if the attribute is active (not just if it == 1)

clear_to_string

Definition: this clears the to_string attribute

Accepts: nothing

Returns: '' (always successful)

Caveat utilitor ^

Supported Node types

ARRAY
HASH
SCALAR
UNDEF

Supported one shot attributes

explanation

match_highlighting
to_string

Printing for skipped nodes

Data::Walk::Extracted allows for some nodes to be skipped. When a node is skipped the print_data function prints the scalar (perl pointer description) of that node.

GLOBAL VARIABLES ^

$ENV{Smart_Comments}

The module uses Smart::Comments if the '-ENV' option is set. The 'use' is encapsulated in an if block triggered by an environmental variable to comfort non-believers. Setting the variable $ENV{Smart_Comments} in a BEGIN block will load and turn on smart comment reporting. There are three levels of 'Smartness' available in this module '###', '####', and '#####'.

SUPPORT ^

github Data-Walk-Extracted/issues

TODO ^

1. Convert from Smart::Comments debugging to Log::Shiras debugging messages.

2. Support printing Objects / Instances

3. Support printing CodeRefs

4. Support REF types

AUTHOR ^

Jed Lund
jandrew@cpan.org

COPYRIGHT ^

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

The full text of the license can be found in the LICENSE file included with this module.

This software is copyrighted (c) 2013 by Jed Lund.

Dependencies ^

version

Moose::Role

requires

_process_the_data
_get_had_secondary
_dispatch_method

MooseX::Types::Moose

Data::Walk::Extracted

Data::Walk::Extracted::Dispatch

SEE ALSO ^

Smart::Comments - is used if the -ENV option is set

Data::Walk

Data::Walker

Data::Dumper - Dumper

YAML - Dump

Data::Walk::Prune - available Data::Walk::Extracted Role

Data::Walk::Graft - available Data::Walk::Extracted Role

Data::Walk::Clone - available Data::Walk::Extracted Role

syntax highlighting: