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 $resolve is true, returns a flat list of fd => path pairs.

getfds()

Like open_fds but 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 $fh via fcntl(F_GETFL).

setfl( $fh, $flags )

Sets the file status flags for $fh via fcntl(F_SETFL).

nonblock( $fh )

Sets O_NONBLOCK on $fh.

Object / Reference Utilities

class( $thing )

Returns ref($thing) if it is a reference, $thing itself if it is a plain string (class name), or 'undef' if it is undefined.

safe_isa( $obj, $class )

Returns true if $obj is a blessed reference that isa $class. Returns undef rather than dying if $obj is not a reference.

safe_blessed( $obj )

Returns the class name if $obj is blessed, undef otherwise.

safe_can( $obj, $method )

Returns the method coderef if $obj is blessed and can $method, undef otherwise.

mkref( $thing )

Returns $thing if it is already a reference, otherwise \$thing.

flatten( @list )

Recursively flattens arrays and hashes in @list into 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-HHMMSS format (UTC). Defaults to the current time.

Process Utilities

child_wait()

Waits for all child processes to exit, warning on non-zero exit status.

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 URI object. URI is 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 $coderef using B::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 @ISA tree.

Like methods() but pretty-prints via ddx.

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