Aion

 view release on metacpan or  search on metacpan

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

eval { Aion::Type->new(name=>"Rim")->make }; $@ # ~> syntax error
```

## make_arg ($pkg)

It make subroutine with arguments, who return type.

```perl
BEGIN {
    Aion::Type->new(name=>"Len", test => sub {
        $Aion::Type::SELF->{args}[0] <= length($_) && length($_) <= $Aion::Type::SELF->{args}[1]
    })->make_arg(__PACKAGE__);
}

"IX" ~~ Len[2,2]    # => 1
```

If subroutine make'nt, then died.

```perl
eval { Aion::Type->new(name=>"Rim")->make_arg }; $@ # ~> syntax error

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

If subroutine make'nt, then died.

	eval { Aion::Type->new(name=>"Rim")->make }; $@ # ~> syntax error

=head2 make_arg ($pkg)

It make subroutine with arguments, who return type.

	BEGIN {
	    Aion::Type->new(name=>"Len", test => sub {
	        $Aion::Type::SELF->{args}[0] <= length($_) && length($_) <= $Aion::Type::SELF->{args}[1]
	    })->make_arg(__PACKAGE__);
	}
	
	"IX" ~~ Len[2,2]    # => 1

If subroutine make'nt, then died.

	eval { Aion::Type->new(name=>"Rim")->make_arg }; $@ # ~> syntax error

=head2 make_maybe_arg ($pkg)

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

Defined unreference values.

```perl
3 ~~ Value        # -> 1
\3 ~~ Value       # -> ""
undef ~~ Value    # -> ""
```

## Len[A, B?]

Defines the length value from `A` to `B`, or from 0 to `A` if `B` is'nt present.

```perl
"1234" ~~ Len[3]   # -> ""
"123" ~~ Len[3]    # -> 1
"12" ~~ Len[3]     # -> 1
"" ~~ Len[1, 2]    # -> ""
"1" ~~ Len[1, 2]   # -> 1
"12" ~~ Len[1, 2]  # -> 1
"123" ~~ Len[1, 2] # -> ""
```

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

				subtype "HasMethods[m...]", as &Like,
					where { my $x = $_; all { $x->can($_) } ARGS };
				subtype "Overload`[m...]", as &Like,
					where { !!overload::Overloaded($_) }
					awhere { my $x = $_; all { overload::Method($x, $_) } ARGS };
				subtype "InstanceOf[A...]", as &Like, where { my $x = $_; all { $x->isa($_) } ARGS };
				subtype "ConsumerOf[A...]", as &Like, where { my $x = $_; all { $x->can("does") && $x->does($_) } ARGS };
				subtype "StrLike", as (&Str | Overload(['""']));
					subtype "Len[A, B?]", as &StrLike,
						init_where => $init_limit,
						where { SELF->{min} <= length($_) && length($_) <= SELF->{max} };

				subtype "NumLike", where { looks_like_number($_) };
					subtype "Float", as &NumLike, where { -3.402823466E+38 <= $_ && $_ <= 3.402823466E+38 };
					
					my $_from; my $_to;
					subtype "Double", as &NumLike, where {
                        $_from //= do { require Math::BigFloat; Math::BigFloat->new('-1.7976931348623157e+308') };
                        $_to   //= do { require Math::BigFloat; Math::BigFloat->new( '1.7976931348623157e+308') };
                        $_from <= $_ && $_ <= $_to;
                    };

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

=head2 Value

Defined unreference values.

	3 ~~ Value        # -> 1
	\3 ~~ Value       # -> ""
	undef ~~ Value    # -> ""

=head2 Len[A, B?]

Defines the length value from C<A> to C<B>, or from 0 to C<A> if C<B> is'nt present.

	"1234" ~~ Len[3]   # -> ""
	"123" ~~ Len[3]    # -> 1
	"12" ~~ Len[3]     # -> 1
	"" ~~ Len[1, 2]    # -> ""
	"1" ~~ Len[1, 2]   # -> 1
	"12" ~~ Len[1, 2]  # -> 1
	"123" ~~ Len[1, 2] # -> ""

=head2 Version

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

::like scalar do {eval { Aion::Type->new(name=>"Rim")->make }; $@}, qr!syntax error!, 'eval { Aion::Type->new(name=>"Rim")->make }; $@ # ~> syntax error';

# 
# ## make_arg ($pkg)
# 
# It make subroutine with arguments, who return type.
# 
done_testing; }; subtest 'make_arg ($pkg)' => sub { 
BEGIN {
    Aion::Type->new(name=>"Len", test => sub {
        $Aion::Type::SELF->{args}[0] <= length($_) && length($_) <= $Aion::Type::SELF->{args}[1]
    })->make_arg(__PACKAGE__);
}

::is scalar do {"IX" ~~ Len[2,2]}, "1", '"IX" ~~ Len[2,2]    # => 1';

# 
# If subroutine make'nt, then died.
# 

::like scalar do {eval { Aion::Type->new(name=>"Rim")->make_arg }; $@}, qr!syntax error!, 'eval { Aion::Type->new(name=>"Rim")->make_arg }; $@ # ~> syntax error';

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

# Defined unreference values.
# 
done_testing; }; subtest 'Value' => sub { 
::is scalar do {3 ~~ Value}, scalar do{1}, '3 ~~ Value        # -> 1';
::is scalar do {\3 ~~ Value}, scalar do{""}, '\3 ~~ Value       # -> ""';
::is scalar do {undef ~~ Value}, scalar do{""}, 'undef ~~ Value    # -> ""';

# 
# ## Len[A, B?]
# 
# Defines the length value from `A` to `B`, or from 0 to `A` if `B` is'nt present.
# 
done_testing; }; subtest 'Len[A, B?]' => sub { 
::is scalar do {"1234" ~~ Len[3]}, scalar do{""}, '"1234" ~~ Len[3]   # -> ""';
::is scalar do {"123" ~~ Len[3]}, scalar do{1}, '"123" ~~ Len[3]    # -> 1';
::is scalar do {"12" ~~ Len[3]}, scalar do{1}, '"12" ~~ Len[3]     # -> 1';
::is scalar do {"" ~~ Len[1, 2]}, scalar do{""}, '"" ~~ Len[1, 2]    # -> ""';
::is scalar do {"1" ~~ Len[1, 2]}, scalar do{1}, '"1" ~~ Len[1, 2]   # -> 1';
::is scalar do {"12" ~~ Len[1, 2]}, scalar do{1}, '"12" ~~ Len[1, 2]  # -> 1';
::is scalar do {"123" ~~ Len[1, 2]}, scalar do{""}, '"123" ~~ Len[1, 2] # -> ""';



( run in 0.809 second using v1.01-cache-2.11-cpan-65fba6d93b7 )