Aion-Format
view release on metacpan or search on metacpan
```
# DESCRIPTION
A utilities for formatting numbers, colorizing output and so on.
# SUBROUTINES
## coloring ($format, @params)
Colorizes the text with escape sequences, and then replaces the format with sprintf. Color names using from module `Term::ANSIColor`. For `RESET` use `#r` or `#R`.
```perl
coloring "#{BOLD RED}###r %i", 6 # => \e[1;31m##\e[0m 6
```
## printcolor ($format, @params)
As `coloring`, but it print formatted string.
## warncolor ($format, @params)
lib/Aion/Format.md view on Meta::CPAN
```
# DESCRIPTION
A utilities for formatting numbers, colorizing output and so on.
# SUBROUTINES
## coloring ($format, @params)
Colorizes the text with escape sequences, and then replaces the format with sprintf. Color names using from module `Term::ANSIColor`. For `RESET` use `#r` or `#R`.
```perl
coloring "#{BOLD RED}###r %i", 6 # => \e[1;31m##\e[0m 6
```
## printcolor ($format, @params)
As `coloring`, but it print formatted string.
## warncolor ($format, @params)
lib/Aion/Format.pm view on Meta::CPAN
use DDP {
colored => 1,
class => {
expand => "all",
inherited => "all",
show_reftype => 1,
},
deparse => 1,
show_unicode => 1,
show_readonly => 1,
print_escapes => 1,
#show_refcount => 1,
#show_memsize => 1,
caller_info => 1,
output => 'stdout',
#unicode_charnames => 1,
};
#@category ÐовÑÑки
# ÐовÑÑка Ð´Ð»Ñ STDERR
lib/Aion/Format.pm view on Meta::CPAN
my $sub = shift;
local *STDOUT;
open STDOUT, '>:utf8', \my $f;
$sub->();
close STDOUT;
$f
}
#@category ЦвеÑ
# ÐолоÑизиÑÑÐµÑ ÑекÑÑ escape-поÑледоваÑелÑноÑÑÑми: coloring("#{BOLD RED}ya#{}100!#RESET"), а заÑем - заменÑÐµÑ ÑоÑÐ¼Ð°Ñ sprintf-ом
sub coloring(@) {
my $s = shift;
$s =~ s!#\{(?<x>[\w \t]*)\}|#(?<x>\w+)!
my $x = $+{x};
$x = "RESET" if $x ~~ [qw/r R/];
Term::ANSIColor::color($x)
!nge;
sprintf $s, @_
}
lib/Aion/Format.pm view on Meta::CPAN
trappout { printcolor "#red ~> #r\n" } # => \e[31m ~> \e[0m\n
=head1 DESCRIPTION
A utilities for formatting numbers, colorizing output and so on.
=head1 SUBROUTINES
=head2 coloring ($format, @params)
Colorizes the text with escape sequences, and then replaces the format with sprintf. Color names using from module C<Term::ANSIColor>. For C<RESET> use C<#r> or C<#R>.
coloring "#{BOLD RED}###r %i", 6 # => \e[1;31m##\e[0m 6
=head2 printcolor ($format, @params)
As C<coloring>, but it print formatted string.
=head2 warncolor ($format, @params)
As C<coloring>, but print formatted string to C<STDERR>.
lib/Aion/Format/Url.pm view on Meta::CPAN
use List::Util qw//;
use Exporter qw/import/;
our @EXPORT = our @EXPORT_OK = grep {
ref \$Aion::Format::Url::{$_} eq "GLOB"
&& *{$Aion::Format::Url::{$_}}{CODE} && !/^(_|(NaN|import)\z)/n
} keys %Aion::Format::Url::;
#@category escape url
use constant UNSAFE_RFC3986 => qr/[^A-Za-z0-9\-\._~]/;
sub to_url_param(;$) {
my ($param) = @_ == 0? $_: @_;
$param =~ s/${\ UNSAFE_RFC3986}/$& eq " "? "+": sprintf "%%%02X", ord $&/age;
$param
}
sub _escape_url_params {
my ($key, $param) = @_;
!defined($param)? ():
$param eq 1? $key:
ref $param eq "HASH"? do {
join "&", map _escape_url_params("${key}[$_]", $param->{$_}), sort keys %$param
}:
ref $param eq "ARRAY"? do {
join "&", map _escape_url_params("${key}[]", $_), @$param
}:
join "", $key, "=", to_url_param $param
}
sub to_url_params(;$) {
my ($param) = @_ == 0? $_: @_;
if(ref $param eq "HASH") {
join "&", map _escape_url_params($_, $param->{$_}), sort keys %$param
}
else {
join "&", List::Util::pairmap { _escape_url_params($a, $b) } @$param
}
}
# #@see https://habr.com/ru/articles/63432/
# # Ð multipart/form-data
# sub to_multipart(;$) {
# my ($param) = @_ == 0? $_: @_;
# $param =~ s/[&=?#+\s]/$& eq " "? "+": sprintf "%%%02X", ord $&/ge;
# $param
# }
t/aion/format.t view on Meta::CPAN
#
# # DESCRIPTION
#
# A utilities for formatting numbers, colorizing output and so on.
#
# # SUBROUTINES
#
# ## coloring ($format, @params)
#
# Colorizes the text with escape sequences, and then replaces the format with sprintf. Color names using from module `Term::ANSIColor`. For `RESET` use `#r` or `#R`.
#
done_testing; }; subtest 'coloring ($format, @params)' => sub {
::is scalar do {coloring "#{BOLD RED}###r %i", 6}, "\e[1;31m##\e[0m 6", 'coloring "#{BOLD RED}###r %i", 6 # => \e[1;31m##\e[0m 6';
#
# ## printcolor ($format, @params)
#
# As `coloring`, but it print formatted string.
#
# ## warncolor ($format, @params)
( run in 0.446 second using v1.01-cache-2.11-cpan-c21f80fb71c )