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 )