Aion-Format
view release on metacpan or search on metacpan
lib/Aion/Format.pm view on Meta::CPAN
package Aion::Format;
# ÐиблиоÑека ÑоÑмаÑиÑÐ¾Ð²Ð°Ð½Ð¸Ñ Ð¸ вÑвода
use common::sense;
our $VERSION = "0.1.2";
require POSIX;
require Term::ANSIColor;
use Guard qw//;
use Exporter qw/import/;
our @EXPORT = our @EXPORT_OK = grep {
*{$Aion::Format::{$_}}{CODE} && !/^(_|(NaN|import)\z)/n
} keys %Aion::Format::;
#@category ÐÑвод ÑÑÑÑкÑÑÑ
use DDP qw//;
sub _extends_ddp_properties {
my ($properties) = @_;
+{
colored => 1,
deparse => 1,
show_unicode => 1,
show_readonly => 1,
print_escapes => 1,
show_refcount => 1,
show_memsize => eval { require Devel::Size; 1 },
caller_info => 1,
#output => 'stdout',
unicode_charnames => 1,
%$properties,
class => {
expand => "all",
inherited => "all",
show_reftype => 1,
%{$properties->{class}},
},
}
}
# p Ñ Ð¿ÑедÑÑÑановленнÑми опÑиÑми
sub p($;%) {
my ($arg, %properties) = @_;
%properties = %{_extends_ddp_properties(\%properties)};
DDP::p $arg, %properties
}
# np Ñ Ð¿ÑедÑÑÑановленнÑми опÑиÑми
sub np($;%) {
my ($arg, %properties) = @_;
%properties = %{_extends_ddp_properties(\%properties)};
DDP::np $arg, %properties
}
#@category ÐовÑÑки
# ÐовÑÑка Ð´Ð»Ñ STDERR
sub trapperr(&) {
my $sub = shift;
local *STDERR;
open STDERR, '>:utf8', \my $f; my $guard = Guard::guard { close STDERR };
$sub->();
undef $guard;
utf8::decode($f) unless utf8::is_utf8($f);
$f
}
# ÐовÑÑка Ð´Ð»Ñ STDOUT
sub trappout(&) {
my $sub = shift;
local *STDOUT;
open STDOUT, '>:utf8', \my $f; my $guard = Guard::guard { close STDOUT };
$sub->();
undef $guard;
utf8::decode($f) unless utf8::is_utf8($f);
$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, @_
}
# ÐеÑаÑÐ°ÐµÑ Ð² STDOUT вÑвод coloring
sub printcolor(@) {
( run in 1.871 second using v1.01-cache-2.11-cpan-97f6503c9c8 )