UNIVERSAL::require broke my tests
This was *real fun* to track down. Here's a minimal test case of what was happening: #!/usr/bin/perl use strict; use warnings; use HTML::TokeParser qw; print "here"; I run that and it prints 'here', even though HTML::TokeParser does not export 'no_such_function'. No errors or warnings produced. Meanwhile, in code many modules away, UNIVERSAL::require is loaded and my code goes boom! Here's another minimal test case: #!/usr/bin/perl use strict; use warnings; use UNIVERSAL::require; use HTML::TokeParser qw; print "here"; That produces: :!perl -Ilib parse.pl "no_such_function" is not exported by the HTML::TokeParser module Can't continue after import errors at parse.pl line 7 BEGIN failed--compilation aborted at parse.pl line 7. So it's great that I can now easily track this sort of error down, but it's not great that the code mysteriously stops working. Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
Re: UNIVERSAL::require broke my tests
In article <[EMAIL PROTECTED]>, Ovid <[EMAIL PROTECTED]> wrote: > Note that the following does not trigger this: > > use UNIVERSAL::require; > use CGI qw; CGI has the nifty feature of auto-generating functions from its import list to turn them into HTML generating functions: use UNIVERSAL::require; use CGI qw; print no_such_function( "Hello" ); The output is: Hello
Re: UNIVERSAL::require broke my tests
Michael G Schwern wrote in perl.qa : > There is a fix for this, something like changing UNIVERSAL::import to be... > > sub import { > my($class) = shift; > > return unless $class eq 'UNIVERSAL'; > > ...do the export... > } Oh yes, that used to be a major *kh* problem. That's what bleadperl's UNIVERSAL does, BTW. -- * What system had proved more effective? * Indirect suggestion implicating selfinterest. -- Ulysses
Re: UNIVERSAL::require broke my tests
Its not UNIVERSAL::require, its UNIVERSAL (which UNIVERSAL::require must unfortunately load). use UNIVERSAL; use HTML::TokeParser qw(wibble); HTML::TokeParser defines nor inherits any import routine. When there's no import, any arguments to use are ignored and any calls to Class->import are ignored. UNIVERSAL unfortunately imports import() from Exporter which means EVERYONE has an import() routine. Thus, boom. There is a fix for this, something like changing UNIVERSAL::import to be... sub import { my($class) = shift; return unless $class eq 'UNIVERSAL'; ...do the export... }
Re: UNIVERSAL::require broke my tests
--- Ovid <[EMAIL PROTECTED]> wrote: > #!/usr/bin/perl > > use strict; > use warnings; > > use UNIVERSAL::require; > use HTML::TokeParser qw; > > print "here"; > > That produces: > > :!perl -Ilib parse.pl > "no_such_function" is not exported by the HTML::TokeParser module > Can't continue after import errors at parse.pl line 7 > BEGIN failed--compilation aborted at parse.pl line 7. > > So it's great that I can now easily track this sort of error down, > but it's not great that the code mysteriously stops working. Note that the following does not trigger this: use UNIVERSAL::require; use CGI qw; So I'm guessing it *might* be related to Exporter, but I don't have time to track this down right now. Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
UNIVERSAL::require broke my tests
This was *real fun* to track down. Here's a minimal test case of what was happening: #!/usr/bin/perl use strict; use warnings; use HTML::TokeParser qw; print "here"; I run that and it prints 'here', even though HTML::TokeParser does not export 'no_such_function'. No errors or warnings produced. Meanwhile, in code many modules away, UNIVERSAL::require is loaded and my code goes boom! Here's another minimal test case: #!/usr/bin/perl use strict; use warnings; use UNIVERSAL::require; use HTML::TokeParser qw; print "here"; That produces: :!perl -Ilib parse.pl "no_such_function" is not exported by the HTML::TokeParser module Can't continue after import errors at parse.pl line 7 BEGIN failed--compilation aborted at parse.pl line 7. So it's great that I can now easily track this sort of error down, but it's not great that the code mysteriously stops working. Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/