NAME
Developer::Dashboard::TextUtils - shared small text-manipulation helpers
SYNOPSIS
use Developer::Dashboard::TextUtils qw(_trim);
my $clean = _trim(" hello world \n"); # 'hello world'
DESCRIPTION
Provides _trim, the single home for a whitespace-trim helper that used to be written out identically in Developer::Dashboard::PageDocument and Developer::Dashboard::Web::App (DD-891) - the same "small helper reimplemented per file instead of shared" pattern this project already fixed once in Developer::Dashboard::DirEntries (DD-762).
PURPOSE
Give every module that needs to strip leading/trailing whitespace from a text string one canonical implementation to call, rather than each maintaining its own private copy that can silently drift out of sync with the others.
WHY IT EXISTS
PageDocument::_trim and Web::App::_trim were byte-for-byte identical - the same undef-guard, the same two substitutions, the same return - with no reason for the two copies to ever diverge and no mechanism to notice if one changed and the other did not. Extracting the shared behavior removes that latent-drift risk before an edit to one copy silently stops matching the other.
WHEN TO USE
Any module in this codebase that needs to trim leading/trailing whitespace from a text string should use this module rather than writing a private _trim.
HOW TO USE
Import _trim explicitly via @EXPORT_OK and call it on any text value that may carry leading or trailing whitespace, including a value that may be undef (it normalizes to an empty string rather than raising a warning):
use Developer::Dashboard::TextUtils qw(_trim);
my $clean = _trim($raw_text);
my $title = _trim( $args{title} ); # safe even if $args{title} is undef
WHAT USES IT
Developer::Dashboard::PageDocument and Developer::Dashboard::Web::App, at the 9 call sites the DD-891 extraction migrated.
EXAMPLES
_trim(undef) # ''
_trim('') # ''
_trim(" hello world \n") # 'hello world'
_trim(' internal spacing kept ') # 'internal spacing kept'