DiaColloDB
view release on metacpan or search on metacpan
DiaColloDB/Utils.pod view on Meta::CPAN
##========================================================================
## POD DOCUMENTATION, auto-generated by podextract.perl
##========================================================================
## NAME
=pod
=head1 NAME
DiaColloDB::Utils - diachronic collocation database, generic utilities
=cut
##========================================================================
## SYNOPSIS
=pod
=head1 SYNOPSIS
##========================================================================
## PRELIMINARIES
use DiaColloDB::Utils;
##========================================================================
## Functions: Fcntl
$flags = PACKAGE::fcflags($flags);
$flags = PACKAGE::fcgetfl($fh);
$bool = fcread($flags);
$bool = fcwrite($flags);
$bool = fctrunc($flags);
$bool = fccreat($flags);
$fh_or_undef = fcopen($file,$flags);
##========================================================================
## JSON: load
$data = PACKAGE::loadJsonString( $string,%opts);
$data = PACKAGE::loadJsonFile($filename_or_handle,%opts);
##========================================================================
## JSON: save
$str = PACKAGE::saveJsonString($data);
$bool = PACKAGE::saveJsonFile($data,$filename_or_handle,%opts);
##========================================================================
## Functions: env
\%setenv = PACKAGE::env_set(%setenv);
\%restored = PACKAGE::env_pop(%setenv);
##========================================================================
## Functions: run
$fh_or_undef = PACKAGE::opencmd($cmd);
$bool = crun(@IPC_Run_args);
$bool = csort_to(\@sortargs, \&catcher);
$bool = csortuc_to(\@sortargs, \&catcher);
$cmd = sortCmd();
##========================================================================
## Functions: pack filters
$len = PACKAGE::packsize($packfmt);
\&filter_sub = PACKAGE::packFilterStore($pack_template);
\&filter_sub = PACKAGE::packFilterFetch($pack_template);
##========================================================================
## Math stuff
$log2 = log2($x);
$max2 = max2($x,$y);
$min2 = min2($x,$y);
##========================================================================
## Functions: lists
\@l_uniq = luniq(\@l);
\@l_sorted_uniq = sluniq(\@l_sorted);
\@l_uniq = xluniq(\@l,\&keyfunc);
##========================================================================
## Functions: regexes
$re = regex($re_str);
##========================================================================
## Functions: html
$escaped = htmlesc($str);
##========================================================================
## Functions: time
$hms = PACKAGE::s2hms($seconds,$sfmt="%06.3f");
$timestr = PACKAGE::s2timestr($seconds,$sfmt="%f");
$rfc_timestamp = PACAKGE->timestamp();
##========================================================================
## Functions: file
$mtime = PACKAGE->file_mtime($file_or_fh);
$timestamp = PACKAGE->file_timestamp($file_or_fh);
$nbytes = du_file(@filenames_or_fh);
$nbytes = du_glob(@globs);
$bool = PACKAGE->copyto ($src_filename_or_array, $dstdir, %opts);
$bool = PACKAGE->copyto_a($src_filename_or_array, $dstdir, %opts);
$bool = PACKAGE->moveto ($src_filename_or_array, $dstdir, %opts);
DiaColloDB/Utils.pod view on Meta::CPAN
=item loadJsonString
$data = PACKAGE::loadJsonString( $string,%opts);
$data = PACKAGE::loadJsonString(\$string,%opts)
decodes JSON string.
%opts are passed to L<JSON::from_json()|JSON/from_json>.
=item loadJsonFile
$data = PACKAGE::loadJsonFile($filename_or_handle,%opts);
loads JSON data from a file or filehandle.
%opts are passed to loadJsonString().
=back
=cut
##----------------------------------------------------------------
## DESCRIPTION: DiaColloDB::Utils: JSON: save
=pod
=head2 JSON: save
=over 4
=item saveJsonString
$str = PACKAGE::saveJsonString($data);
$str = PACKAGE::saveJsonString($data,%opts);
Encode data as a JSON string.
%opts are passed to L<JSON::to_json()|JSON/to_json>, e.g. (pretty=E<gt>0, canonical=E<gt>0)'.
=item saveJsonFile
$bool = PACKAGE::saveJsonFile($data,$filename_or_handle,%opts);
Save JSON data to a file.
%opts are passed to saveJsonString().
=back
=cut
##----------------------------------------------------------------
## DESCRIPTION: DiaColloDB::Utils: Functions: env
=pod
=head2 Functions: env
=over 4
=item Variable: @env_stack
Stack of temporary environment variables.
=item env_set
\%setenv = PACKAGE::env_set(%setenv);
Set or clear environment variables.
=item env_push
\%oldvals = PACKAGE::env_push(%setenv);
Push old values for keys(%setenv) to @env_stack
and calls env_set(%setenv).
=item env_pop
\%restored = PACKAGE::env_pop(%setenv);
Pops the most recent variable bindings from @env_stack
and restores them to the environment.
=back
=cut
##----------------------------------------------------------------
## DESCRIPTION: DiaColloDB::Utils: Functions: run
=pod
=head2 Functions: run
=over 4
=item opencmd
$fh_or_undef = PACKAGE::opencmd($cmd);
$fh_or_undef = PACKAGE::opencmd($mode,@argv);
does log trace at level $TRACE_RUNCMD
=item crun
$bool = crun(@IPC_Run_args);
wrapper for IPC::Run::run(@IPC_Run_args) with $ENV{LC_ALL}='C'
=item csort_to
$bool = csort_to(\@sortargs, \&catcher);
runs system sort and feeds resulting lines to \&catcher
=item csortuc_to
$bool = csortuc_to(\@sortargs, \&catcher);
runs system sort | uniq -c and feeds resulting lines to \&catcher
=item sortCmd
$cmd = sortCmd();
$cmd = sortCmd($nJobs);
Returns command-line prefix (command and initial optopins) for GNU-like B<sort> command.
This method just returns the value of the C<DIACOLLO_SORT> environment variable if it is set,
otherwise the value of the C<SORT> environment variable if that is set. If neither
C<DIACOLLO_SORT> nor C<SORT> are set, it returns the string B<sort> with the parallelization
options returned by L</sortJobs> appended. You can use the environment variable hooks e.g. to
reduce the amount of RAM and/or CPU cores used by subordinate system sort calls by setting
them appropriately, e.g.
env SORT="/bin/sort --parallel=4 --buffer-size=1G"
to request that GNU sort use at most 4 CPU cores and a maximum RAM buffer size of 1GB.
=back
( run in 0.617 second using v1.01-cache-2.11-cpan-39bf76dae61 )