Acrux
view release on metacpan or search on metacpan
lib/Acrux/Util.pm view on Meta::CPAN
package Acrux::Util;
use strict;
use utf8;
=encoding utf8
=head1 NAME
Acrux::Util - The Acrux utilities
=head1 SYNOPSIS
use Acrux::Util;
=head1 DESCRIPTION
This module provides portable utility functions for Acrux
=head2 clone
my $copy = clone(\@array);
my $copy = clone(\%hash);
This function is a proxy function for L<Storable/dclone>
It makes recursive copies of nested hash, array, scalar and reference types, including tied variables and objects.
The C<clone()> takes a scalar argument and duplicates it. To duplicate lists, arrays or hashes, pass them in by reference, e.g.
=head2 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 L<Term::ANSIColor>
=head2 deprecated
deprecated('foo is DEPRECATED in favor of bar');
Warn about deprecated feature from perspective of caller.
You can also set the C<ACRUX_FATAL_DEPRECATIONS> environment
variable to make them die instead with L<Carp>
=head2 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 L<CTK::Util/dformat>
=head2 dtf
See L</fdt>
=head2 dumper
my $perl = dumper({some => 'data'});
Dump a Perl data structure with L<Data::Dumper>
=head2 eqtime
eqtime("from/file", "to/file") or die "Oops";
Sets modified time of destination to that of source
=head2 fbytes
print fbytes( 123456 );
Returns formatted size value
=head2 fdate
print fdate( time );
Returns formatted date value
( run in 1.328 second using v1.01-cache-2.11-cpan-d8267643d1d )