Aion
view release on metacpan or search on metacpan
lib/Aion/Types.md view on Meta::CPAN
Bin
NonEmptyStr
StartsWith
EndsWith
Email
Tel
Url
Path
Html
StrDate
StrDateTime
StrMatch[qr/.../]
ClassName[A]
RoleName[A]
Rat
Num
PositiveNum
Int
PositiveInt
Nat
Ref
lib/Aion/Types.md view on Meta::CPAN
## StrDate
ÐаÑа в ÑоÑмаÑе `yyyy-mm-dd`.
```perl
"2001-01-12" ~~ StrDate # -> 1
"01-01-01" ~~ StrDate # -> ""
```
## StrDateTime
ÐаÑа и вÑÐµÐ¼Ñ Ð² ÑоÑмаÑе `yyyy-mm-dd HH:MM:SS`.
```perl
"2012-12-01 00:00:00" ~~ StrDateTime # -> 1
"2012-12-01 00:00:00 " ~~ StrDateTime # -> ""
```
## StrMatch[qr/.../]
СопоÑÑавлÑÐµÑ ÑÑÑÐ¾ÐºÑ Ñ ÑегÑлÑÑнÑм вÑÑажением.
```perl
' abc ' ~~ StrMatch[qr/abc/] # -> 1
' abbc ' ~~ StrMatch[qr/abc/] # -> ""
```
lib/Aion/Types.pm view on Meta::CPAN
where { $_ =~ M };
subtype "EndsWith[S]", as &Str,
init_where { N = qr/${\ quotemeta A}$/ },
where { $_ =~ N };
subtype "Email", as &Str, where { /@/ };
subtype "Tel", as &Str, where { /^\+\d{7,}\z/ };
subtype "Url", as &Str, where { /^https?:\/\// };
subtype "Path", as &Str, where { /^\// };
subtype "Html", as &Str, where { /^\s*<(!doctype\s+html|html)\b/i };
subtype "StrDate", as &Str, where { /^\d{4}-\d{2}-\d{2}\z/ };
subtype "StrDateTime", as &Str, where { /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\z/ };
subtype "StrMatch[qr/.../]", as &Str, where { $_ =~ A };
subtype "ClassName", as &Str, where { !!$_->can('new') };
subtype "RoleName", as &Str, where { !$_->can('new') && !!(@{"$_\::ISA"} || first { *{$_}{CODE} } values %{"$_\::"}) };
subtype "Num", as &Str, where { looks_like_number($_) && /[\dfn]\z/i };
subtype "PositiveNum", as &Num, where { $_ >= 0 };
subtype "Int", as &Num, where { /^-?\d+\z/ };
subtype "PositiveInt", as &Int, where { $_ >= 0 };
subtype "Nat", as &Int, where { $_ > 0 };
subtype "Rat", as &Str, where { &Num->test || /^(-?\d+(\/\d+)?)\z/in };
lib/Aion/Types.pm view on Meta::CPAN
Bin
NonEmptyStr
StartsWith
EndsWith
Email
Tel
Url
Path
Html
StrDate
StrDateTime
StrMatch[qr/.../]
ClassName[A]
RoleName[A]
Rat
Num
PositiveNum
Int
PositiveInt
Nat
Ref
lib/Aion/Types.pm view on Meta::CPAN
" <!doctype html>" ~~ Html # -> 1
" <html1>" ~~ Html # -> ""
=head2 StrDate
Date in C<yyyy-mm-dd> format.
"2001-01-12" ~~ StrDate # -> 1
"01-01-01" ~~ StrDate # -> ""
=head2 StrDateTime
Date and time in the format C<yyyy-mm-dd HH:MM:SS>.
"2012-12-01 00:00:00" ~~ StrDateTime # -> 1
"2012-12-01 00:00:00 " ~~ StrDateTime # -> ""
=head2 StrMatch[qr/.../]
Matches a string against a regular expression.
' abc ' ~~ StrMatch[qr/abc/] # -> 1
' abbc ' ~~ StrMatch[qr/abc/] # -> ""
=head2 ClassName
t/aion/types.t view on Meta::CPAN
# Bin
# NonEmptyStr
# StartsWith
# EndsWith
# Email
# Tel
# Url
# Path
# Html
# StrDate
# StrDateTime
# StrMatch[qr/.../]
# ClassName[A]
# RoleName[A]
# Rat
# Num
# PositiveNum
# Int
# PositiveInt
# Nat
# Ref
t/aion/types.t view on Meta::CPAN
#
# ## StrDate
#
# ÐаÑа в ÑоÑмаÑе `yyyy-mm-dd`.
#
::done_testing; }; subtest 'StrDate' => sub {
local ($::_g0 = do {"2001-01-12" ~~ StrDate}, $::_e0 = do {1}); ::ok defined($::_g0) == defined($::_e0) && $::_g0 eq $::_e0, '"2001-01-12" ~~ StrDate # -> 1' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
local ($::_g0 = do {"01-01-01" ~~ StrDate}, $::_e0 = do {""}); ::ok defined($::_g0) == defined($::_e0) && $::_g0 eq $::_e0, '"01-01-01" ~~ StrDate # -> ""' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
#
# ## StrDateTime
#
# ÐаÑа и вÑÐµÐ¼Ñ Ð² ÑоÑмаÑе `yyyy-mm-dd HH:MM:SS`.
#
::done_testing; }; subtest 'StrDateTime' => sub {
local ($::_g0 = do {"2012-12-01 00:00:00" ~~ StrDateTime}, $::_e0 = do {1}); ::ok defined($::_g0) == defined($::_e0) && $::_g0 eq $::_e0, '"2012-12-01 00:00:00" ~~ StrDateTime # -> 1' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::...
local ($::_g0 = do {"2012-12-01 00:00:00 " ~~ StrDateTime}, $::_e0 = do {""}); ::ok defined($::_g0) == defined($::_e0) && $::_g0 eq $::_e0, '"2012-12-01 00:00:00 " ~~ StrDateTime # -> ""' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef ...
#
# ## StrMatch[qr/.../]
#
# СопоÑÑавлÑÐµÑ ÑÑÑÐ¾ÐºÑ Ñ ÑегÑлÑÑнÑм вÑÑажением.
#
::done_testing; }; subtest 'StrMatch[qr/.../]' => sub {
local ($::_g0 = do {' abc ' ~~ StrMatch[qr/abc/]}, $::_e0 = do {1}); ::ok defined($::_g0) == defined($::_e0) && $::_g0 eq $::_e0, '\' abc \' ~~ StrMatch[qr/abc/] # -> 1' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
local ($::_g0 = do {' abbc ' ~~ StrMatch[qr/abc/]}, $::_e0 = do {""}); ::ok defined($::_g0) == defined($::_e0) && $::_g0 eq $::_e0, '\' abbc \' ~~ StrMatch[qr/abc/] # -> ""' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
( run in 0.333 second using v1.01-cache-2.11-cpan-62ea2d55848 )