AnyEvent-ZeroMQ
view release on metacpan or search on metacpan
lib/AnyEvent/ZeroMQ/Types.pm view on Meta::CPAN
3031323334353637383940414243444546474849505152535455565758596061626364
return
1
if
$proto
eq
'inproc'
;
return
1
if
$proto
eq
'ipc'
;
return
1
if
$proto
eq
'tcp'
&&
$rest
=~ /^(?:
$host
|
$ip
|
$interface
|\*)
$andport
$/;
return
1
if
(
$proto
eq
'pgm'
||
$proto
eq
'epgm'
) &&
$rest
=~ /^(?:
$interface
|
$ip
);
$ip
$andport
$/;
return
0;
}
return
0;
}, message {
'An endpoint must be in the form "<transport>://<address>"'
};
subtype Endpoints, as ArrayRef[Endpoint], message {
'Each endpoint must be in the form "<transport>://<address>"'
;
};
sub
fixup_endpoint() {
s{(^[/])/$}{$1}g;
}
coerce Endpoint, from Str, via { fixup_endpoint };
coerce Endpoints, from ArrayRef[Str], via {
my
@array
=
@$_
;
fixup_endpoint
for
@array
;
$_
= [
@array
];
};
my
%allowed_sockettype
=
map
{ ZeroMQ::Raw::Constants->
$_
=>
$_
}
@socket_constants
;
subtype SocketType, as Int, where {
exists
$allowed_sockettype
{
$_
};
}, message {
'A socket type must be one of: '
.
join
(
', '
,
@socket_constants
) };
subtype IdentityStr, as Str, where {
length
$_
< 256 &&
length
$_
>= 0;
123456789101112131415161718192021222324252627282930use
strict;
use
warnings;
use
Test::TableDriven (
endpoint
=> {
'foo'
=> 0,
'tcp://'
=> 0,
'inproc://'
=> 0,
'pgm://'
=> 0,
'egpm://'
=> 0,
'ipc://'
=> 0,
'tcp://*:1234'
=> 1,
},
);
sub
endpoint {
my
$in
=
shift
;
return
Endpoint()->validate(
$in
) ? 0 : 1;
}
runtests;
( run in 1.738 second using v1.01-cache-2.11-cpan-49f99fa48dc )