assuming that the app can run with or with threads (using the threaded env when it can), we need a way to NOOP ops from threads and threads::shared.

This is sort of a hack I came up with while developing tests for the pooling DBI I'm working on. Would be nice to have a core solution for that.

It covers only ops that I used in the tests.

the app now should do:

use My::threads;

instead of:

use threads;
use threads::shared;

and it should be able to work w/ or w/o ithreaded perl.

here is the wrapper:

package My::threads;

use strict;
use warnings;

use constant THREADS => eval {require threads };

if (THREADS) {
    require threads::shared;
}
else {
    eval <<'EOI';
    sub lock  {};
    sub share {};
    package threads;
    sub self  {'thread'}
    sub create {
        shift; # package
        my $sub = shift;
        no strict 'refs';
        $sub = (caller)[0] . "::" . $sub unless defined *$sub{CODE};
        $sub->(@_);
        return 'thread';
    }
    package threads::shared;
    sub lock  {};
    sub share {};
    package thread;
    sub join  {};
    sub tid   {0}
    package My::threads;
EOI
}

sub import {
    my $package = (caller)[0];
    # XXX: currently export all by default
    no strict 'refs';
    *{$package . "::self"}  = \&threads::self;
    *{$package . "::share"} = \&threads::shared::share;
}

1;


__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com



Reply via email to