The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

App::LXC::Container::Texts - text functions of App::LXC::Container

SYNOPSIS

    # This module should never be used directly!
    # It is used indirectly by the main modules of App::LXC::Container

ABSTRACT

This module contains helper functions for the App::LXC::Container package to deal with texts and support different languages.

DESCRIPTION

The documentation of this module is mainly intended for developers of the package itself.

Basically the module is a singleton providing a set of functions to be used by the other modules of App::LXC::Container.

EXPORT

all functions of this module except language (only used in exactly one location) are exported

FUNCTIONS

language - get or set currently used language

    $language = language($new_language);

example:

    language(substr($ENV{LANG}, 0, 2));

parameters:

    $language           optional new language to be used

description:

This function returns the currently used language. If the optional parameter $new_language is set and a supported language, the language is first changed to that.

returns:

currently used language

fatal - abort with error message

    fatal($message_id, @message_data);

example:

    fatal('unsupported_language__1', $new_language);
    fatal('bad_container_name');

parameters:

    $message_id         ID of the text or format string in language module
    @message_data       optional additional text data for format string

description:

This function looks up the format (or simple) string passed in $message_id in the text hash of the currently used language, formats it together with the @message_data with sprintf and passes it on to croak.

returns:

never

error / warning / info - print error / warning / info message

    error($message_id, @message_data);
    warning($message_id, @message_data);
    info($message_id, @message_data);

example:

    warning('message__1_missing_en', $message_id);

parameters:

    $message_id         ID of the text or format string in language module
    @message_data       optional additional text data for format string

description:

This function looks up the format (or simple) string passed in $message_id in the text hash of the currently used language, formats it together with the @message_data with sprintf and passes it on to carp (in case of errors or warnings) or warn (in case of informational messages).

Note that currently the first two functions only differ semantically. (This may or may not change in the future.)

message - return formatted message

    $string = message($message_id, @message_data);

example:

    $_ = message('can_t_open__1__2', $_, $!);

parameters:

    $message_id         ID of the text or format string in language module
    @message_data       optional additional text data for format string

description:

This function just returns the formatted message for the given $message_id and @message_data, e.g. to be used within a compound widget.

returns:

the formatted message as string

debug - set debugging level or print debugging message

    debug($level);              # sets debugging level
    debug($level, @message);    # prints message

example:

    debug(2);
    debug(1, __PACKAGE__, '::new');

parameters:

    $level              debugging level to be set (>= 0)  or
                        debug-level of the message (>= 1)
    @message            the text to be printed

description:

If only the debugging level (numeric value >= 0) is passed, the debugging level is changed to the given value.

Otherwise the given message is printed on STDERR if the debug-level of the message is less or equal than the previously set debugging level. All messages are prefixed with DEBUG and some blanks according to the debug-level.

txt - look-up text for currently used language

    $message = txt($message_id);

example:

    $_ = sprintf(txt($message_id), @_);

parameters:

    $message_id         ID of the text or format string in language module

description:

This function looks up the format (or simple) string passed in its parameter $message_id in the text hash of the currently used language and returns it.

returns:

looked up string

tabify - replace spaces with tabulators, if feasible

    $string = tabify($string);

parameters:

    $string             input string

description:

This function replaces multiple spaces in a string with a tabulator, whenever this matches a tabulator position (multiple of 8). It then returns the modified string.

returns:

modified string

SEE ALSO

App::LXC::Container

LICENSE

Copyright (C) Thomas Dorner.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See LICENSE file for more details.

AUTHOR

Thomas Dorner <dorner (at) cpan (dot) org>