NAME
Gnuplot::Builder::PrototypedData - generic prototype-based object
DESCRIPTION
This is an internal module for Gnuplot::Builder distribution. End-users should not rely on this module.
Gnuplot::Builder::PrototypedData is a generic data structure depicted below.
PrototypedData
|
+--PartiallyKeyedList--+--entry
| +--entry
| +--...
|
+--attributes--{ key => value ... }
|
+--parent
It contains a Gnuplot::Builder::PartiallyKeyedList and a hash. The hash is called "attributes" here.
It supports prototype-based inheritance for both PartiallyKeyedList and attributes.
Entries and attribute values can be code-ref. If an "evaluator" is provided for the entries or attributes, the code-ref is automatically evaluated when you try to get the value. If there is no evaluator for the entry or attribute, it just returns the code-ref.
CLASS METHODS
$pdata = Gnuplot::Builder::PrototypedData->new(%args)
In %args
:
entry_evaluator
=> CODE-
The evaluator for PKL entries. It is called like:
@result = $evaluator->($key, $value_code_ref)
For non-keyed entries,
$key
isundef
. attribute_evaluator
=> HASH-
The key-evaluator pairs for attributes.
{ $attribute_name => $evaluator } ($result) = $evaluator->($attribute_name, $value_code_ref)
OBJECT METHODS
$pdata->set_entry(%args)
Set PKL entry. In %args
,
entries
=> ARRAY-REF (mandatory)-
Array-ref of entry settings. If it contains a single string, the string is parsed. Otherwise it must be a flat array of key-value pairs.
key_prefix
=> STR (optional, default: "")-
Prefix prepended to the keys.
quote
=> BOOL (optional, default: false)-
If true, the values are quoted.
$pdata->add_entry(@entries)
@values = $pdata->get_resolved_entry($key)
Get the values from the PKL. It resolves inheritance and evaluates code-ref values. If there is no such key in $pdata
or any of its ancestors, it returns an empty list.
$value = $pdata->get_resolved_entry($key)
In scalar context, get_resolved_entry()
returns the first value for $key
. If it would return an empty list in list context, it returns undef
in scalar context.
$pdata->each_resolved_entry($code)
Iterate over resolved PKL entries.
$code->($key, $resolved_values_array_ref)
$pdata->delete_entry($key)
$exists = $pdata->has_own_entry($key)
$pdata->set_attribute(%args)
Set an attribute value. Fields in %args
are
$value = $pdata->get_resolved_attribute($name)
Get the attribute value for the $name
. It resolves inheritance and evaluates code-ref values if the corresponding evaluator exists. It returns undef
if it cannot find the name anywhere.
$exists = $pdata->has_own_attribute($name)
$pdata->delete_attribute($name)
$pdata->set_parent($parent)
$parent = $pdata->get_parent()
AUTHOR
Toshio Ito, <toshioito at cpan.org>