my ($resolved_methods, $cag_produced_crefs);
+sub CLONE {
+ my @crefs = grep { defined $_ } values %{$cag_produced_crefs||{}};
+ $cag_produced_crefs = @crefs
+ ? { map { $_ => $_ } @crefs }
+ : undef
+ ;
+}
+
# Note!!! Unusual signature
$gen_accessor = sub {
my ($type, $class, $group, $field, $methname) = @_;
+my $has_threads;
+BEGIN { eval '
+ use 5.008001;
+ use threads;
+ use threads::shared;
+ $has_threads = 1;
+' }
+
use strict;
use warnings;
+no warnings 'once';
use FindBin qw($Bin);
use File::Spec::Functions;
use File::Spec::Unix (); # need this for %INC munging
our $SUBTESTING = 1;
for my $tname (qw/accessors.t accessors_ro.t accessors_wo.t/) {
- for (1,2) {
- note "\nTesting $tname without Sub::Name (pass $_)\n\n";
+ my $pass = 1;
+ share($pass) if $has_threads;
+
+ my $todo = sub {
+ note "\nTesting $tname without Sub::Name (pass @{[ $pass ++ ]})\n\n";
my $tfn = catfile($Bin, $tname);
local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /subroutine .+ redefined/i };
do($tfn);
+ };
+ if ($has_threads) {
+ threads->create(sub {
+ threads->create(sub {
+ $todo->() for (1,2) }
+ )->join;
+ $todo->() for (1,2);
+ })->join for (1,2)
+ }
+ else {
+ $todo->() for (1, 2);
}
}
+my $has_threads;
+BEGIN { eval '
+ use 5.008001;
+ use threads;
+ use threads::shared;
+ $has_threads = 1;
+' }
+
use strict;
use warnings;
+no warnings 'once';
use FindBin qw($Bin);
use File::Spec::Functions;
use File::Spec::Unix (); # need this for %INC munging
for my $tname (qw/accessors.t accessors_ro.t accessors_wo.t/) {
- for (1,2) {
- note "\nTesting $tname with USE_XS (pass $_)\n\n";
+ my $pass = 1;
+ share($pass) if $has_threads;
+
+ my $todo = sub {
+ note "\nTesting $tname with USE_XS (pass @{[ $pass++ ]})\n\n";
my $tfn = catfile($Bin, $tname);
local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /subroutine .+ redefined/i };
do($tfn);
+ };
+
+ if ($has_threads) {
+ threads->create(sub {
+ threads->create(sub {
+ $todo->() for (1,2) }
+ )->join;
+ $todo->() for (1,2);
+ })->join for (1,2)
+ }
+ else {
+ $todo->() for (1, 2);
}
}
+my $has_threads;
+BEGIN { eval '
+ use 5.008004; # older perls get confused by $SIG fiddling
+ use threads;
+ use threads::shared;
+ $has_threads = 1;
+' }
+
use strict;
use warnings;
use Test::More;
use AccessorGroupsSubclass;
-my $obj = AccessorGroupsSubclass->new;
-my $deferred_stub = AccessorGroupsSubclass->can('singlefield');
-my $obj2 = AccessorGroups->new;
-
my @w;
+share(@w) if $has_threads;
+
{
- local $SIG{__WARN__} = sub { push @w, @_ };
- is ($obj->$deferred_stub(1), 1, 'Set');
- is ($obj->$deferred_stub, 1, 'Get');
- is ($obj->$deferred_stub(2), 2, 'ReSet');
- is ($obj->$deferred_stub, 2, 'ReGet');
-
- is ($obj->singlefield, 2, 'Normal get');
- is ($obj2->singlefield, undef, 'Normal get on unrelated object');
+ my $obj = AccessorGroupsSubclass->new;
+ my $deferred_stub = AccessorGroupsSubclass->can('singlefield');
+ my $obj2 = AccessorGroups->new;
+
+ my $todo = sub {
+ local $SIG{__WARN__} = sub { push @w, @_ };
+ is ($obj->$deferred_stub(1), 1, 'Set');
+ is ($obj->$deferred_stub, 1, 'Get');
+ is ($obj->$deferred_stub(2), 2, 'ReSet');
+ is ($obj->$deferred_stub, 2, 'ReGet');
+
+ is ($obj->singlefield, 2, 'Normal get');
+ is ($obj2->singlefield, undef, 'Normal get on unrelated object');
+ };
+
+ $has_threads ? threads->create( $todo )->join : $todo->();
}
is (@w, 3, '3 warnings total');