view release on metacpan or search on metacpan
373374375376377378379380381382383384385386387388389390391392393394395396397398399400401```perl
xxS
# -> 255
```
## to_str (;$scalar)
Converts to string perl without interpolation.
```perl
to_str
"a'\n"
# => 'a\\'\n'
[
map
to_str,
"a'\n"
]
# --> ["'a\\'\n'"]
```
## from_str (;$one_quote_str)
Converts from string perl without interpolation.
```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
372373374375376377378379380381382383384385386387388389390391392393394395396397398399400```perl
xxS
# -> 255
```
## to_str (;$scalar)
Converts to string perl without interpolation.
```perl
to_str
"a'\n"
# => 'a\\'\n'
[
map
to_str,
"a'\n"
]
# --> ["'a\\'\n'"]
```
## from_str (;$one_quote_str)
Converts from string perl without interpolation.
```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
9293949596979899100101102103104105106107108109110111112#@category ПреобразованиÑ
# Проводит ÑоответÑтвиÑ
#
# matches "...", qr/.../ => sub {...}, ...
#
sub
matches($@) {
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
155156157158159160161162163164165166167168169170171172173174175sub
from_str(;$) {
my
(
$s
) =
@_
== 0?
$_
:
@_
;
$s
=~ s/^
'(.*)'
\z/$1/s;
$s
=~ s/\\([\\'])/$1/g;
$s
}
# Упрощённый Ñзык регулÑрок
sub
nous($) {
my
(
$templates
) =
@_
;
my
$x
=
join
"|"
,
map
{
matches
$_
,
# Срезаем вÑе пробелы Ñ ÐºÐ¾Ð½Ñ†Ð°:
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
239240241242243244245246247248249250251252253254255256257258259260261262263264
}
}
$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($;$) {
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
723724725726727728729730731732733734735736737738739740741742743744745746747748749750Maximum
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'"]
=head2 from_str (;$one_quote_str)
Converts from string perl 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
104010411042104310441045104610471048104910501051105210531054105510561057105810591060# ♠«пики» (ÐºÐ°Ñ€Ñ‚Ð¾Ñ‡Ð½Ð°Ñ Ð¼Ð°Ñть) ♠ ♠
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
11481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170my
@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
130513061307130813091310131113121313131413151316131713181319132013211322132313241325
$_
}
# Ð’Ñе, кроме запрещённых:
# 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
137413751376137713781379138013811382138313841385138613871388138913901391139213931394ins
isindex
kbd
keygen
li
main
map
marquee
mark
menu
meter
nav
nobr
noembed
noframes
lib/Aion/Format/Html.pm view on Meta::CPAN
142914301431143214331434143514361437143814391440144114421443144414451446144714481449tt
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
4243444546474849505152535455565758596061to_json
# -> $result
```
## from_json (;$string)
Parse string in json
format
to perl structure.
```perl
from_json
'{"a": 10}'
# --> {a => 10}
[
map
from_json,
"{}"
,
"2"
]
# --> [{}, 2]
```
# AUTHOR
Yaroslav O. Kosmina [darviarush
.ru](darviarush
.ru)
# LICENSE
âš– *
*GPLv3
**
lib/Aion/Format/Json.pm view on Meta::CPAN
757677787980818283848586878889909192939495
local
$_
=
$data
;
to_json
# -> $result
=head2 from_json (;$string)
Parse string in json format to perl structure.
from_json '{"a": 10}' # --> {a => 10}
[map from_json, "{}", "2"] # --> [{}, 2]
=head1 AUTHOR
Yaroslav O. Kosmina LL<mailto:darviarush@mail.ru>
=head1 LICENSE
âš– B<GPLv3>
=head1 COPYRIGHT
lib/Aion/Format/Url.md view on Meta::CPAN
181920212223242526272829303132333435363738# SUBROUTINES
## to_url_param (;$scalar)
Escape
scalar
to part of url search.
```perl
to_url_param
"a b"
# => a+b
[
map
to_url_param,
"a b"
,
"ðŸ¦"
]
# --> [qw/a+b %1F981/]
```
## to_url_params (;$hash_ref)
Generates the search part of the url.
```perl
local
$_
= {
a
=> 1,
b
=> [[1,2],3,{
x
=>10}]};
to_url_params
# => a&b[][]&b[][]=2&b[]=3&b[][x]=10
```
lib/Aion/Format/Url.pm view on Meta::CPAN
202122232425262728293031323334353637383940414243444546474849505152535455
$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
}
}
# # Ð’ multipart/form-data
# sub to_multipart(;$) {
# my ($param) = @_ == 0? $_: @_;
# $param =~ s/[&=?#+\s]/$& eq " "? "+": sprintf "%%%02X", ord $&/ge;
# $param
# }
lib/Aion/Format/Url.pm view on Meta::CPAN
177178179180181182183184185186187188189190191192193194195196The utitlities
for
encode and decode the urls.
=head1 SUBROUTINES
=head2 to_url_param (;$scalar)
Escape scalar to part of url search.
to_url_param "a b" # => a+b
[map to_url_param, "a b", "ðŸ¦"] # --> [qw/a+b %1F981/]
=head2 to_url_params (;$hash_ref)
Generates the search part 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.t view on Meta::CPAN
372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401done_testing; }; subtest
'xxS ()'
=>
sub
{
::is
scalar
do
{xxS},
scalar
do
{255},
'xxS # -> 255'
;
#
# ## to_str (;$scalar)
#
# Converts to string perl without interpolation.
#
done_testing; }; subtest
'to_str (;$scalar)'
=>
sub
{
::is
scalar
do
{to_str
"a'\n"
},
"'a\\'\n'"
,
'to_str "a\'\n" # => \'a\\\'\n\''
;
::is_deeply
scalar
do
{[
map
to_str,
"a'\n"
]},
scalar
do
{[
"'a\\'\n'"
]},
'[map to_str, "a\'\n"] # --> ["\'a\\\'\n\'"]'
;
#
# ## from_str (;$one_quote_str)
#
# Converts from string perl without interpolation.
#
done_testing; }; subtest
'from_str (;$one_quote_str)'
=>
sub
{
::is
scalar
do
{from_str
"'a\\'\n'"
},
"a'\n"
,
'from_str "\'a\\\'\n\'" # => a\'\n'
;
::is_deeply
scalar
do
{[
map
from_str,
"'a\\'\n'"
]},
scalar
do
{[
"a'\n"
]},
'[map from_str, "\'a\\\'\n\'"] # --> ["a\'\n"]'
;
#
# # SUBROUTINES/METHODS
#
# # AUTHOR
#
# Yaroslav O. Kosmina <dart@cpan.org>
#
# # LICENSE
#
t/aion/format/json.t view on Meta::CPAN
424344454647484950515253545556575859606162::is
scalar
do
{to_json},
scalar
do
{
$result
},
'to_json # -> $result'
;
#
# ## from_json (;$string)
#
# Parse string in json format to perl structure.
#
done_testing; }; subtest
'from_json (;$string)'
=>
sub
{
::is_deeply
scalar
do
{from_json
'{"a": 10}'
},
scalar
do
{{
a
=> 10}},
'from_json \'{"a": 10}\' # --> {a => 10}'
;
::is_deeply
scalar
do
{[
map
from_json,
"{}"
,
"2"
]},
scalar
do
{[{}, 2]},
'[map from_json, "{}", "2"] # --> [{}, 2]'
;
#
# # AUTHOR
#
# Yaroslav O. Kosmina [darviarush@mail.ru](darviarush@mail.ru)
#
# # LICENSE
#
# âš– **GPLv3**
#
t/aion/format/url.t view on Meta::CPAN
1819202122232425262728293031323334353637#
# # SUBROUTINES
#
# ## to_url_param (;$scalar)
#
# Escape scalar to part of url search.
#
done_testing; }; subtest
'to_url_param (;$scalar)'
=>
sub
{
::is
scalar
do
{to_url_param
"a b"
},
"a+b"
,
'to_url_param "a b" # => a+b'
;
::is_deeply
scalar
do
{[
map
to_url_param,
"a b"
,
"ðŸ¦"
]},
scalar
do
{[
qw/a+b %1F981/
]},
'[map to_url_param, "a b", "ðŸ¦"] # --> [qw/a+b %1F981/]'
;
#
# ## to_url_params (;$hash_ref)
#
# Generates the search part of the url.
#
done_testing; }; subtest
'to_url_params (;$hash_ref)'
=>
sub
{
local
$_
= {
a
=> 1,
b
=> [[1,2],3,{
x
=>10}]};
::is
scalar
do
{to_url_params},
"a&b[][]&b[][]=2&b[]=3&b[][x]=10"
,
'to_url_params # => a&b[][]&b[][]=2&b[]=3&b[][x]=10'
;