Aion-Format
view release on metacpan or search on metacpan
## KiB ()
The constant is one kibibyte.
```perl
KiB # -> 2**10
```
## xxL ()
Maximum length in data LongText mysql and mariadb.
L - large.
```perl
xxL # -> 4*GiB-1
```
## xxM ()
Maximum length in data MediumText mysql and mariadb.
M - medium.
```perl
xxM # -> 16*MiB-1
```
## xxR ()
Maximum length in data Text mysql and mariadb.
R - regularity.
```perl
xxR # -> 64*KiB-1
```
## xxS ()
Maximum length in data TinyText mysql and mariadb.
S - small.
```perl
xxS # -> 255
```
## to_str (;$scalar)
Converts to string perl without interpolation.
lib/Aion/Format.md view on Meta::CPAN
## KiB ()
The constant is one kibibyte.
```perl
KiB # -> 2**10
```
## xxL ()
Maximum length in data LongText mysql and mariadb.
L - large.
```perl
xxL # -> 4*GiB-1
```
## xxM ()
Maximum length in data MediumText mysql and mariadb.
M - medium.
```perl
xxM # -> 16*MiB-1
```
## xxR ()
Maximum length in data Text mysql and mariadb.
R - regularity.
```perl
xxR # -> 64*KiB-1
```
## xxS ()
Maximum length in data TinyText mysql and mariadb.
S - small.
```perl
xxS # -> 255
```
## to_str (;$scalar)
Converts to string perl without interpolation.
lib/Aion/Format.pm view on Meta::CPAN
"!\"#\$%&'()*+,./:;<=>?\@[\\]^`{|}~", # ÑÐ¸Ð¼Ð²Ð¾Ð»Ñ Ð¿ÑнкÑÑаÑии ASCII
" ", # пÑобел
(map chr, 0 .. 0x1F, 0x7F), # ÑпÑавлÑÑÑие ÑÐ¸Ð¼Ð²Ð¾Ð»Ñ ASCII
# Ñимвол 152 (0x98) в cp1251 оÑÑÑÑÑÑвÑеÑ.
;
# ÐеÑÐµÐ²Ð¾Ð´Ð¸Ñ Ð½Ð°ÑÑÑалÑное ÑиÑло в заданнÑÑ ÑиÑÑÐµÐ¼Ñ ÑÑиÑлениÑ
sub to_radix($;$) {
use bigint;
my ($n, $radix) = @_;
$radix //= 64;
die "to_radix: The number system $radix is too large. Use NS before " . (1 + length $CIF) if $radix > length $CIF;
$n+=0; $radix+=0;
my $x = "";
for(;;) {
my $cif_idx = $n % $radix;
my $cif = substr $CIF, $cif_idx, 1;
$x =~ s/^/$cif/;
last unless $n = int($n / $radix);
}
return $x;
}
# ÐаÑÑÐ¸Ñ Ð½Ð°ÑÑÑалÑное ÑиÑло в Ñказанной ÑиÑÑеме ÑÑиÑлениÑ
sub from_radix(@) {
use bigint;
my ($s, $radix) = @_;
$radix //= 64;
$radix+=0;
die "from_radix: The number system $radix is too large. Use NS before " . (1 + length $CIF) if $radix > length $CIF;
my $x = 0;
for my $ch (split "", $s) {
$x = $x*$radix + index $CIF, $ch;
}
return $x;
}
# ÐкÑÑглÑÐµÑ Ð´Ð¾ Ñказанного ÑазÑÑда ÑиÑла
sub round($;$) {
my ($x, $dec) = @_;
lib/Aion/Format.pm view on Meta::CPAN
return num(round($n)) . "b";
}
# ÐÑÑавлÑÐµÑ $n ÑиÑÑ Ð´Ð¾ и поÑле ÑоÑки: 10.11 = 10, 0.00012 = 0.00012, 1.2345 = 1.2, еÑли $n = 2
sub sround($;$) {
my ($number, $digits) = @_;
$digits //= 2;
my $num = sprintf("%.100f", $number);
$num =~ /^-?0?(\d*)\.(0*)[1-9]/;
return "" . round($num, $digits + length $2) if length($1) == 0;
my $k = $digits - length $1;
return "" . round($num, $k < 0? 0: $k);
}
# ÐибибайÑ
sub KiB() { 2**10 }
# ÐебибайÑ
sub MiB() { 2**20 }
# ÐибибайÑ
lib/Aion/Format.pm view on Meta::CPAN
MiB # -> 2**20
=head2 KiB ()
The constant is one kibibyte.
KiB # -> 2**10
=head2 xxL ()
Maximum length in data LongText mysql and mariadb.
L - large.
xxL # -> 4*GiB-1
=head2 xxM ()
Maximum length in data MediumText mysql and mariadb.
M - medium.
xxM # -> 16*MiB-1
=head2 xxR ()
Maximum length in data Text mysql and mariadb.
R - regularity.
xxR # -> 64*KiB-1
=head2 xxS ()
Maximum length in data TinyText mysql and mariadb.
S - small.
xxS # -> 255
=head2 to_str (;$scalar)
Converts to string perl without interpolation.
to_str "a'\n" # => 'a\\'\n'
[map to_str, "a'\n"] # --> ["'a\\'\n'"]
lib/Aion/Format/Html.pm view on Meta::CPAN
my $re_proposal = qr/[.?!â¦]/;
my @S; # маÑÑив оÑкÑÑваÑÑиÑ
Ñегов [tag, '<tag ...>']
# ФÑнкÑÐ¸Ñ ÑикÑиÑÑÐµÑ ÑÑÑаниÑÑ Ð¸ ÑбÑаÑÑÐ²Ð°ÐµÑ ÑÑÑÑÑики
my $make_page = sub {
push @pages, join "", @page, map { "</$_->[0]>" } reverse @S;
$i_page = $c = $is_proposal = 0;
@page = map $_->[1], @S;
};
for(grep length, split m{(
<[a-z] [^<>]* >
| </ \s* [a-z]\w* \s* >
| &(?: [a-z]\w* | \# \d+ | \#x[0-9a-f]+ ) ;?
| \n # ÐбзаÑ
| $re_proposal+ # ÐÑедложение
| \b # Слово
)}xiu, $html) {
if(/^&/) {$c++} # html-Ñимвол
elsif(/^<\/\s*([a-z]\w*)/) { # закÑÑваÑÑий Ñег
my $tag = lc $1;
eval { out_tag @S, $tag };
next if $@;
# </p> пÑевÑаÑаем в <p></p>
$_ = "<p></p>" if $tag eq "p";
}
elsif(/^<([a-z]\w*)/) { in_tag @S, lc $1, $_ } # Ñег
else {$c += length} # ÑекÑÑ
push @page, $_; # накапливаем ÑÐ¸Ð¼Ð²Ð¾Ð»Ñ Ð² маÑÑиве @page
next if $c < $symbols_on_page; # ÑÑÑаниÑÑ Ð½Ðµ набÑали - Ñогда на next
$c_page = $c, $i_page = @page if !$i_page;
# ÐÑоÑмаÑÑиваем впеÑÑд пока не найдÑм гÑаниÑÑ Ð¸Ð»Ð¸ не доÑÑигнем огÑаниÑениÑ
if(/^\n/) { $make_page->() } # ÐбзаÑ
elsif(!$is_proposal && /^$re_proposal/) { $i_page = @page; $c_page = $c; $is_proposal = 1 }
elsif($c >= $max) {
# ÐÑли ÑледÑÑÑий за пÑедложением или Ñловом ÑÐ»ÐµÐ¼ÐµÐ½Ñ - пÑобелÑ, Ñо добавлÑем иÑ
к ÑÑÑаниÑе
$c_page -= length $page[$i_page++] if $page[$i_page] =~ /^\s/;
my @x = splice @page, $i_page;
$make_page->();
push @page, @x;
$c -= $c_page;
}
}
$make_page->() if @page;
# ÐÑли ÑÐ°Ð·Ð¼ÐµÑ Ð¿Ð¾Ñледней ÑÑÑаниÑÑ Ð¼ÐµÐ½ÑÑе Ñем 2/3, Ñо добавлÑем ÐµÑ Ðº пÑедпоÑледней
$pages[$#pages - 1] .= pop @pages if @pages > 1 and length($pages[$#pages]) < $symbols_on_page * 2 / 3;
#my $len = 0; $len += length for @pages;
#die "СÑммаÑнÑй ÑÐ°Ð·Ð¼ÐµÑ ÑÑÑÐ°Ð½Ð¸Ñ Ð½Ðµ изменилÑÑ: " . length($html) . " == $len pages=" . @pages . " ->\n\n$html" if $len == length $html;
my ($end1) = $html =~ m!([^<>\s]{1,13})\s*(</?\w[^<>]*>\s*)*$!a;
my ($end2) = $pages[$#pages] =~ m!([^<>\s]{1,13})\s*(</?\w[^<>]*>\s*)*$!a;
die "ÐонÑÑ ÑекÑÑа и поÑледней ÑÑÑаниÑÑ Ð½Ðµ ÑÑ
одÑÑÑÑ! `$end1` <> `$end2`" if $end1 ne $end2;
return @pages;
}
our %TAG2SPACE = (
"br" => "\n",
lib/Aion/Format/Url.pm view on Meta::CPAN
$link{path} = "/";
} else { delete $link{path} }
$link{orig} = $orig;
$link{onpage} = $onpage;
$link{link} = join "", $link{proto}, "://",
exists $link{user} || exists $link{pass}? ($link{user},
exists $link{pass}? ":$link{pass}": (), '@'): (),
$link{dom},
$link{path},
length($link{query})? ("?", $link{query}): (),
length($link{hash})? ("#", $link{hash}): (),
;
return \%link;
}
# ÐоÑмализÑÐµÑ url
sub normalize_url($;$$) {
parse_url($_[0], $_[1], $_[2])->{link}
}
t/aion/format.t view on Meta::CPAN
use common::sense; use open qw/:std :utf8/; use Test::More 0.98; sub _mkpath_ { my ($p) = @_; length($`) && !-e $`? mkdir($`, 0755) || die "mkdir $`: $!": () while $p =~ m!/!g; $p } BEGIN { use Scalar::Util qw//; use Carp qw//; $SIG{__DIE__} = sub { ...
#
# Aion::Format - Perl extension for formatting numbers, colorizing output and so on
#
# # VERSION
#
# 0.0.9
#
# # SYNOPSIS
#
subtest 'SYNOPSIS' => sub {
t/aion/format.t view on Meta::CPAN
# ## KiB ()
#
# The constant is one kibibyte.
#
done_testing; }; subtest 'KiB ()' => sub {
::is scalar do {KiB}, scalar do{2**10}, 'KiB # -> 2**10';
#
# ## xxL ()
#
# Maximum length in data LongText mysql and mariadb.
# L - large.
#
done_testing; }; subtest 'xxL ()' => sub {
::is scalar do {xxL}, scalar do{4*GiB-1}, 'xxL # -> 4*GiB-1';
#
# ## xxM ()
#
# Maximum length in data MediumText mysql and mariadb.
# M - medium.
#
done_testing; }; subtest 'xxM ()' => sub {
::is scalar do {xxM}, scalar do{16*MiB-1}, 'xxM # -> 16*MiB-1';
#
# ## xxR ()
#
# Maximum length in data Text mysql and mariadb.
# R - regularity.
#
done_testing; }; subtest 'xxR ()' => sub {
::is scalar do {xxR}, scalar do{64*KiB-1}, 'xxR # -> 64*KiB-1';
#
# ## xxS ()
#
# Maximum length in data TinyText mysql and mariadb.
# S - small.
#
done_testing; }; subtest 'xxS ()' => sub {
::is scalar do {xxS}, scalar do{255}, 'xxS # -> 255';
#
# ## to_str (;$scalar)
#
# Converts to string perl without interpolation.
#
t/aion/format/html.t view on Meta::CPAN
use common::sense; use open qw/:std :utf8/; use Test::More 0.98; sub _mkpath_ { my ($p) = @_; length($`) && !-e $`? mkdir($`, 0755) || die "mkdir $`: $!": () while $p =~ m!/!g; $p } BEGIN { use Scalar::Util qw//; use Carp qw//; $SIG{__DIE__} = sub { ...
#
# Aion::Format::Html - Perl extension for formatting HTML
#
# # SYNOPSIS
#
subtest 'SYNOPSIS' => sub {
use Aion::Format::Html;
::is scalar do {from_html "<b>!</b>"}, "!", 'from_html "<b>!</b>" # => !';
::is scalar do {to_html "<a>"}, "<a>", 'to_html "<a>" # => <a>';
t/aion/format/json.t view on Meta::CPAN
use common::sense; use open qw/:std :utf8/; use Test::More 0.98; sub _mkpath_ { my ($p) = @_; length($`) && !-e $`? mkdir($`, 0755) || die "mkdir $`: $!": () while $p =~ m!/!g; $p } BEGIN { use Scalar::Util qw//; use Carp qw//; $SIG{__DIE__} = sub { ...
#
# Aion::Format::Json - Perl extension for formatting JSON
#
# # SYNOPSIS
#
subtest 'SYNOPSIS' => sub {
use Aion::Format::Json;
::is scalar do {to_json {a => 10}}, "{\n \"a\": 10\n}\n", 'to_json {a => 10} # => {\n "a": 10\n}\n';
::is_deeply scalar do {from_json '[1, "5"]'}, scalar do {[1, "5"]}, 'from_json \'[1, "5"]\' # --> [1, "5"]';
t/aion/format/url.t view on Meta::CPAN
use common::sense; use open qw/:std :utf8/; use Test::More 0.98; sub _mkpath_ { my ($p) = @_; length($`) && !-e $`? mkdir($`, 0755) || die "mkdir $`: $!": () while $p =~ m!/!g; $p } BEGIN { use Scalar::Util qw//; use Carp qw//; $SIG{__DIE__} = sub { ...
#
# Aion::Format::Url - the utitlities for encode and decode the urls
#
# # SYNOPSIS
#
subtest 'SYNOPSIS' => sub {
use Aion::Format::Url;
::is scalar do {to_url_params {a => 1, b => [[1,2],3,{x=>10}]}}, "a&b[][]&b[][]=2&b[]=3&b[][x]=10", 'to_url_params {a => 1, b => [[1,2],3,{x=>10}]} # => a&b[][]&b[][]=2&b[]=3&b[][x]=10';
( run in 0.290 second using v1.01-cache-2.11-cpan-65fba6d93b7 )