Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Simple CPAN distribution.

Report information
The Basics
Id: 8188
Status: resolved
Priority: 0/
Queue: Test-Simple

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

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



Subject: Test::More use_ok with imports issue
I am having trouble using imports with DBI. It could be due to DBI's use of "groups" of symbols. You will see that :sql_types imports numerous symbols when using DBI directly. Maybe I'm not using it correctly? It will print SQL_TYPE_TIMESTAMP when incorrect and print 93 when correct. Use the following script to reproduce: use Test::More tests => 1; { package Foo::one; Test::More::use_ok('DBI', qw(:sql_types)); # can't seem to get the imports right this way # use DBI qw(:sql_types); print "use_ok ", SQL_TYPE_TIMESTAMP, "\n"; } { package Foo::two; use DBI qw(:sql_types); print "use ", SQL_TYPE_TIMESTAMP, "\n"; }
Date: Sat, 30 Oct 2004 12:09:46 -0400
From: Michael G Schwern <schwern [...] pobox.com>
To: Guest via RT <bug-Test-Simple [...] rt.cpan.org>
Subject: Re: [cpan #8188] Test::More use_ok with imports issue
RT-Send-Cc:
On Sat, Oct 30, 2004 at 10:31:01AM -0400, Guest via RT wrote: Show quoted text
> I am having trouble using imports with DBI. It could be due to DBI's use of "groups" of symbols. You will see that :sql_types imports numerous symbols when using DBI directly. Maybe I'm not using it correctly? It will print SQL_TYPE_TIMESTAMP when incorrect and print 93 when correct. Use the following script to reproduce:
If you turn on warnings you get a hint as to what's going on. $ perl -wle 'use Test::More tests => 1; use_ok 'DBI', qw(:sql_types); print SQL_TYPE_TIMESTAMP' 1..1 Name "main::SQL_TYPE_TIMESTAMP" used only once: possible typo at -e line 1. ok 1 - use DBI; print() on unopened filehandle SQL_TYPE_TIMESTAMP at -e line 1. Perl thinks SQL_TYPE_TIMESTAMP is a filehandle not a function. This is a parsing issue. Its because SQL_TYPE_TIMESTAMP wasn't declared early enough. If you do "print &SQL_TYPE_TIMESTAMP" it works, so its getting exported. In order for constants to work properly they have to be declared at compile time. "use" happens at compile time before anything else happens, even before the rest of the program is compiled. use_ok() does not. In order for exports to work properly its recommended you place use_ok() in a BEGIN block to force it to happen at compile time. use Test::More tests => 1; BEGIN { use_ok 'DBI', qw(:sql_types) } print SQL_TYPE_TIMESTAMP; -- Michael G Schwern schwern@pobox.com http://www.pobox.com/~schwern/ The eye opening delightful morning taste of expired cheese bits in sour milk!
Closing this. Not a bug. Docs are pretty clear about BEGIN.