Skip Menu |

This queue is for tickets about the HTTP-Client-Parallel CPAN distribution.

Report information
The Basics
Id: 60500
Status: new
Priority: 0/
Queue: HTTP-Client-Parallel

People
Owner: Nobody in particular
Requestors: patcat88 [...] snet.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.02
Fixed in: (no value)



There is an undocumented feature in this module. In the get method of this module, instead of submitting a scalar string url or list of scalar strings, a single or an array/list of HTTP::Resquest objects can be submitted as parameters to the get method. Private method _build_request tests the urls if they are HTTP::Request objects, if not it builds a new HTTP::Request object. This isn't document in the POD. Being able give a HTTP::Request object is an important feature since thats a (or the only?) way of setting custom headers for the http request. But, giving the get method HTTP::Request objects doesn't work. get() returns an array of nulls (or undefs?) if you give get method HTTP::Request objects. Using a debugger I traced the problem to the map statement in the get method. "$self-urls" is an array and the parameters given originally to the get method. The problem is, "$self->{responses}{$_}" assumes $_ will be the url string, originating from the get method parameters, instead its the HTTP::Request object, no dereferencing means failure. I cooked up a patch for myself. It works for my purpose. My coding skills are poor so I can't vouch for its correctness or fitness to be directly added to the official module. I also include an example script called test.pl, with unmodded Parallel 0.02 it will fail with ------------------------------------------------------------------- C:\Documents and Settings\Owner\My Documents>perl test.pl OK Can't call method "message" on an undefined value at test.pl line 19. C:\Documents and Settings\Owner\My Documents> ------------------------------------------------------------------- after applying my patch, the module will work correctly and the output will be ------------------------------------------------------------------- C:\Documents and Settings\Owner\My Documents>perl test.pl OK OK C:\Documents and Settings\Owner\My Documents> ------------------------------------------------------------------- I guess this undocumented feature was incomplete and was going to be added in a future version of this module, but I needed it right now :) I suggest the author document that the get method can take a HTTP::Request object and fix the map statement in the get method. My perl -V for the record. ------------------------------------------------------------------- C:\Perl\site\lib\HTTP\Client>perl -V Summary of my perl5 (revision 5 version 10 subversion 0) configuration: Platform: osname=MSWin32, osvers=5.00, archname=MSWin32-x86-multi-thread uname='' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=undef, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE - DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_IM PLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX', optimize='-MD -Zi -DNDEBUG -O1', cppflags='-DWIN32' ccversion='13.10.3077', gccversion='', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksi ze=8 alignbytes=8, prototype=define Linker and Libraries: ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf -libpath:"C: \Perl\lib\CORE" -machine:x86' libpth=\lib libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32 .lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_ 32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comd lg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl510.lib gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf - libpath:"C:\Perl\lib\CORE" -machine:x86' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS PERL_MALLOC_WRAP PL_OP_SLAB_ALLOC USE_ITHREADS USE_LARGE_FILES USE_PERLIO USE_SITECUSTOMIZE Locally applied patches: ActivePerl Build 1003 [285500] 33741 avoids segfaults invoking S_raise_signal() (on Linux) 33763 Win32 process ids can have more than 16 bits 32809 Load 'loadable object' with non-default file extension 32728 64-bit fix for Time::Local Built under MSWin32 Compiled at May 13 2008 16:52:49 @INC: C:/Perl/site/lib C:/Perl/lib . C:\Perl\site\lib\HTTP\Client> --------------------------------------------------------------------
Subject: test.pl
#!/usr/bin/perl -w use strict; use HTTP::Client::Parallel; my $client = HTTP::Client::Parallel->new; my @requests; #works fine, documented in POD my @responsePlain = $client->get('http://www.google.com'); print $responsePlain[0]->message."\n"; #the below call will fail with HTTP::Client::Parallel V 0.02, undocumented in POD my @responseRequestObj = $client->get(HTTP::Request->new( GET => 'http://www.google.com', ['Accept-Encoding' => 'gzip, x-gzip, deflate, x-bzip2'] ) ); print $responseRequestObj[0]->message."\n";
Subject: parallel.pm.patch
--- Parallel.pm.old 2008-07-05 16:37:22.000000000 -0400 +++ Parallel.pm 2010-08-19 00:06:29.609375000 -0400 @@ -117,7 +117,14 @@ $self->_init; $self->_set_urls(@_); $self->poe_loop; - my @responses = map { $self->{responses}{$_} } $self->urls; + my @responses; + if ($self->urls->[0]->isa('HTTP::Request')) { + @responses = map { $self->{responses}{$_->uri}} $self->urls; + } + + else { + @responses = map { $self->{responses}{$_}} $self->urls; + } return wantarray ? @responses : \@responses # XXX from the pod, this may be the desired behavior