NAME
Nobody::Util - Utilities Nobody Uses
SYNOPSIS
use Nobody::Util;
my $id = file_id("/etc/passwd");
my $date = serdate();
my @vers = vsort(qw( 1.10 1.9 2.0 1.1 ));
my $cwd = getcwd();
DESCRIPTION
Nobody::Util is a collection of utility functions accumulated over years of Perl development by Rich Paul (CPAN: NOBODY). It is, as the name suggests, full of things that nobody else does — but that save time.
The module re-exports commonly needed symbols from Carp, List::Util, Scalar::Util, Sub::Util, POSIX, Fcntl, Path::Tiny, and FindBin so that most scripts need only use Nobody::Util to get a useful working environment.
EXPORTED BY DEFAULT
All functions listed under "FUNCTIONS" are exported by default.
EXPORT_OK / EXPORT_TAGS
use Nobody::Util qw( :all ); # everything, including re-exports
FUNCTIONS
File Descriptor Utilities
- open_fds( [$resolve] )
-
Returns a list of open file descriptor numbers for the current process. If
$resolveis true, returns a flat list offd => pathpairs. - getfds()
-
Like
open_fdsbut includes the directory fd used internally. - getcwd()
-
Returns the current working directory by reading
/proc/self/cwd. - getfl( $fh )
-
Returns the file status flags for
$fhviafcntl(F_GETFL). - setfl( $fh, $flags )
-
Sets the file status flags for
$fhviafcntl(F_SETFL). - nonblock( $fh )
-
Sets
O_NONBLOCKon$fh.
Object / Reference Utilities
- class( $thing )
-
Returns
ref($thing)if it is a reference,$thingitself if it is a plain string (class name), or'undef'if it is undefined. - safe_isa( $obj, $class )
-
Returns true if
$objis a blessed reference thatisa$class. Returnsundefrather than dying if$objis not a reference. - safe_blessed( $obj )
-
Returns the class name if
$objis blessed,undefotherwise. - safe_can( $obj, $method )
-
Returns the method coderef if
$objis blessed and can$method,undefotherwise. - mkref( $thing )
-
Returns
$thingif it is already a reference, otherwise\$thing. - flatten( @list )
-
Recursively flattens arrays and hashes in
@listinto a flat list.
String / List Utilities
- pad( @strings )
-
Right-pads all strings to the length of the longest, using
.as fill. - pasteLines( @strings )
-
Joins strings, removing line-continuation backslashes.
- lsort( @list )
-
Sorts by length first, then lexicographically.
- lcmp
-
Sort comparator for
lsort(length then lex).
Version Comparison
- vcmp( $a, $b )
-
Compares two version strings numerically segment by segment.
- vsort( @versions )
-
Sorts a list of version strings using
vcmp.
Date / Time
- serdate( [$time] )
-
Returns a sortable timestamp string in
YYYYMMDD-HHMMSSformat (UTC). Defaults to the current time.
Process Utilities
File Utilities
- file_id( $path )
-
Returns a unique string identifier for a file based on its device and inode numbers, suitable for detecting hard links.
- uri( $string )
-
Constructs and returns a
URIobject.URIis loaded on demand. - serial_maker( %args )
-
Returns a closure that generates sequentially-numbered unique files or directories. Arguments:
fmt(sprintf format, required),min(default 0),max(default 1000),dir(make directories if true).
Introspection
- deparse( $coderef )
-
Returns a string representation of
$coderefusingB::Deparse. - methods( $obj_or_class )
-
Prints all methods available to
$obj_or_class, including inherited ones. - methods_via( $class, $prefix, $crawl_upward )
-
Worker for
methods(); crawls the@ISAtree. - print_methods( $obj_or_class )
-
Like
methods()but pretty-prints viaddx.
AUTHOR
Rich Paul, <nobody at cpan.org>
LICENSE
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 442:
Non-ASCII character seen before =encoding in '—'. Assuming UTF-8