NAME

oEdtk::Restitution - read a value out of nested data with a key path

SYNOPSIS

use oEdtk::Restitution qw(follow_path restitution_value);

my $h = { a => { b => { c => 'value' } } };
follow_path($h, [ 'a', 'b', 'c' ]);          # 'value'
restitution_value($h, [ 'a', 'b' ], 1);      # 'value', quiet

DESCRIPTION

A small path walker used by the templates to pull a value out of a nested structure described by a list of keys. Ported from the 0.8032 fork at S20 of the fork-merge plan.

FUNCTIONS

follow_path

my $value = follow_path($h, $list, $flag_quiet);

Walk $list over $h. A plain (non-reference) key descends into a hash. A code reference is called with the value gathered so far and its result is returned immediately. A missing key returns '' (and prints an INFO line on STDERR unless $flag_quiet is true); a key of any other kind is an error. At the end, an array value is joined with newlines, any other reference is an error, and a plain scalar is returned as is.

restitution_value

my $value = restitution_value($h, $rule, $flag_quiet);

Wrapper for a restitution rule: an undefined rule yields '', a list rule is passed to "follow_path", and anything else is an error.

AUTHOR

The oEdtk team.