summaryrefslogtreecommitdiff
path: root/t/02_do_callback_args.t
blob: 43c8c3b5cf7c89d4b7995899793b809090a5d922 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env perl

use strict;
use warnings;
use utf8;
use open qw(:std :utf8);

use Test::More;

BEGIN {
   use_ok 'MCE';
}

my $come_then_i_pray = "さあ、私は祈る";

sub callback1 {
   my ($a_ref, $h_ref, $s_ref) = @_;

   is($a_ref->[1], 'two', 'check array reference');
   is($h_ref->{'two'}, 'TWO', 'check hash reference');
   is(${ $s_ref }, 'fall colors', 'check scalar reference');

   return;
}

sub callback2 {
   my ($wid) = @_;
   is($wid, 1, 'check scalar value');
   return;
}

sub callback3 {
   my ($text) = @_;
   is($text, $come_then_i_pray, 'check utf8 value');
   return;
}

my $mce = MCE->new(
   max_workers => 1,

   user_func => sub {
      my ($self) = @_;

      my @a = ('one', 'two');
      my %h = ('one' => 'ONE', 'two' => 'TWO');
      my $s = 'fall colors';

      $self->do('callback1', \@a, \%h, \$s);
      $self->do('callback2', $self->wid());
      $self->do('callback3', $come_then_i_pray);

      return;
   }
);

$mce->run;

done_testing;