Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: scope of "use strict"? (needed: "superstrict")

by davido (Cardinal)
on Jul 07, 2005 at 04:57 UTC ( #473025=note: print w/replies, xml ) Need Help??


in reply to scope of "use strict"? (needed: "superstrict")

I don't fully understand why you would want to force modules to be compiled under strictures when they weren't designed to do so. As others have pointed out, this has the potential of generating lots of errors, and many of them will point to perfectly legitimate code, since it's possible to create bug-free code that isn't strict-compliant.

But I thought it sounded like a fun little challenge, so in the spirit of "give them what they ask for" here is a little snippet that will test-compile every module in the dependancy heirarchy of your script with strictures enforced:

use strict; use warnings; use IO::CaptureOutput qw/capture_exec/; my( $stdout, $stderr ) = capture_exec( 'perl', '-d:Modlist=nocore,stop,path,noversion', $ARGV[0] ); my( @modules ) = split /\n/, $stderr; foreach my $module ( @modules ) { my( $stdout, $stderr ) = capture_exec( 'perl', '-Mstrict', '-c', $module ); print "Module: $module\n\tSTDOUT = $stdout\n\tSTDERR = $stderr\n"; }

This snippet requires Devel::Modlist, and IO::CaptureOutput. They aren't core, so you'll probably have to install them. Then run it like this:

perl stricttester.pl yourcode.pl >output.log

Then examine what you get in output.log. Every module that is strictures-compliant, and that is otherwise free from compiletime problems will compile "ok", and every module that isn't will give you a bunch of error messages.
It actually works really slick.

Enjoy!


Dave

Replies are listed 'Best First'.
Re^2: scope of "use strict"? (needed: "superstrict")
by argv (Pilgrim) on Jul 07, 2005 at 05:31 UTC
    I don't fully understand why you would want to force modules to be compiled under strictures when they weren't designed to do so.

    call it, "chasing a hunch." It's not my code I'm debugging, it's someone else's, and while I can easily "fix" some of his programming errors, I'm still trying to determine if those errors are the cause for other erratic problems going on.... like variable stomping, etc. So, I want to leave the errors in place and follow other sources to see what they do, and what the effects are. Note that it's not just determining "if" there's a bug, but finding "who" is doing the stomping? A quick examination of the "use strict" output could yield some instantly obvious results since I have an idea of what I'm looking for. Sometimes, it isn't enough to just fix a bug, it's finding out how far and wide its effects are before its fixed that can reveal other useful info one might not have expected.

    With some variations on your excellent script, I think I might find the very culprit I'm looking for.

Re^2: scope of "use strict"? (needed: "superstrict")
by Anonymous Monk on Jul 07, 2005 at 07:41 UTC
    Put coderef into @INC, search for file, read in, prepend "use strict; ", eval ...
Re^2: scope of "use strict"? (needed: "superstrict")
by leriksen (Curate) on Jul 07, 2005 at 12:41 UTC
    In my experience, people dont 'design' modules to only work without strictures. More typically, they dont 'use strict' because, and I quote, 'you just end up with lots of annoying lines getting in the way' (I had an experience somewhat like that today - the developers had a huge script with everything as a global. And to top it all, I gave him a function to do some parsing, which promptly broke when he removed all the 'my's' in front of the lexical variables. A stern talking-to then ensued).

    ...it is better to be approximately right than precisely wrong. - Warren Buffet

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://473025]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2020-08-06 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (39 votes). Check out past polls.

    Notices?