Bot-Cobalt
view release on metacpan or search on metacpan
lib/Bot/Cobalt/Utils.pm view on Meta::CPAN
use Bot::Cobalt::Utils;
my $hash = Bot::Cobalt::Utils::mkpasswd('things');
Import some things:
use Bot::Cobalt::Utils qw/ mkpasswd passwdcmp /;
my $hash = mkpasswd('things');
Import all the things:
use Bot::Cobalt::Utils qw/ :ALL /;
my $hash = mkpasswd('things', 'sha512');
my $secs = timestr_to_secs('3h30m');
. . .
See below for a list of exportable functions.
=head1 FUNCTIONS
=head2 Exportable functions
=over
=item L</timestr_to_secs> - Convert a string into seconds
=item L</secs_to_timestr> - Convert seconds back into timestr
=item L</secs_to_str> - Convert seconds into a 'readable' string
=item L</color> - Add format/color to IRC messages
=item L</glob_to_re_str> - Convert Cobalt-style globs to regex strings
=item L</glob_to_re> - Convert Cobalt-style globs to compiled regexes
=item L</glob_grep> - Search an array or arrayref by glob
=item L</rplprintf> - Format portable langset reply strings
=item L</mkpasswd> - Create crypted passwords
=item L</passwdcmp> - Compare crypted passwords
=back
=head2 Date and Time
=head3 timestr_to_secs
Convert a string such as "2h10m" into seconds.
my $delay_s = timestr_to_secs '1h33m10s';
Useful for dealing with timers.
=head3 secs_to_timestr
Turns seconds back into a timestring suitable for feeding to
L</timestr_to_secs>:
my $timestr = secs_to_timestr 820; ## -> 13m40s
=head3 secs_to_str
Convert a timestamp delta into a string.
Useful for uptime reporting, for example:
my $delta = time() - $your_start_TS;
my $uptime_str = secs_to_str $delta;
Returns time formatted as: C<< <D> day(s), <H>:<M>:<S> >>
=head3 secs_to_str_y
Like L</secs_to_str>, but includes year calculation and returns time formatted
as: C<< <Y> year(s), <D> day(s), <H>:<M>:<S> >> B<if> there are more than 365
days; otherwise the same format as L</secs_to_str> is returned.
(Added in C<v0.18.1>)
=head2 String Formatting
=head3 color
Add mIRC formatting and color codes to a string.
Valid formatting codes:
NORMAL BOLD UNDERLINE REVERSE ITALIC
Valid color codes:
WHITE BLACK BLUE GREEN RED BROWN PURPLE ORANGE YELLOW TEAL PINK
LIGHT_CYAN LIGHT_BLUE LIGHT_GRAY LIGHT_GREEN
Format/color type can be passed in upper or lower case.
If passed just a color or format name, returns the control code.
If passed nothing at all, returns the 'NORMAL' reset code:
my $str = color('bold') . "bold text" . color() . "normal text";
If passed a color or format name and a string, returns the formatted
string, terminated by NORMAL:
my $formatted = color('red', "red text") . "normal text";
If you need to retrieve (or alter via C<local>, for example) the actual
control characters themselves, they are accessible via the C<<
%Bot::Cobalt::Utils::COLORS >> hash:
( run in 1.236 second using v1.01-cache-2.11-cpan-437f7b0c052 )