File: 02_do_callback_args.t

package info (click to toggle)
libmce-perl 1.517-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,864 kB
  • ctags: 377
  • sloc: perl: 10,516; makefile: 2
file content (45 lines) | stat: -rwxr-xr-x 842 bytes parent folder | download
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
#!/usr/bin/env perl

use strict;
use warnings;

BEGIN {
   eval 'use threads; use threads::shared;' if $^O eq 'MSWin32';
}

use Test::More tests => 4;

use MCE;

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 $s = $_[0];
   is($s, 1, 'check scalar value');
}

my $mce = MCE->new(
   use_threads => ($^O eq 'MSWin32') ? 1 : 0,
   spawn_delay => 0.2,
   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());
   }
);

$mce->run;