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::MonM::Util - Internal utilities

VERSION

Version 1.02

SYNOPSIS

    use App::MonM::Util qw/
            explain expire_calc
        /;

    print explain( $object );

DESCRIPTION

Internal utilities

FUNCTIONS

explain
    print explain( $object );

Returns Data::Dumper dump

blue, cyan, green, red, yellow, magenta, gray
    print cyan("Format %s", "text");

Returns colored string

nope, skip, wow, yep
    my $status = nope("Format %s", "text");

Prints status message and returns status.

For nope returns - 0; for skip, wow, yep - 1

getCheckitByName
    my $checkits = getCheckitByName($app->config("checkit"), "foo", "bar");

Returns list of normalized the "checkit" config sections by name

getExpireOffset
    print getExpireOffset("+1d"); # 86400
    print getExpireOffset("-1d"); # -86400

Returns offset of expires time (in secs).

Original this function is the part of CGI::Util::expire_calc!

This internal routine creates an expires time exactly some number of hours from the current time. It incorporates modifications from Mark Fisher.

format for time can be in any of the forms:

    now   -- expire immediately
    +180s -- in 180 seconds
    +2m   -- in 2 minutes
    +12h  -- in 12 hours
    +1d   -- in 1 day
    +3M   -- in 3 months
    +2y   -- in 2 years
    -3m   -- 3 minutes ago(!)

If you don't supply one of these forms, we assume you are specifying the date yourself

getTimeOffset
    my $off = getTimeOffset("1h2m24s"); # 4344
    my $off = getTimeOffset("1h 2m 24s"); # 4344

Returns offset of time (in secs)

getBit
    print getBit(123, 3) ? "SET" : "UNSET"; # UNSET

Getting specified Bit

header_field_normalize
    print header_field_normalize("content-type"); # Content-Type

Returns normalized header field

merge
    my $a = {a => 1, c => 3, d => { i => 2 }, r => {}};
    my $b = {b => 2, a => 100, d => { l => 4 }};
    my $c = merge($a, $b);
    # $c is {a => 100, b => 2, c => 3, d => { i => 2, l => 4 }, r => {}}

Recursively merge two or more hashes, simply

This code was taken from Hash::Merge::Simple (Thanks, Robert Krimen)

node2anode
    my $anode = node2anode({});

Returns array of nodes

parsewords
    my @b = parsewords("foo,bar baz"); # qw/foo bar baz/

Parses string and split it by words. See "quotewords" in Text::ParseWords

run_cmd
    my $hash = run_cmd($command, $timeout, $stdin);

Wrapped "run_forked" in IPC::Cmd function

This function returns hash:

    {
        'cmd'     => 'perl -w',
        'code'    => 0, # Exit code (errorlevel)
        'message' => 'OK', # OK/ERROR
        'pgid'    => 176294, # Pid of child process
        'status'  => 1, # 1/0
        'stderr'  => '', # STDERR
        'stdout'  => '', # STDOUT
    }
set2attr
    my $hash = set2attr({set => ["AttrName Value"]}); # {"AttrName" => "Value"}

Converts attributes from the "set" format to regular hash

setBit
    printf("%08b", setBit(123, 3)); # 01111111

Setting specified Bit. Returns new value.

slurp
    my $content = slurp($file);

Read all data at once from the file (utf8)

    my $content = slurp($file, 1);

Read all data at once from the file (binary)

spurt, spew
    my $error = spurt($file, qw/foo bar baz/);

Write all data at once to the file

HISTORY

See Changes file

AUTHOR

Serż Minus (Sergey Lepenkov) https://www.serzik.com <abalama@cpan.org>

COPYRIGHT

Copyright (C) 1998-2022 D&D Corporation. All Rights Reserved

LICENSE

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

See LICENSE file and https://dev.perl.org/licenses/