App-Nag
view release on metacpan or search on metacpan
lib/App/Nag.pm view on Meta::CPAN
# generate message text and synopsis
my $text = join ' ', @args;
$text =~ s/^\s++|\s++$//g;
$text =~ s/\s++/ /g;
( my $synopsis = $text ) =~ s/^(\S++(?: \S++){0,3}).*/$1/;
$synopsis .= ' ...' if length($text) - length($synopsis) > 4;
return ( $verbosity, $text, $synopsis, $seconds );
}
# extract useful bits out of a time expression
# tried to do this with a more readable recursive regex and callbacks but got
# OOM errors at unpredictable intervals so I gave up
sub _parse_time {
my %props;
given ( $_[0] ) {
when (/^(\d++)([hms])$/i) { @props{qw(time unit)} = ( $1, lc $2 ) }
when (/^(\d{1,2})(?::(\d{2}))?(?:([ap])(\.?)m\4)?$/i) {
@props{qw(hour minute suffix)} = ( $1, $2 || 0, lc( $3 || '' ) )
}
}
return %props;
( run in 0.563 second using v1.01-cache-2.11-cpan-8d75d55dd25 )