Aion

 view release on metacpan or  search on metacpan

lib/Aion/Types.md  view on Meta::CPAN

Strings, include numbers.

```perl
1.1 ~~ Str         # -> 1
"" ~~ Str          # -> 1
1.1.0 ~~ Str       # -> ""
```

## Uni

Unicode strings: with utf8-flag or decode to utf8 without error.

```perl
"↭" ~~ Uni    # -> 1
123 ~~ Uni    # -> ""
do {no utf8; "↭" ~~ Uni}    # -> 1
```

## Bin

Binary strings: without utf8-flag and octets with numbers less then 128.

```perl
123 ~~ Bin    # -> 1
"z" ~~ Bin    # -> 1
"↭" ~~ Bin    # -> ""
do {no utf8; "↭" ~~ Bin }   # -> ""
```

## StartsWith\[S]

The string starts with `S`.

```perl
"Hi, world!" ~~ StartsWith["Hi,"]	# -> 1
"Hi world!" ~~ StartsWith["Hi,"]	# -> ""
```

lib/Aion/Types.pm  view on Meta::CPAN

	subtype "Item", as &Any;
		subtype "Bool", as &Item, where { ref $_ eq "" and /^(1|0|)\z/ };
		subtype "Enum[A...]", as &Item, where { $_ ~~ ARGS };
		subtype "Maybe[A]", as &Item, where { !defined($_) || A->test };
		subtype "Undef", as &Item, where { !defined $_ };
		subtype "Defined", as &Item, where { defined $_ };
			subtype "Value", as &Defined, where { "" eq ref $_ };
				subtype "Version", as &Value, where { "VSTRING" eq ref \$_ };
				my $init_limit = sub { if(@{&ARGS} == 1) { SELF->{min} = 0; SELF->{max} = A } else { SELF->{min} = A; SELF->{max} = B } };
				subtype "Str", as &Value, where { "SCALAR" eq ref \$_ };
					subtype "Uni", as &Str,	where { utf8::is_utf8($_) || /[\x80-\xFF]/a };
					subtype "Bin", as &Str, where { !utf8::is_utf8($_) && !/[\x80-\xFF]/a };
					subtype "NonEmptyStr", as &Str,	where { /\S/ };
					subtype "StartsWith[S]", as &Str,
						init_where { M = qr/^${\ quotemeta A}/ },
						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?:\/\// };

lib/Aion/Types.pm  view on Meta::CPAN

=head2 Str

Strings, include numbers.

	1.1 ~~ Str         # -> 1
	"" ~~ Str          # -> 1
	1.1.0 ~~ Str       # -> ""

=head2 Uni

Unicode strings: with utf8-flag or decode to utf8 without error.

	"↭" ~~ Uni    # -> 1
	123 ~~ Uni    # -> ""
	do {no utf8; "↭" ~~ Uni}    # -> 1

=head2 Bin

Binary strings: without utf8-flag and octets with numbers less then 128.

	123 ~~ Bin    # -> 1
	"z" ~~ Bin    # -> 1
	"↭" ~~ Bin    # -> ""
	do {no utf8; "↭" ~~ Bin }   # -> ""

=head2 StartsWith[S]

The string starts with C<S>.

	"Hi, world!" ~~ StartsWith["Hi,"]	# -> 1
	"Hi world!" ~~ StartsWith["Hi,"]	# -> ""

=head2 EndsWith[S]

t/aion.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 - a postmodern object system for Perl 5, as `Moose` and `Moo`, but with improvements
# 
# # VERSION
# 
# 0.1
# 
# # SYNOPSIS
# 
subtest 'SYNOPSIS' => sub { 

t/aion/type.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::Type - class of validators
# 
# # SYNOPSIS
# 
subtest 'SYNOPSIS' => sub { 
use Aion::Type;

my $Int = Aion::Type->new(name => "Int", test => sub { /^-?\d+$/ });
::is scalar do {12   ~~ $Int}, "1", '12   ~~ $Int # => 1';

t/aion/types.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::Types is a library of validators. And it makes new validators
# 
# # SYNOPSIS
# 
subtest 'SYNOPSIS' => sub { 
use Aion::Types;

BEGIN {
    subtype SpeakOfKitty => as StrMatch[qr/\bkitty\b/i],

t/aion/types.t  view on Meta::CPAN

# Strings, include numbers.
# 
done_testing; }; subtest 'Str' => sub { 
::is scalar do {1.1 ~~ Str}, scalar do{1}, '1.1 ~~ Str         # -> 1';
::is scalar do {"" ~~ Str}, scalar do{1}, '"" ~~ Str          # -> 1';
::is scalar do {1.1.0 ~~ Str}, scalar do{""}, '1.1.0 ~~ Str       # -> ""';

# 
# ## Uni
# 
# Unicode strings: with utf8-flag or decode to utf8 without error.
# 
done_testing; }; subtest 'Uni' => sub { 
::is scalar do {"↭" ~~ Uni}, scalar do{1}, '"↭" ~~ Uni    # -> 1';
::is scalar do {123 ~~ Uni}, scalar do{""}, '123 ~~ Uni    # -> ""';
::is scalar do {do {no utf8; "↭" ~~ Uni}}, scalar do{1}, 'do {no utf8; "↭" ~~ Uni}    # -> 1';

# 
# ## Bin
# 
# Binary strings: without utf8-flag and octets with numbers less then 128.
# 
done_testing; }; subtest 'Bin' => sub { 
::is scalar do {123 ~~ Bin}, scalar do{1}, '123 ~~ Bin    # -> 1';
::is scalar do {"z" ~~ Bin}, scalar do{1}, '"z" ~~ Bin    # -> 1';
::is scalar do {"↭" ~~ Bin}, scalar do{""}, '"↭" ~~ Bin    # -> ""';
::is scalar do {do {no utf8; "↭" ~~ Bin }}, scalar do{""}, 'do {no utf8; "↭" ~~ Bin }   # -> ""';

# 
# ## StartsWith\[S]
# 
# The string starts with `S`.
# 
done_testing; }; subtest 'StartsWith\[S]' => sub { 
::is scalar do {"Hi, world!" ~~ StartsWith["Hi,"]}, scalar do{1}, '"Hi, world!" ~~ StartsWith["Hi,"]	# -> 1';
::is scalar do {"Hi world!" ~~ StartsWith["Hi,"]}, scalar do{""}, '"Hi world!" ~~ StartsWith["Hi,"]	# -> ""';



( run in 1.111 second using v1.01-cache-2.11-cpan-49f99fa48dc )