in reply to Typeglob substitution in objects based typeglob

Monks, I have one other solution. What do you think about it?
I added method new_from_socket() to IO::Socket::Socks module:
sub new_from_socket { my ($class, $sock, %arg) = @_; bless $sock, $class; $sock->autoflush(1); ${*$sock}{'io_socket_timeout'} = delete $arg{Timeout}; return scalar(%arg) ? $sock->configure(\%arg) : $sock; }
And overrided connect() function looks like this now:
use Socket; BEGIN { *CORE::GLOBAL::connect = sub(*$) { my ($socket, $name) = @_; return CORE::connect($socket, $name) if (scalar(caller 2) eq ' +IO::Socket::Socks'); my ($port, $host) = sockaddr_in($name); $host = inet_ntoa($host); my $ref = ref($socket); IO::Socket::Socks->new_from_socket( $socket, ProxyAddr => 'localhost', ProxyPort => 1080, SocksVersion => 5, ConnectAddr => $host, ConnectPort => $port, #SocksDebug => 1 ) or return undef; bless $socket, $ref if $ref; return 1; } } use IO::Socket::Socks;
First tests shows that it works both with simple sockets and with IO::Socket::INET objects.