view release on metacpan or search on metacpan
```perl
xxS # -> 255
```
## to_str (;$scalar)
ÐÑеобÑазование в ÑÑÑÐ¾ÐºÑ Perl без инÑеÑполÑÑии.
```perl
to_str "a'\n" # => 'a\\'\n'
[map to_str, "a'\n"] # --> ["'a\\'\n'"]
```
## from_str (;$one_quote_str)
ÐÑеобÑазование из ÑÑÑоки Perl без инÑеÑполÑÑии.
```perl
from_str "'a\\'\n'" # => a'\n
[map from_str, "'a\\'\n'"] # --> ["a'\n"]
```
# SUBROUTINES/METHODS
# AUTHOR
Yaroslav O. Kosmina <dart@cpan.org>
# LICENSE
lib/Aion/Format.md view on Meta::CPAN
```perl
xxS # -> 255
```
## to_str (;$scalar)
ÐÑеобÑазование в ÑÑÑÐ¾ÐºÑ Perl без инÑеÑполÑÑии.
```perl
to_str "a'\n" # => 'a\\'\n'
[map to_str, "a'\n"] # --> ["'a\\'\n'"]
```
## from_str (;$one_quote_str)
ÐÑеобÑазование из ÑÑÑоки Perl без инÑеÑполÑÑии.
```perl
from_str "'a\\'\n'" # => a'\n
[map from_str, "'a\\'\n'"] # --> ["a'\n"]
```
# SUBROUTINES/METHODS
# AUTHOR
Yaroslav O. Kosmina <dart@cpan.org>
# LICENSE
lib/Aion/Format.pm view on Meta::CPAN
#@category ÐÑеобÑазованиÑ
# ÐÑÐ¾Ð²Ð¾Ð´Ð¸Ñ ÑооÑвеÑÑÑвиÑ
#
# replace "...", qr/.../ => sub {...}, ...
#
sub matches($@) { goto &replace }
sub replace($@) {
my $s = shift;
my $i = 0;
my $re = join "\n| ", map { $i++ % 2 == 0? "(?<I$i> $_ )": () } @_;
my $arg = \@_;
my $fn = sub {
for my $k (keys %+) {
return $arg->[$k]->() if do { $k =~ /^I(\d+)\z/ and $k = $1 }
}
};
$s =~ s/$re/$fn->()/gex;
$s
lib/Aion/Format.pm view on Meta::CPAN
sub from_str(;$) {
my ($s) = @_ == 0? $_: @_;
$s =~ s/^'(.*)'\z/$1/s;
$s =~ s/\\([\\'])/$1/g;
$s
}
# УпÑоÑÑннÑй ÑзÑк ÑегÑлÑÑок
sub nous($) {
my ($templates) = @_;
my $x = join "|", map {
replace $_,
# СÑезаем вÑе пÑÐ¾Ð±ÐµÐ»Ñ Ñ ÐºÐ¾Ð½Ñа:
qr!\s*$! => sub {},
# СÑезаем вÑе наÑалÑнÑе ÑÑÑоки:
qr!^([ \t]*\n)*! => sub {},
# С наÑала каждой ÑÑÑоки 4 пÑобела или 0-3 пÑобела и ÑабÑлÑÑиÑ:
qr!^( {4}| {0,3}\t)!m => sub {},
# ÐÑÐ¾Ð±ÐµÐ»Ñ Ð² конÑе ÑÑÑоки и пÑобелÑнÑе ÑÑÑоки заÑем заменÑем на \s*
qr!([ \t]*\n)+! => sub { "\\s*" },
# ÐаменÑем вÑе пеÑеменнÑе {{}}:
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;
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 = "";
lib/Aion/Format.pm view on Meta::CPAN
Maximum length of TinyText mysql and mariadb data.
S - small.
xxS # -> 255
=head2 to_str (;$scalar)
Convert to Perl string without interpolation.
to_str "a'\n" # => 'a\\'\n'
[map to_str, "a'\n"] # --> ["'a\\'\n'"]
=head2 from_str (;$one_quote_str)
Conversion from Perl string without interpolation.
from_str "'a\\'\n'" # => a'\n
[map from_str, "'a\\'\n'"] # --> ["a'\n"]
=head1 SUBROUTINES/METHODS
=head1 AUTHOR
Yaroslav O. Kosmina L<mailto:dart@cpan.org>
=head1 LICENSE
â B<GPLv3>
lib/Aion/Format/Html.pm view on Meta::CPAN
# â «пики» (каÑÑоÑÐ½Ð°Ñ Ð¼Ð°ÑÑÑ) ♠ ♠
spades => 9824,
# ⣠«ÑÑеÑÑ» (каÑÑоÑÐ½Ð°Ñ Ð¼Ð°ÑÑÑ) ♣ ♣
clubs => 9827,
# ⥠«ÑеÑвÑ» (каÑÑоÑÐ½Ð°Ñ Ð¼Ð°ÑÑÑ) ♥ ♥
hearts => 9829,
# ⦠«бÑбнÑ» (каÑÑоÑÐ½Ð°Ñ Ð¼Ð°ÑÑÑ) ♦ ♦
diams => 9830,
);
sub _set(@) { +{ map { $_ => 1 } @_ } }
# Теги не имеÑÑие закÑÑваÑÑего Ñега
our %SINGLE_TAG = %{ _set qw/area base br col embed hr img input link meta param source track wbr/ };
# <li> закÑÑваеÑÑÑ, еÑли пÑиÑ
Ð¾Ð´Ð¸Ñ </ol> или </ul>
our %TOP_CLOSE_TAG = (
li => _set(qw/ol ul/),
caption => _set(qw/table/),
thead => _set(qw/table/),
tbody => _set(qw/table/),
lib/Aion/Format/Html.pm view on Meta::CPAN
my @page; # маÑÑив ÑлеменÑов ÑекÑÑа и Ñегов ÑекÑÑей ÑÑÑаниÑÑ
my $c = 0; # колиÑеÑÑво Ñимволов в ÑекÑÑей ÑÑÑаниÑе
my $i_page = 0; # Ð¸Ð½Ð´ÐµÐºÑ ÑлеменÑа @page коÑоÑÑй пÑивÑÑил ÑÐ°Ð·Ð¼ÐµÑ ÑÑÑаниÑÑ
my $c_page = 0; # колиÑеÑÑво Ñимволов @page по $i_page
my $is_proposal = 0; # РконÑе ÑекÑÑей ÑÑÑаниÑÑ Ð¾Ð±Ð½Ð°ÑÑжен ÐºÐ¾Ð½ÐµÑ Ð¿ÑедложениÑ
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) {
lib/Aion/Format/Html.pm view on Meta::CPAN
$_
}
# ÐÑе, кÑоме запÑеÑÑннÑÑ
:
# applet, script, style, embed, object, param,
# video, audio, source, track, frame, frameset, iframe, comment
# html, head, body, title, meta, base, basefont, bgsound, link
# form, keygen, output, textarea, select, option, optgroup, legend, label, input
# plaintext, xmp
# Ð Ñак же ÑдалÑÐµÑ Ð°ÑÑибÑÑÑ Ð½Ð°ÑинаÑÑиеÑÑ Ð½Ð° "on", name, for, formaction и дÑ..
my %SAFE_TAG = map {$_=>1} qw/
a
abbr
acronym
address
area
article
aside
b
lib/Aion/Format/Html.pm view on Meta::CPAN
ins
isindex
kbd
keygen
li
main
map
marquee
mark
menu
meter
nav
nobr
noembed
noframes
lib/Aion/Format/Html.pm view on Meta::CPAN
tt
u
ul
var
wbr
/;
my %SAFE_ATTR = map {$_=>1} qw/
pubdate datetime
open optimum
dir lang language style tabindex title high low hreflang icon
max min
href media ping rel rev name type
class
lib/Aion/Format/Json.md view on Meta::CPAN
to_json # -> $result
```
## from_json (;$string)
РазбиÑÐ°ÐµÑ ÑÑÑÐ¾ÐºÑ Ð² ÑоÑмаÑе JSON в ÑÑÑÑкÑÑÑÑ Perl.
```perl
from_json '{"a": 10}' # --> {a => 10}
[map from_json, "{}", "2"] # --> [{}, 2]
```
# AUTHOR
Yaroslav O. Kosmina <darviarush@mail.ru>
# LICENSE
â **GPLv3**
lib/Aion/Format/Json.pm view on Meta::CPAN
local $_ = $data;
to_json # -> $result
=head2 from_json (;$string)
Parses a JSON string into a Perl structure.
from_json '{"a": 10}' # --> {a => 10}
[map from_json, "{}", "2"] # --> [{}, 2]
=head1 AUTHOR
Yaroslav O. Kosmina L<mailto:darviarush@mail.ru>
=head1 LICENSE
â B<GPLv3>
=head1 COPYRIGHT
lib/Aion/Format/Url.md view on Meta::CPAN
# SUBROUTINES
## to_url_param (;$scalar)
ÐкÑаниÑÑÐµÑ `$scalar` Ð´Ð»Ñ ÑаÑÑи поиÑка URL.
```perl
to_url_param "a b" # => a+b
[map to_url_param, "a b", "ð¦"] # --> [qw/a+b %F0%9F%A6%81/]
```
## to_url_params (;$hash_ref)
ÐенеÑиÑÑÐµÑ Ð¿Ð¾Ð¸ÑковÑÑ ÑаÑÑÑ URL-адÑеÑа.
```perl
local $_ = {a => 1, b => [[1,2],3,{x=>10}]};
to_url_params # => a&b[][]&b[][1]=2&b[1]=3&b[2][x]=10
```
lib/Aion/Format/Url.pm view on Meta::CPAN
my ($param) = @_ == 0? $_: @_;
my @R;
my @S = [$param];
while(@S) {
my $u = pop @S;
my ($x, $key) = @$u;
if(ref $x eq "HASH") {
push @S, defined($key)
? (map [$x->{$_}, "$key\[${\to_url_param}]"], sort keys %$x)
: (map [$x->{$_}, to_url_param], sort keys %$x)
;
}
elsif(ref $x eq "ARRAY") {
my $i = '';
push @S, map [$_, "$key\[${\($i++)}]"], @$x;
}
elsif(!defined $x) {}
elsif($x eq 1) { unshift @R, $key }
else {
unshift @R, join "=", $key, to_url_param $x;
}
}
join "&", @R
}
lib/Aion/Format/Url.pm view on Meta::CPAN
Utilities for encoding and decoding URLs.
=head1 SUBROUTINES
=head2 to_url_param (;$scalar)
Escapes C<$scalar> for the search part of the URL.
to_url_param "a b" # => a+b
[map to_url_param, "a b", "ð¦"] # --> [qw/a+b %F0%9F%A6%81/]
=head2 to_url_params (;$hash_ref)
Generates the search portion of the URL.
local $_ = {a => 1, b => [[1,2],3,{x=>10}]};
to_url_params # => a&b[][]&b[][1]=2&b[1]=3&b[2][x]=10
=over
t/aion/format.t view on Meta::CPAN
::done_testing; }; subtest 'xxS ()' => sub {
local ($::_g0 = do {xxS}, $::_e0 = do {255}); ::ok defined($::_g0) == defined($::_e0) && $::_g0 eq $::_e0, 'xxS # -> 255' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
#
# ## to_str (;$scalar)
#
# ÐÑеобÑазование в ÑÑÑÐ¾ÐºÑ Perl без инÑеÑполÑÑии.
#
::done_testing; }; subtest 'to_str (;$scalar)' => sub {
local ($::_g0 = do {to_str "a'\n"}, $::_e0 = "'a\\'\n'"); ::ok $::_g0 eq $::_e0, 'to_str "a\'\n" # => \'a\\\'\n\'' or ::diag ::_string_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
local ($::_g0 = do {[map to_str, "a'\n"]}, $::_e0 = do {["'a\\'\n'"]}); ::is_deeply $::_g0, $::_e0, '[map to_str, "a\'\n"] # --> ["\'a\\\'\n\'"]' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
#
# ## from_str (;$one_quote_str)
#
# ÐÑеобÑазование из ÑÑÑоки Perl без инÑеÑполÑÑии.
#
::done_testing; }; subtest 'from_str (;$one_quote_str)' => sub {
local ($::_g0 = do {from_str "'a\\'\n'"}, $::_e0 = "a'\n"); ::ok $::_g0 eq $::_e0, 'from_str "\'a\\\'\n\'" # => a\'\n' or ::diag ::_string_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
local ($::_g0 = do {[map from_str, "'a\\'\n'"]}, $::_e0 = do {["a'\n"]}); ::is_deeply $::_g0, $::_e0, '[map from_str, "\'a\\\'\n\'"] # --> ["a\'\n"]' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
#
# # SUBROUTINES/METHODS
#
# # AUTHOR
#
# Yaroslav O. Kosmina <dart@cpan.org>
#
# # LICENSE
#
t/aion/format/json.t view on Meta::CPAN
local ($::_g0 = do {to_json}, $::_e0 = do {$result}); ::ok defined($::_g0) == defined($::_e0) && $::_g0 eq $::_e0, 'to_json # -> $result' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
#
# ## from_json (;$string)
#
# РазбиÑÐ°ÐµÑ ÑÑÑÐ¾ÐºÑ Ð² ÑоÑмаÑе JSON в ÑÑÑÑкÑÑÑÑ Perl.
#
::done_testing; }; subtest 'from_json (;$string)' => sub {
local ($::_g0 = do {from_json '{"a": 10}'}, $::_e0 = do {{a => 10}}); ::is_deeply $::_g0, $::_e0, 'from_json \'{"a": 10}\' # --> {a => 10}' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
local ($::_g0 = do {[map from_json, "{}", "2"]}, $::_e0 = do {[{}, 2]}); ::is_deeply $::_g0, $::_e0, '[map from_json, "{}", "2"] # --> [{}, 2]' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
#
# # AUTHOR
#
# Yaroslav O. Kosmina <darviarush@mail.ru>
#
# # LICENSE
#
# â **GPLv3**
#
t/aion/format/url.pm view on Meta::CPAN
# my ($param) = @_ == 0? $_: @_;
#
# my @R;
# my @S = [$param];
# while(@S) {
# my $u = pop @S;
# my ($x, $key) = @$u;
#
# if(ref $x eq "HASH") {
# push @S, defined($key)
# ? (map [$x->{$_}, "$key\[${\to_url_param}]"], sort keys %$x)
# : (map [$x->{$_}, to_url_param], sort keys %$x)
# ;
# }
# elsif(ref $x eq "ARRAY") {
# push @S, map [$_, "$key\[]"], @$x;
# }
# elsif(!defined $x) {}
# elsif($x eq 1) { unshift @R, $key }
# else {
# unshift @R, join "=", $key, to_url_param $x;
# }
# }
#
# join "&", @R
# }
t/aion/format/url.pm view on Meta::CPAN
# Utilities for encoding and decoding URLs.
#
# =head1 SUBROUTINES
#
# =head2 to_url_param (;$scalar)
#
# Escapes C<$scalar> for the search part of the URL.
#
# to_url_param "a b" # => a+b
#
# [map to_url_param, "a b", "ð¦"] # --> [qw/a+b %F0%9F%A6%81/]
#
# =head2 to_url_params (;$hash_ref)
#
# Generates the search portion of the URL.
#
# local $_ = {a => 1, b => [[1,2],3,{x=>10}]};
# to_url_params # => a&b[][]&b[][]=2&b[]=3&b[][x]=10
#
# =over
#
t/aion/format/url.t view on Meta::CPAN
#
# # SUBROUTINES
#
# ## to_url_param (;$scalar)
#
# ÐкÑаниÑÑÐµÑ `$scalar` Ð´Ð»Ñ ÑаÑÑи поиÑка URL.
#
::done_testing; }; subtest 'to_url_param (;$scalar)' => sub {
local ($::_g0 = do {to_url_param "a b"}, $::_e0 = "a+b"); ::ok $::_g0 eq $::_e0, 'to_url_param "a b" # => a+b' or ::diag ::_string_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
local ($::_g0 = do {[map to_url_param, "a b", "ð¦"]}, $::_e0 = do {[qw/a+b %F0%9F%A6%81/]}); ::is_deeply $::_g0, $::_e0, '[map to_url_param, "a b", "ð¦"] # --> [qw/a+b %F0%9F%A6%81/]' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef ...
#
# ## to_url_params (;$hash_ref)
#
# ÐенеÑиÑÑÐµÑ Ð¿Ð¾Ð¸ÑковÑÑ ÑаÑÑÑ URL-адÑеÑа.
#
::done_testing; }; subtest 'to_url_params (;$hash_ref)' => sub {
local $_ = {a => 1, b => [[1,2],3,{x=>10}]};
local ($::_g0 = do {to_url_params}, $::_e0 = "a&b[][]&b[][1]=2&b[1]=3&b[2][x]=10"); ::ok $::_g0 eq $::_e0, 'to_url_params # => a&b[][]&b[][1]=2&b[1]=3&b[2][x]=10' or ::diag ::_string_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;