NAME

Lib::Pepper::OptionList - Object-oriented wrapper for Pepper option lists

SYNOPSIS

use Lib::Pepper::OptionList;

# Create a new option list
my $options = Lib::Pepper::OptionList->new();

# Add values
$options->addString('sHostName', '192.168.1.100:20007');
$options->addInt('iTerminalType', 118);
$options->addInt('iAmount', 10_050);  # 100.50 EUR in cents

# Create nested option list
my $childOptions = Lib::Pepper::OptionList->new();
$childOptions->addString('sValue', 'test');
$options->addChild('hChild', $childOptions);

# Retrieve values
my $hostname = $options->getString('sHostName');
my $amount = $options->getInt('iAmount');
my $child = $options->getChild('hChild');

# Convert to/from hashref
my $hashref = $options->toHashref();
my $newOptions = Lib::Pepper::OptionList->fromHashref($hashref);

# Get list of all keys
my $elements = $options->getElementList();

DESCRIPTION

Lib::Pepper::OptionList provides an object-oriented interface to Pepper option lists. Option lists are key-value stores used throughout the Pepper API for passing configuration and receiving results.

This class wraps the low-level XS functions and provides convenient methods for working with option lists, including conversion to/from Perl hashrefs.

METHODS

new([$handle])

Constructor. Creates a new option list or wraps an existing handle.

my $options = Lib::Pepper::OptionList->new();           # Create new
my $wrapped = Lib::Pepper::OptionList->new($handle);    # Wrap existing

Parameters: - $handle: Optional. Existing option list handle to wrap.

Returns: Lib::Pepper::OptionList object

getHandle()

Returns the underlying C handle for this option list.

my $handle = $options->getHandle();

Returns: Integer handle value

getString($key)

Retrieves a string value from the option list.

my $hostname = $options->getString('sHostName');

Parameters: - $key: The option key to retrieve

Returns: String value

Throws: Exception if key not found or wrong type

getInt($key)

Retrieves an integer value from the option list.

my $amount = $options->getInt('iAmount');

Parameters: - $key: The option key to retrieve

Returns: Integer value

Throws: Exception if key not found or wrong type

getChild($key)

Retrieves a child option list.

my $child = $options->getChild('hTicket');

Parameters: - $key: The option key to retrieve

Returns: Lib::Pepper::OptionList object

Throws: Exception if key not found or wrong type

addString($key, $value)

Adds a string value to the option list.

$options->addString('sPosNumber', 'POS-001');

Parameters: - $key: The option key - $value: The string value

Returns: $self (for method chaining)

addInt($key, $value)

Adds an integer value to the option list.

$options->addInt('iAmount', 10_000);

Parameters: - $key: The option key - $value: The integer value

Returns: $self (for method chaining)

addChild($key, $childOptionList)

Adds a child option list.

my $child = Lib::Pepper::OptionList->new();
$child->addString('sValue', 'test');
$options->addChild('hChild', $child);

Parameters: - $key: The option key - $childOptionList: Lib::Pepper::OptionList object

Returns: $self (for method chaining)

getElementList()

Returns an array reference of all keys in the option list.

my $keys = $options->getElementList();
for my $key (@$keys) {
    print "Key: $key\n";
}

Returns: Array reference of key strings

toHashref()

Converts the option list to a Perl hashref. Nested option lists become nested hashes.

my $hashref = $options->toHashref();

Returns: Hash reference

fromHashref($hashref)

Class method. Creates a new option list from a Perl hashref. Values are automatically typed (integer vs string). Nested hashes become child option lists.

my $options = Lib::Pepper::OptionList->fromHashref({
    sHostName => '192.168.1.100:20007',
    iAmount => 10_000,
    hConfig => {
        sValue => 'test',
    },
});

Parameters: - $hashref: Hash reference to convert

Returns: New Lib::Pepper::OptionList object

NAMING CONVENTIONS

Pepper option list keys use Hungarian notation prefixes:

- s: String values (e.g., sHostName, sPosNumber) - i: Integer values (e.g., iAmount, iTerminalType) - h: Handle/child option lists (e.g., hTicket, hConfig)

WARNING: AI USE

Warning, this file was generated with the help of the 'Claude' AI (an LLM/large language model by the USA company Anthropic PBC) in November 2025. It was not reviewed line-by-line by a human, only on a functional level. It is therefore not up to the usual code quality and review standards. Different copyright laws may also apply, since the program was not created by humans but mostly by a machine, therefore the laws requiring a human creative process may or may not apply. Laws regarding AI use are changing rapidly. Before using the code provided in this file for any of your projects, make sure to check the current version of your local laws.

AUTHOR

Rene Schickbauer, <cavac@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2025 by Rene Schickbauer

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.42.0 or, at your option, any later version of Perl 5 you may have available.