Cn-Util
view release on metacpan or search on metacpan
Revision history for Cn-Util
0.0243 2026-11-18 CST (Claude Opus 5.5 helped)
[`ref_to_json_file`]
- A structure that cannot be encoded, such as one holding a code reference or a reference to itself, now dies with the existing file left as it was. The file used to be opened, and so emptied, before the structure was encoded, so a failed call destr...
[`structure`]
- A reference that is already being described further out is now shown as `(cycle)` only when it leads back to the container that holds it, and as `(shown above)` otherwise. It used to be called `(cycle)` whenever it was cut off, so in `[$a, $b]` wi...
[`execute`]
- The output returned for `'stdout'`, `'stderr'` and `'all'` now loses its trailing newline whatever the caller's `$/` is. Under a caller's `local $/;` the newline used to be left on.
[`json_file_to_ref`]
- A file holding only a bare `NaN`, `Infinity` or `-Infinity`, as Python's `json.dumps(float('nan'))` writes it, now reads as `undef`. It used to die in `decode_json`.
[`file2string`]
- The file is now read with the `:raw` layer, as the documentation always said. On Windows, where perl reads through `:crlf` by default, `"\r\n"` used to come back as `"\n"`; elsewhere nothing changes.
[Documentation]
- `format_commas` says that it rounds the binary number perl holds, not the decimal the caller wrote, so `1.005`, held as 1.00499999999999989... in a double, gives `1.00`, as `sprintf('%.2f')` does.
0.0242 2026-11-14 CST (Claude Opus 5.5 helped)
[`file2string`]
- A directory now dies with "can't read", its name and "Is a directory" on NetBSD as well. NetBSD's `read` succeeds on a directory and returns its raw entries, so 0.0241 returned those bytes as if they were the file's contents. The module was at fau...
0.0241 2026-11-09 CST (Claude Opus 5.5 helped)
[`dir`]
- With `cpu` above 1, a worker process no longer runs the program's `END` blocks and destructors as it finishes. Each worker left through `Parallel::ForkManager`'s `finish`, which calls `exit`, so an `END` block ran once in every worker as well as o...
- A recursive listing no longer goes through `File::Find`, and takes less than half the CPU time in perl: 0.43 s of user time against 1.06 s over 279,000 entries. It returns the same paths.
- A recursive listing dies with "Cannot open directory" and the path, as a non-recursive one does, when `dir` is a file, when it does not exist, and when a subdirectory cannot be read. A file used to be returned as the only result, and the other two...
[`structure`]
- `structure` and `st` take 43% less memory and 30% less time on a large array of records: 237 MB and 1.4 s, down from 413 MB and 2.0 s, for 300,000 five-key records. They no longer copy every value they merge at each level. The output is unchanged.
[`json_file_to_ref`]
- A file with neither `NaN` nor `Infinity` in it is no longer scanned for them before decoding. The scan took seven times as long as the decoding: 2.1 s for a 43 MB file that decodes in 0.3 s.
[`file2string`]
- A directory, or a file whose read fails, dies with "can't read" and the name. It used to return `undef`.
[`ref_to_json_file`]
- The file name after "Wrote" is colored only when `STDOUT` is a terminal, or `CLICOLOR_FORCE` is set, and `NO_COLOR` is not, as `structure` already decided. Output sent to a file or a pipe used to carry the escape codes.
[`p` and `np`]
- The first `p` or `np` no longer warns "Devel::Size not found, show_memsize will be ignored" when `Devel::Size` is not installed. The memory size is shown when it is.
[Tests]
- `t/dir.t` skips its two checks that list `/` when `/` cannot be opened, as on Android, where 0.024 failed under Termux with "Cannot open directory /: Permission denied".
[Prerequisites]
- `POSIX`, `Storable` and `File::Temp`, which the module loads, are listed as prerequisites, and `File::Find` and `File::Spec`, which it no longer loads or never did, are not. `Devel::Size` is recommended. All but `Devel::Size` are core.
0.024 2026-11-08 CST (Claude Opus 5.5 helped)
[`execute`]
- Input that the caller had already read ahead from `STDIN` is no longer lost. In `printf 'a\nb\nc\n' | perl -e 'while (<STDIN>) { print; execute("true") }'` only `a` was printed. The command's standard input was the null device, put on fd 0 under p...
- `STDIN` is restored when `Capture::Tiny::capture` dies. It used to stay on the null device for the rest of the program.
- A return mode with a trailing newline, such as `"exit\n"`, is rejected before the command runs. It used to run the command and then die with "broke pigeonholes".
- `$die` is read as true or false, as documented. `'yes'` used to die with "isn't numeric", and `2` used to mean "do not die".
[`format_commas`]
- Infinity and NaN are returned as perl prints them, rather than as `Inf.NaN`, `-Inf.NaN` and `NaN.NaN`.
[`ref_to_json_file`]
- A write that fails, such as on a full disk, dies with "can't write" and the file name. It used to print "Wrote" and return the name of a truncated file on perl 5.20 and earlier, and die with "unable to close filehandle" on later perls.
[Argument checks]
- `dir` with an undefined `tests`, `dir`, `regex` or `cpu`, and `structure` with an undefined `output` or `color`, die saying which argument it was, instead of "Use of uninitialized value". `dir` rejects an `on_match` that is not a code reference, w...
0.023 2026-11-02 CST (Claude Opus 5.5 helped)
[`dir`]
- On Windows, a recursive `dir` whose `dir` is a symlink to a directory lists what is under it, as it already did elsewhere. 0.022 passed the link to `File::Find` with a trailing slash, which makes `lstat` follow the link on POSIX systems but not on...
0.022 2026-10-18 CDT (Claude Opus 5.5 helped)
[Renamed to Cn::Util]
- The distribution is now `Cn-Util`, installing `Cn::Util`, and a script changes `use Util::Cn` to `use Cn::Util`. The functions, and what each returns, are unchanged.
[`dir`]
- On Windows, a recursive `dir` of a path written with `\`, such as the one `File::Temp`'s `tempdir` returns, no longer returns that directory itself, and with `cpu` above 1 no longer returns each top-level subdirectory twice. `File::Find` 1.44 repo...
- On Windows, `dir => 'C:/'` and `dir => 'C:\'` list the root of drive C. The trailing slash of `C:/` was stripped, and `C:` alone is the current directory on drive C.
[Test suite]
- `t/windows-names.t`, listed under 0.021, is in the distribution. It had not been added to git, and `dzil build` gathers from git's index, so the 0.021 tarball left it out.
0.021 2026-10-16 CDT (Claude Opus 5.5 helped)
[Renamed to Util::Cn]
- The distribution is now `Util-Cn`, installing `Util::Cn`, and a script changes `use Util::Con` to `use Util::Cn`. `Util-Con` could not be built on Windows: `CON` is a reserved device name there, so `make` died creating `blib\lib\auto\Util\Con` wit...
[Test suite]
- `t/windows-names.t` is new and fails if a file, directory or package segment of the distribution is named after a Windows device such as `CON`, `NUL` or `COM1`.
0.02 2026-10-15 CDT (Claude Opus 5.5 helped)
[`dir`]
- A `dir` that is a symbolic link to a directory is listed through the link in every mode. A recursive listing with the default `cpu => 1` returned nothing for one, because `File::Find` took the link for a file, while a non-recursive listing and a r...
- `dir => '///'` returns `/etc` and the like. Only a single trailing slash after something other than a slash was removed, so it returned `////etc`.
[`format_commas`]
- `format_commas($n, '%.0u')` rounds half up to a whole number. The documented way to ask for a whole number appended the hundredths of any fraction without a decimal point: `1234.56` came out as `1,23456`, and `0.4` as `040`.
[`json_file_to_ref`]
- A bare `NaN`, `Infinity` or `-Infinity` is turned into `null` only outside JSON strings. Text inside a string that looked like one in value position was rewritten too, so `"values: [1, NaN, 2]"` was read as `"values: [1, null, 2]"`.
[`random_key` and `random_value`]
- Both leave the hash's iterator at the start, as they did before 0.01. 0.01 left it one pair in, so an `each` loop over the same hash afterwards skipped its first pair.
[`p` and `np`]
- A `p` or `np` of the calling package's own is kept when the stub for the other one loads DDP. DDP exports both, so a package with its own `p` that called `np` had that `p` replaced by DDP's.
- A `p` or `np` called again after DDP failed to load dies again. It looped forever, because the package was marked as loaded before the load was tried.
- If DDP is configured to export `p` under another name (an `alias` in `~/.dataprinter`), calling `p` dies saying so. It looped forever.
[`structure` and `st`]
- `structure` and `st` indent everything inside a scalar reference by its depth. The contents of a reference such as `{ a => { ptr => \{ x => 1 } } }` were printed one level below the top, as if they belonged to the outermost hash.
[Test suite]
- `t/structure.t` is new and covers `structure` and `st`, which had no tests.
0.01 2026-10-13 CDT (Claude Opus 5.5 helped)
[First CPAN release]
- `Util.pm`, a module that had only ever been loaded from a symlink into one perl's `site_perl`, is now the distribution `Util-Con`, installing `Util::Con`. The ten functions it exports, and what each returns, are unchanged: `dir`, `execute`, `file2...
[Runs on perl 5.10.1]
- The module required perl 5.44: it was written with subroutine signatures, the `:prototype` attribute and `no source::encoding`, none of which an older perl can compile. It is now written in perl 5.10 syntax, and the test suite passes on perl 5.10....
- `autodie` reaches the script on perl 5.10.1 and 5.12.5 too, whose `autodie` is 2.06. `Util.pm` imported it from inside a string eval, which works with perl 5.44's `autodie` 2.37, but 2.06 un-installs itself again as the eval returns, so a failed `...
[`p` and `np`]
- `p` and `np` are installed into the package that says `use Util::Con`, not always into `main`, and only when that package does not have its own. They were compiled into `main` whenever the module was loaded, so a script that said `use DDP` before ...
[Clearer messages]
- `execute` given an unknown `$return` says that it accepts `exit`, `stdout`, `stderr` and `all`. The message left out `all`.
[Test suite]
- The tests no longer assume a unix shell or a unix filesystem: `t/execute.t` runs perl itself rather than `true`, `false` and `echo`, a missing file or directory is named under a temporary directory rather than as `/no/such/...`, and the check that...
( run in 1.093 second using v1.01-cache-2.11-cpan-60884a8df76 )