NAME

WWW::Suffit::Util - The Suffit utilities

SYNOPSIS

use WWW::Suffit::Util;

DESCRIPTION

Exported utility functions

color

say color(blue => "Format %s %s" => "text", "foo");
say color(cyan => "text");
say color("red on_bright_yellow" => "text");
say STDERR color("red on_bright_yellow" => "text");

Returns colored formatted string if is session was runned from terminal

Supported normal foreground colors:

black, red, green, yellow, blue, magenta, cyan, white

Bright foreground colors:

bright_black, bright_red,     bright_green, bright_yellow
bright_blue,  bright_magenta, bright_cyan,  bright_white

Normal background colors:

on_black, on_red,     on_green, on yellow
on_blue,  on_magenta, on_cyan,  on_white

Bright background color:

on_bright_black, on_bright_red,     on_bright_green, on_bright_yellow
on_bright_blue,  on_bright_magenta, on_bright_cyan,  on_bright_white

See also Term::ANSIColor

dformat

$string = dformat( $mask, \%replacehash );
$string = dformat( $mask, %replacehash );

Replace substrings "[...]" in mask and returns replaced result. Data for replacing get from \%replacehash

For example:

# -> 01-foo-bar.baz.tgz
$string = dformat( "01-[NAME]-bar.[EXT].tgz", {
    NAME => 'foo',
    EXT  => 'baz',
});

See also "dformat" in CTK::Util

fbytes

print fbytes( 123456 );

Returns formatted size value

fdate

print fdate( time );

Returns formatted date value

fdatetime

print fdatetime( time );

Returns formatted date value

fduration

print fduration( 123 );

Returns formatted duration value

human2bytes

my $bytes = human2bytes("100 kB");

Converts a human readable byte count into the pure number of bytes without any suffix

json_load

my $hash  = json_load( $file );

Loads JSON file and returns data as perl struct

json_save

my $path = json_save( $file, {foo => [1, 2], bar => 'hello!', baz => \1} );

Save perl struct to file as JSON document and returns the Mojo::File object

md5sum

my $md5 = md5sum( $file );

See Digest::MD5

parse_expire

print parse_expire("+1d"); # 86400
print parse_expire("-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

parse_time_offset

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

Returns offset of time (in secs)

HISTORY

See Changes file

TO DO

See TODO file

SEE ALSO

Digest::MD5

AUTHOR

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

COPYRIGHT

Copyright (C) 1998-2023 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/