NAME

App::DistSync::Util - The App::DistSync utilities

SYNOPSIS

use App::DistSync::Util;

DESCRIPTION

Exported utility functions

debug

debug("Foo bar baz");
debug("Foo %s baz", "bar");
debug("Foo %s %s", "bar", "baz");

Show debug information to STDERR

fdelete

my $status = fdelete( $file );

Deleting a file if it exists

manifind

my $files_struct = manifind($dir); # { ... }

Read direactory and returns file structure

maniread

my $mani_struct = maniread($file, skipflag); # { ... }

Read file as manifest and returns hash structure

maniwrite

maniwrite($file, $mani_struct);

This function writes manifest structure to manifest file

qrreconstruct

my $r = qrreconstruct('!!perl/regexp (?i-xsm:^\s*(error|fault|no))');
# Translate to:
#    qr/^\s*(error|fault|no)/i

Returns regular expression (QR) by perl/regexp string. YAML form of definition

my $r = qrreconstruct('perl/regexp (?i-xsm:^\s*(error|fault|no))');
# Translate to:
#    qr/^\s*(error|fault|no)/i

Not-YAML form of definition

my $r = qrreconstruct('regexp (?i-xsm:^\s*(error|fault|no))');
# Translate to:
#    qr/^\s*(error|fault|no)/i

Short form of definition

See also "regexp" in YAML::Type of YAML::Types

read_yaml

my $yaml = read_yaml($yaml_file);

Read YAML file

slurp

my $data = slurp($file, %args);
my $data = slurp($file, { %args });
slurp($file, { buffer => \my $data });
my $data = slurp($file, { binmode => ":raw:utf8" });

Reads file $filename into a scalar

my $data = slurp($file, { binmode => ":unix" });

Reads file in fast, unbuffered, raw mode

my $data = slurp($file, { binmode => ":unix:encoding(UTF-8)" });

Reads file with UTF-8 encoding

By default it returns this scalar. Can optionally take these named arguments:

binmode

Set the layers to read the file with. The default will be something sensible on your platform

block_size

Set the buffered block size in bytes, default to 1048576 bytes (1 MiB)

buffer

Pass a reference to a scalar to read the file into, instead of returning it by value. This has performance benefits

See also "spew" to writing data to file

spew

spew($file, $data, %args);
spew($file, $data, { %args });
spew($file, \$data, { %args });
spew($file, \@data, { %args });
spew($file, $data, { binmode => ":raw:utf8" });

Writes data to a file atomically. The only argument is binmode, which is passed to binmode() on the handle used for writing.

Can optionally take these named arguments:

append

This argument is a boolean option, defaulted to false (0). Setting this argument to true (1) will cause the data to be be written at the end of the current file. Internally this sets the sysopen mode flag O_APPEND

binmode

Set the layers to write the file with. The default will be something sensible on your platform

locked

This argument is a boolean option, defaulted to false (0). Setting this argument to true (1) will ensure an that existing file will not be overwritten

mode

This numeric argument sets the default mode of opening files to write. By default this argument to (O_WRONLY | O_CREAT). Please DO NOT set this argument unless really necessary!

perms

This argument sets the permissions of newly-created files. This value is modified by your process's umask and defaults to 0666 (same as sysopen)

See also "slurp" to reading data from file

tms

print tms();

This function returns current time and PID in format, for eg.:

[Sat Dec  6 19:09:54 2025] [533052]

touch

touch( "file" ) or die "Can't touch file";

Makes file exist, with current timestamp

See ExtUtils::Command

write_yaml

write_yaml($yaml_file, $yaml);

Write YAML file

HISTORY

See Changes file

TO DO

See TODO file

SEE ALSO

LWP::Simple

AUTHOR

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

COPYRIGHT

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