Skip Menu |

This queue is for tickets about the IO-Prompter CPAN distribution.

Report information
The Basics
Id: 82741
Status: open
Priority: 0/
Queue: IO-Prompter

People
Owner: Nobody in particular
Requestors: KUERBIS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.004002
Fixed in: (no value)



Subject: Problemns when using IO::Promter with DBI
#!/usr/bin/env perl use warnings; use 5.16.2; use DBI; use IO::Prompter; say $DBI::VERSION; say $IO::Prompter::VERSION; my $user = prompt( 'Enter username: ' ); my $passwd = prompt( 'Enter password: ', -echo => '' ); my $dbh = DBI->connect( "DBI:mysql:dbname=information_schema", $user, $passwd, {} ) or die DBI->errstr; #my $dbh = DBI->connect( "DBI:Pg:dbname=postgres", $user, $passwd, {} ) or die DBI->errstr; say "Hello World"; Outputs: 1.623 0.004003 Enter username: testuser Enter password: Usage: $class->connect([$dsn [,$user [,$passwd [,\%attr]]]]) at ./perl.pl line 13. When I enter the username and the password with a normal "readline" I get no error message. Summary of my perl5 (revision 5 version 16 subversion 2) configuration: Platform: osname=linux, osvers=3.4.11-2.16-desktop, archname=x86_64-linux uname='linux linux1 3.4.11-2.16-desktop #1 smp preempt wed sep 26 17:05:00 utc 2012 (259fc87) x86_64 x86_64 x86_64 gnulinux ' config_args='-de' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion='', gccversion='4.7.1 20120723 [gcc-4_7-branch revision 189773]', gccosandvers='' intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='cc', ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /lib/../lib64 /usr/lib/../lib64 /lib /usr/lib /lib64 /usr/lib64 /usr/local/lib64 libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=/lib/libc-2.15.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.15' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector' Characteristics of this binary (from libperl): Compile-time options: HAS_TIMES PERLIO_LAYERS PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP PERL_PRESERVE_IVUV USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF Built under linux Compiled at Nov 6 2012 11:05:56 @INC: /usr/local/lib/perl5/site_perl/5.16.2/x86_64-linux /usr/local/lib/perl5/site_perl/5.16.2 /usr/local/lib/perl5/5.16.2/x86_64-linux /usr/local/lib/perl5/5.16.2 .
Subject: Re: [rt.cpan.org #82741] Problemns when using IO::Promter with DBI
Date: Tue, 22 Jan 2013 18:23:02 +1100
To: bug-IO-Prompter [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Hi Matthäus, Without being able to run the code, I can only guess at the cause of the problem. But I'm reasonably confident in my guess. :-) I think the problem here is that IO::Prompter::prompt() normally returns a blessed object, rather than a raw string. And I suspect passing in these blessed objects as the $user and $passwd arguments is tripping up something inside DBI. If that is indeed the problem then arguably that's a bug inside DBI, but let's ignore that for the moment and just solve the problem. ;-) I think that you will be able to get the desired outcome either by changing the prompt lines to: my $user = prompt( 'Enter username: ', -verbatim); my $passwd = prompt( 'Enter password: ', -echo => '', -verbatim ); The -verbatim argument will cause prompt() to return a string instead of a blessed object. Alternatively, you can ensure that you stringify the objects yourself before passing them to DBI::connect(), by changing that call to: my $dbh = DBI->connect( "DBI:mysql:dbname=information_schema", "$user", "$passwd", {} ) or die DBI->errstr; That is, explicitly convert the username and password variables to strings before passing them into DBI::connect(). You should only need to use one of these two fixes, so pick whichever one most appeals to you. Hope this helps (and please let me know if it doesn't), Damian