NAME
U - Utilities
SYNOPSIS
use U;
U::ewarn 'Subject', 'Body text';
U::email 'user@example.com', 'Hello', "Body\n";
my $rounded = U::round 5.6777, 2; # "5.68"
DESCRIPTION
U contains utility functions used across the application. Some functions, such as email, intentionally depend on shared configuration or the application context through C, and may log messages through L. You are responsible for initializing these facilities before calling utilities and treating configuration as stable after startup.
Utilities may use infrastructure initialized at startup. They should provide a predictable result or immediate effect without maintaining persistent state between calls. The U:: functions should look like: call -> result/effect. Configuration chooses the implementation; callers rely on the utility's contract.
See "TUTORIAL" in App::Ground for initialization and usage examples.
FUNCTIONS
ewarn
U::ewarn $subject, $body, $attachments;
Log the first two arguments using "warn" in L and send an email to the debug address configured in C::config->{Debug}{to}.
Configuration example:
Debug => {
to => 'recepient@example.com',
subject => 'Invoice: Exception',
},
See C::load for details.
U::email $to, $subject, $body;
U::email $to, $subject, $body, \@attachments;
U::email \%opts;
Send an email using Email::Stuffer.
Configuration is read from C::config->{email} and is expected to contain transport settings (server, port, ssl, username, password, from, and so on).
Attachments can be provided as an array reference. Each element is passed to Email::Stuffer->attach (scalar or arrayref of arguments).
Configuration example:
email => {
stop_subj => '[Debug]',
# stop_mail => 'recepient@example.com',
from => 'source@example.com',
transport => '::SMTP::Persistent',
server => 'email-smtp.eu-west-1.amazonaws.com',
port => '587',
ssl => 'starttls',
username => 'AKIA...',
password => 'XYZ',
},
See C::load for details.
round
my $str = U::round $number;
my $str = U::round $number, $places;
Round a number to $places decimals (default: 2) using "bfround" in Math::BigFloat. Returns a formatted string.