NAME

TPath::Forester::Ref - TPath::Forester that understands Perl structs

VERSION

version 0.004

SYNOPSIS

use TPath::Forester::Ref;
use Data::Dumper;

my $ref = {
    a => [],
    b => {
        g => undef,
        h => { i => [ { l => 3, 4 => 5 }, 2 ], k => 1 },
        c => [qw(d e f)]
    }
};

my @hashes = tfr->path(q{//@hash})->dsel($ref);
print scalar @hashes, "\n"; # 3
my @arrays = tfr->path(q{//@array})->dsel($ref);
print scalar @arrays, "\n"; # 3
print Dumper $arrays[2];    # hash keys are sorted alphabetically
# $VAR1 = [
#           {
#             'l' => 3,
#             '4' => 5
#           },
#           2
#         ];

DESCRIPTION

TPath::Forester::Ref adapts TPath::Forester to run-of-the-mill Perl data structures.

METHODS

@array

Whether the node is an array ref.

@can('method')

Attribute that is defined if the node in question has the specified method.

@code

Attribute that is defined if the node is a code reference.

@defined

Attribute that is defined if the node is a defined value.

@does('role')

Attribute that is defined if the node does the specified role.

@glob

Attribute that is defined if the node is a glob reference.

@hash

Attribute that is defined if the node is a hash reference.

@isa('Foo','Bar')

Attribute that is defined if the node instantiates any of the specified classes.

@key

Attribute that returns the hash key, if any, associated with the node value.

@num

Attribute defined for nodes whose value looks like a number according to Scalar::Util.

@obj

Attribute that is defined for nodes holding objects.

@ref

Attribute defined for nodes holding references such as {} or [].

@non-ref

Attribute that is defined for nodes holding non-references -- undef, strings, or numbers.

@repeat or @repeat(1)

Attribute that is defined if the node holds a reference that has occurs earlier in the tree. If a parameter is supplied, it is defined if the node in question is the specified repetition of the reference, where the first instance is repetition 0.

@repeated

Attribute that is defined for any node holding a reference that occurs more than once in the tree.

@scalar

Attribute that is defined for any node holding a scalar reference.

@str

Attribute that is defined for any node holding a string.

@undef

Attribute that is defined for any node holding the undef value.

wrap

Takes a reference and converts it into a tree, overriding TPath::Forester's no-op wrap method.

my $tree = tfr->wrap(
    { foo => bar, baz => [qw(1 2 3 4)], qux => { quux => { corge => undef } } }
);

This is useful if you are going to be doing multiple selections from a single struct and want to use a common index. If you don't use wrap to work off a common object your index will give strange results as it won't be able to find the parents of your nodes.

FUNCTIONS

tfr

Returns singleton TPath::Forester::Ref.

ROLES

TPath::Forester

AUTHOR

David F. Houghton <dfhoughton@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by David F. Houghton.

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