Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Making Coro::Socket Override IO::Socket::INET

by jabowery (Beadle)
on Jun 17, 2013 at 16:40 UTC ( #1039413=perlquestion: print w/replies, xml ) Need Help??
jabowery has asked for the wisdom of the Perl Monks concerning the following question:

CPAN has a lot of modules for network access. While few of them are set up to support multithreading most use IO::Socket::INET. The cpan page for Coro::Socket says:
This module was written to imitate the IO::Socket::INET API

So an obvious question is:

Is there a better way to get networking modules that use IO::Socket::INET to instead use Coro::Socket, than to copy the code and do a search and replace?
  • Comment on Making Coro::Socket Override IO::Socket::INET

Replies are listed 'Best First'.
Re: Making Coro::Socket Override IO::Socket::INET
by aitap (Curate) on Jun 17, 2013 at 18:14 UTC
    You can probably acheive this by altering the symbol table:
    package Bar; sub import { print "Hi!\n"; } package main; use warnings; use strict; BEGIN{*{Foo::} = *{Bar::};} # can't "use" there because there is no Foo::->import; __END__ Hi!

    Write a header in your script that once uses Coro::Socket and then replaces IO::Socket::INET:: namespace with Coro::Socket::. Subsequent uses of IO::Socket::INET will call import() from Coro::Socket and will use its subroutines.

    Edit: you'll probably need to use IO::Socket::INET before replacing namespaces, too, so further calls to it won't eval it and overwrite Coro::Socket's subs back.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1039413]
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-07-15 23:35 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (328 votes). Check out past polls.