Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: allow Object with stringify overloading as passwd in connect() #148

Open
rwfranks opened this issue Oct 27, 2024 · 1 comment

Comments

@rwfranks
Copy link

Transcribed verbatim from CPAN RT#96763, warts and all.

Fri Jun 27 07:25:39 2014 zaucker [...] oetiker.ch - Ticket created
Subject: Suggestion: allow Object with stringify overloading as passwd in connect()

Date: Fri, 27 Jun 2014 13:25:25 +0200 (CEST)
To: [email protected]
From: Fritz Zaucker [email protected]

Dear DBI-maintainers,

first of all, many thanks for your great work on this module.

I recently used Damian Conway's IO::Prompter module to ask the user for a
DB-password to be used later in a call to DBI->connect().

As it turns out, DBI->connect() tests the parameter passed as password (for
being a string, I guess):

     Carp::croak('Usage: $class->connect([$dsn [,$user [,$passwd [,\%attr]]]])')
       if (ref $old_driver or ($attr and not ref $attr) or ref $pass);
#                                                         ^^^^^^^^^

IO::Prompter->prompt() returns an object with lazy evaluation of the user's
input (unless called with the -verbatim option). Therefore

my $dsn = 'whatever';
my $user = 'fritz';
my $passwd = IO::Prompter->prompt();
DBI->connect($dsn, $user, $passwd);

will croak().

This would solve the problem:

   use overload;
   Carp::croak('Usage: $class->connect([$dsn [,$user [,$passwd [,\%attr]]]])')
       if (ref $old_driver or ($attr and not ref $attr) or
          (ref $pass and not overload::Method($pass,q{""}));

  (as suggested by Damian).

Now, this is not really a very pressing issue, as I can always use the
-verbatim option for IO::Prompter (or force the lazy evaluation before
calling DBI->connect().

But perhaps you might want to use the above patch (overload being a core module
should make this painless for users of DBI).

Cheers,
Fritz

--
Oetiker+Partner AG tel: +41 62 775 9903 (direct)
Fritz Zaucker +41 62 775 9900 (switch board)
Aarweg 15 +41 79 675 0630 (mobile)
CH-4600 Olten fax: +41 62 775 9905
Schweiz web: www.oetiker.ch

@rwfranks
Copy link
Author

Sun Sep 21 08:08:25 2014 TIMB [...] cpan.org - Correspondence added

Thanks for the suggestion Fritz.

As you say, it's not a high priority. However, if you want to contribute, I'd consider a patch that only loads the overload module if needed and includes tests.

Sun Sep 21 08:08:26 2014 The RT System itself - Status changed from 'new' to 'open'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant