Aion-Format
view release on metacpan or search on metacpan
lib/Aion/Format.pm view on Meta::CPAN
%properties = %{_extends_ddp_properties(\%properties)};
DDP::np $arg, %properties
}
#@category ÐовÑÑки
# ÐовÑÑка Ð´Ð»Ñ STDERR
sub trapperr(&) {
my $sub = shift;
local *STDERR;
open STDERR, '>:utf8', \my $f;
$sub->();
close STDERR;
utf8::decode($f) unless utf8::is_utf8($f);
$f
}
# ÐовÑÑка Ð´Ð»Ñ STDOUT
sub trappout(&) {
my $sub = shift;
local *STDOUT;
open STDOUT, '>:utf8', \my $f;
$sub->();
close STDOUT;
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};
lib/Aion/Format.pm view on Meta::CPAN
$s //= "N";
$s =~ s/ \z//;
$s
}
# ÐÑполÑÐ·Ð¾Ð²Ð°Ð½Ñ ÑÐ¸Ð¼Ð²Ð¾Ð»Ñ Ð¸Ð· кодиÑовки cp1251, ÑÑо нÑжно Ð´Ð»Ñ ÐºÐ¾ÑÑекÑной запиÑи в ÑаблиÑÑ
our $CIF = join "", "0".."9", "A".."Z", "a".."z", "_-", # 64 Ñимвола Ð´Ð»Ñ 64-ÑиÑной ÑиÑÑÐµÐ¼Ñ ÑÑиÑлениÑ
(map chr, ord "Ð" .. ord "Я"), "ÐÐÐÐÐÐÐÐÐÐÒÐÐÐÐ
",
(map chr, ord "а" .. ord "Ñ"), "ÑÑÑÑÑÑÑÑÑÑÒÑÑÑÑ",
"âââ¦â â¡â¬â°â¹âââââ¢âââ¢âºÂ¤Â¦Â§Â©Â«Â¬Â®°±µ¶·â»", do { no utf8; chr 0xa0 }, # небÑквеннÑе ÑÐ¸Ð¼Ð²Ð¾Ð»Ñ Ð¸Ð· cp1251
"!\"#\$%&'()*+,./:;<=>?\@[\\]^`{|}~", # ÑÐ¸Ð¼Ð²Ð¾Ð»Ñ Ð¿ÑнкÑÑаÑии ASCII
" ", # пÑобел
(map chr, 0 .. 0x1F, 0x7F), # ÑпÑавлÑÑÑие ÑÐ¸Ð¼Ð²Ð¾Ð»Ñ ASCII
# Ñимвол 152 (0x98) в cp1251 оÑÑÑÑÑÑвÑеÑ.
;
# ÐеÑÐµÐ²Ð¾Ð´Ð¸Ñ Ð½Ð°ÑÑÑалÑное ÑиÑло в заданнÑÑ ÑиÑÑÐµÐ¼Ñ ÑÑиÑлениÑ
sub to_radix($;$) {
use bigint;
my ($n, $radix) = @_;
$radix //= 64;
lib/Aion/Format/Url.pm view on Meta::CPAN
while($s =~ /[а-ÑÑ]+/gi) {
my $x = $&;
if($x =~ /^[Ð-ЯÐа-ÑÑ][а-ÑÑ]*$/) { $c += length $x } else { $c -= length $x }
}
$c
}
sub from_url_param(;$) {
my ($param) = @_ == 0? $_: @_;
utf8::encode($param) if utf8::is_utf8($param);
{
no utf8;
use bytes;
$param =~ tr!\+! !;
$param =~ s!%([\da-f]{2})! chr hex $1 !iage;
}
eval { $param = Encode::decode_utf8($param, Encode::FB_CROAK) };
if($@) { # видимо ÑÑÑ ÐºÐ¾Ð´Ð¸Ñовка cp1251 или koi8-r
my $cp = Encode::decode('cp1251', $param);
my $koi = Encode::decode('koi8-r', $param);
# вÑбиÑаем пеÑекодиÑÐ¾Ð²ÐºÑ Ð² коÑоÑой менÑÑе болÑÑиÑ
бÑкв внÑÑÑи Ñлова
$param = _bohemy($koi) > _bohemy($cp)? $koi: $cp;
}
$param
}
t/aion/format.t view on Meta::CPAN
use common::sense; use open qw/:std :utf8/; use Carp qw//; use Cwd qw//; use File::Basename qw//; use File::Find qw//; use File::Slurper qw//; use File::Spec qw//; use File::Path qw//; use Scalar::Util qw//; use Test::More 0.98; use String::Diff q...
# # NAME
#
# Aion::Format - ÑаÑÑиÑение Perl Ð´Ð»Ñ ÑоÑмаÑиÑÐ¾Ð²Ð°Ð½Ð¸Ñ ÑиÑел, ÑаÑкÑаÑÐ¸Ð²Ð°Ð½Ð¸Ñ Ð²Ñвода и Ñ.п.
#
# # VERSION
#
# 0.0.10
#
# # SYNOPSIS
#
t/aion/format/html.t view on Meta::CPAN
use common::sense; use open qw/:std :utf8/; use Carp qw//; use Cwd qw//; use File::Basename qw//; use File::Find qw//; use File::Slurper qw//; use File::Spec qw//; use File::Path qw//; use Scalar::Util qw//; use Test::More 0.98; use String::Diff q...
# # NAME
#
# Aion::Format::Html - библиоÑека Ð´Ð»Ñ ÑоÑмаÑиÑÐ¾Ð²Ð°Ð½Ð¸Ñ HTML
#
# # SYNOPSIS
#
subtest 'SYNOPSIS' => sub {
use Aion::Format::Html;
local ($::_g0 = do {from_html "<b>!</b>"}, $::_e0 = "!"); ::ok $::_g0 eq $::_e0, 'from_html "<b>!</b>" # => !' or ::diag ::_string_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
t/aion/format/json.t view on Meta::CPAN
use common::sense; use open qw/:std :utf8/; use Carp qw//; use Cwd qw//; use File::Basename qw//; use File::Find qw//; use File::Slurper qw//; use File::Spec qw//; use File::Path qw//; use Scalar::Util qw//; use Test::More 0.98; use String::Diff q...
# # NAME
#
# Aion::Format::Json - ÑаÑÑиÑение Perl Ð´Ð»Ñ ÑоÑмаÑиÑÐ¾Ð²Ð°Ð½Ð¸Ñ JSON
#
# # SYNOPSIS
#
subtest 'SYNOPSIS' => sub {
use Aion::Format::Json;
local ($::_g0 = do {to_json {a => 10}}, $::_e0 = "{\n \"a\": 10\n}\n"); ::ok $::_g0 eq $::_e0, 'to_json {a => 10} # => {\n "a": 10\n}\n' or ::diag ::_string_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
t/aion/format/url.pm view on Meta::CPAN
use common::sense; use open qw/:std :utf8/; use Carp qw//; use Cwd qw//; use File::Basename qw//; use File::Find qw//; use File::Slurper qw//; use File::Spec qw//; use File::Path qw//; use Scalar::Util qw//; use Test::More 0.98; use String::Diff q...
#
# use common::sense;
#
# use List::Util qw//;
# use Encode 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
t/aion/format/url.pm view on Meta::CPAN
# while($s =~ /[а-ÑÑ]+/gi) {
# my $x = $&;
# if($x =~ /^[Ð-ЯÐа-ÑÑ][а-ÑÑ]*$/) { $c += length $x } else { $c -= length $x }
# }
# $c
# }
#
# sub from_url_param(;$) {
# my ($param) = @_ == 0? $_: @_;
#
# utf8::encode($param) if utf8::is_utf8($param);
#
# {
# no utf8;
# use bytes;
# $param =~ s!\+! !g;
# $param =~ s!%([\da-f]{2})! chr hex $1 !age;
# }
#
# eval { $param = Encode::decode_utf8($param, Encode::FB_CROAK) };
#
# if($@) { # видимо ÑÑÑ ÐºÐ¾Ð´Ð¸Ñовка cp1251 или koi8-r
# my $cp = Encode::decode('cp1251', $param);
# my $koi = Encode::decode('koi8-r', $param);
# # вÑбиÑаем пеÑекодиÑÐ¾Ð²ÐºÑ Ð² коÑоÑой менÑÑе болÑÑиÑ
бÑкв внÑÑÑи Ñлова
# $param = _bohemy($koi) > _bohemy($cp)? $koi: $cp;
# }
#
# $param
# }
t/aion/format/url.t view on Meta::CPAN
use common::sense; use open qw/:std :utf8/; use Carp qw//; use Cwd qw//; use File::Basename qw//; use File::Find qw//; use File::Slurper qw//; use File::Spec qw//; use File::Path qw//; use Scalar::Util qw//; use Test::More 0.98; use String::Diff q...
# # NAME
#
# Aion::Format::Url - ÑÑилиÑÑ Ð´Ð»Ñ ÐºÐ¾Ð´Ð¸ÑÐ¾Ð²Ð°Ð½Ð¸Ñ Ð¸ декодиÑÐ¾Ð²Ð°Ð½Ð¸Ñ URL-адÑеÑов
#
# # SYNOPSIS
#
subtest 'SYNOPSIS' => sub {
use Aion::Format::Url;
local ($::_g0 = do {to_url_params {a => 1, b => [[1,2],3,{x=>10}]}}, $::_e0 = "a&b[][]&b[][1]=2&b[1]=3&b[2][x]=10"); ::ok $::_g0 eq $::_e0, 'to_url_params {a => 1, b => [[1,2],3,{x=>10}]} # => a&b[][]&b[][1]=2&b[1]=3&b[2][x]=10' or ::diag ::_string_d...
t/aion/format/yaml.t view on Meta::CPAN
use common::sense; use open qw/:std :utf8/; use Carp qw//; use Cwd qw//; use File::Basename qw//; use File::Find qw//; use File::Slurper qw//; use File::Spec qw//; use File::Path qw//; use Scalar::Util qw//; use Test::More 0.98; use String::Diff q...
# # NAME
#
# Aion::Format::Yaml - конвеÑÑÐµÑ Ð¸Ð·/в yaml
#
# # SYNOPSIS
#
subtest 'SYNOPSIS' => sub {
use Aion::Format::Yaml qw/from_yaml to_yaml/;
local ($::_g0 = do {to_yaml {foo => 'bar'}}, $::_e0 = do {"foo: bar\n"}); ::ok defined($::_g0) == defined($::_e0) && $::_g0 eq $::_e0, 'to_yaml {foo => \'bar\'} # -> "foo: bar\n"' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
( run in 0.679 second using v1.01-cache-2.11-cpan-30a0b3e4e11 )