1package IO::Socket::Socks::Wrapped; 2 3no warnings 'redefine'; 4use IO::Socket; 5use IO::Socket::Socks::Wrapper; 6 7our $VERSION = '0.17'; 8our $AUTOLOAD; 9 10sub new { 11 my ($class, $obj, $cfg) = @_; 12 bless {orig => $obj, cfg => $cfg}, $class; 13} 14 15sub AUTOLOAD { 16 my $self = shift; 17 18 IO::Socket::Socks::Wrapper::_io_socket_connect_ref(); 19 20 local *IO::Socket::IP::connect = local *IO::Socket::connect = sub { 21 return IO::Socket::Socks::Wrapper::_connect(@_, $self->{cfg}, 1); 22 }; 23 24 $AUTOLOAD =~ s/^.+:://; 25 $self->{orig}->$AUTOLOAD(@_); 26} 27 28sub isa { 29 my $self = shift; 30 $self->{orig}->isa(@_); 31} 32 33sub can { 34 my $self = shift; 35 $self->{orig}->can(@_); 36} 37 38sub DOES { 39 my $self = shift; 40 $self->{orig}->DOES(@_); 41} 42 43sub DESTROY {} 44 451; 46 47__END__ 48 49=head1 NAME 50 51IO::Socket::Socks::Wrapped - object wrapped by IO::Socket::Socks::Wrapper 52 53=head1 SYNOPSIS 54 55 use WWW::Mechanize; 56 use IO::Socket::Socks::Wrapped; 57 58 my $ua = WWW::Mechanize->new; 59 my $s_ua = IO::Socket::Socks::Wrapped->new($ua, { 60 ProxyAddr => 'localhost', 61 ProxyPort => 1080 62 }); 63 64 $s_ua->get("http://google.com"); # via proxy 65 $ua->get("http://google.com"); # direct 66 67 $s_ua->isa('WWW::Mechanize'); # true 68 $s_ua->can('is_html'); # true 69 print ref($s_ua); # IO::Socket::Socks::Wrapped 70 71=head1 DESCRIPTION 72 73C<IO::Socket::Socks::Wrapped> is representation of object wrapped by C<IO::Socket::Socks::Wrapper>. You may create it directly 74by new() method or through IO::Socket::Socks::Wrapper::wrap_connection() subroutine. First parameter is original object, that 75internally uses IO::Socket for creation of tcp connections. Second is proxy configuration (see L<IO::Socket::Socks::Wrapper> 76documentation). New IO::Socket::Socks::Wrapped object will use proxy specified in configuration for tcp connections. Original 77object also may be used, but it will make direct tcp connections. In fact new object uses original internally and has all it 78methods. So if you'll change some behaviour of original object, behaviour of wrapped object also will be changed. 79 80You can access original object this way: 81 82 my $orig = $wrapped_object->{orig}; 83 84Wrapped object behaviour for UNIVERSAL methods (isa, can, DOES) is same as original object behaviour. So, the following is true 85 86 $wrapped_object->isa('Original::Package'); 87 88=head1 SEE ALSO 89 90L<IO::Socket::Socks::Wrapper> 91 92=head1 COPYRIGHT 93 94Oleg G <oleg@cpan.org>. 95 96This library is free software; you can redistribute it and/or 97modify it under the same terms as Perl itself. 98