MCE
view release on metacpan or search on metacpan
t/04_channel_threads_mp.t view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use open qw(:std :utf8);
use Test::More;
BEGIN {
plan skip_all => "Not used on Cygwin" if ( $^O eq 'cygwin' );
if ( $] lt '5.010001' && $^O ne 'MSWin32' ) {
plan skip_all => "old Perl and threads not supported on Unix platforms";
}
eval 'use threads'; ## no critic
plan skip_all => "threads not available" if $@;
use_ok 'MCE::Channel';
use_ok 'MCE::Channel::Threads';
}
## https://sacred-texts.com/cla/usappho/sph02.htm (IV)
my $sappho_text =
"αá¿Ïα δ᾽ á¼ÏίκονÏο, Ïὺ δ᾽, ὦ μάÏαιÏα
μειδιάÏαιÏá¾½ á¼Î¸á½±Î½Î±Ïῳ ÏÏοÏá½½Ïῳ,
ἤÏá¼ á½ÏÏι δηá½Ïε Ïá½³Ïονθα κὤÏÏι
δἦγÏε κάλημι.";
my $translation =
"Then, soon they arrived and thou, blessed goddess,
With divine contenance smiling, didst ask me
What new woe had befallen me now and why,
Thus I had called the.";
my $come_then_i_pray = "ãããç§ã¯ç¥ã" . "Ç¢";
my $chnl = MCE::Channel->new( impl => 'Threads', mp => 1 );
is $chnl->impl(), 'Threads', 'implementation name';
# send recv
{
$chnl->send('a string');
is $chnl->recv, 'a string', 'send recv scalar';
$chnl->send($sappho_text);
is $chnl->recv, $sappho_text, 'send recv utf8';
$chnl->send($come_then_i_pray);
is $chnl->recv, $come_then_i_pray, 'send recv utf8_ja';
$chnl->send(qw/ a list of arguments /);
is scalar( my @args = $chnl->recv ), 4, 'send recv list';
$chnl->send({ complex => 'structure' });
is ref( $chnl->recv ), 'HASH', 'send recv complex';
}
# send recv_nb
if ($^O ne 'MSWin32')
{
$chnl->send('a string');
is $chnl->recv_nb, 'a string', 'send recv_nb scalar';
$chnl->send($sappho_text);
is $chnl->recv_nb, $sappho_text, 'send recv_nb utf8';
$chnl->send($come_then_i_pray);
is $chnl->recv_nb, $come_then_i_pray, 'send recv_nb utf8_ja';
$chnl->send(qw/ a list of arguments /);
( run in 2.877 seconds using v1.01-cache-2.11-cpan-5e09290becf )