Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

File::Spec patch

by pileofrogs (Priest)
on Aug 08, 2008 at 22:34 UTC ( #703193=perlmeditation: print w/ replies, xml ) Need Help??

Blessings upon ye monks!

I've recently run across this error message:

Use of uninitialized value in join or string at /usr/lib64/perl5/5.8.8 +/x86_64-linux-thread-multi/File/Spec/Unix.pm line 81

Which wouldn't be a big deal if I were actually using File::Spec in my own code.

Long story short, I found my own bug and I've written a patch for File::Spec::Unix that makes it generate a useful error instead of the one above.

My solution was to use Carp and cluck if conditions would cause the situation above.

So, my request from ye monks is any feedback on my solution and patch before I mail it off the author.

Thanks!
--Pileofrogs

UPDATE: I've changed the patch. The old version clucked if there were no args, the new version clucks if @_ contains an undef. IE something that exists but is not defined, EG catdir('/home',undef,'wibble')

--- lib.old/File/Spec/Unix.pm 2008-02-11 19:43:20.000000000 -0800 +++ lib/File/Spec/Unix.pm 2008-08-08 16:15:55.000000000 -0700 @@ -1,6 +1,7 @@ package File::Spec::Unix; use strict; +use Carp qw(cluck); use vars qw($VERSION); $VERSION = '3.2701'; @@ -78,7 +79,12 @@ sub catdir { my $self = shift; - + for ( @_ ) { + if ( !defined($_) ) { + cluck "Undefined arg passed to catdir"; + last; + } + } $self->canonpath(join('/', @_, '')); # '' because need a trailing + '/' } @@ -91,6 +97,11 @@ sub catfile { my $self = shift; + for ( @_ ) { + if ( !defined($_) ) { + cluck "Undefined arg passed to catfile"; + last; + } my $file = $self->canonpath(pop @_); return $file unless @_; my $dir = $self->catdir(@_);

Comment on File::Spec patch
Select or Download Code
Re: File::Spec patch
by parv (Priest) on Aug 08, 2008 at 23:40 UTC
    I wonder, admittedly out loud, just how many similar patches you are going to produce.

      Me too.

Re: File::Spec patch (alternative)
by tye (Cardinal) on Aug 09, 2008 at 05:56 UTC

    Next time you have this kind of problem, consider this technique instead:

    require Carp; $SIG{__WARN__} = sub { Carp::cluck(@_) };

    It will save you a lot of time trying to patch your copy of a module.

    You can also just start your script with "perl -d" then "c" since "o warn=1" is the default which means that you'll get a stack dump tacked on to each warning you get. You can probably even get the debugger to stop at the point of the warning so that you can look around and figure out the source of the problem:

    perl -d ... > $SIG{__WARN__} = sub { $DB::single = 1; } > c

    - tye        

      Yes!

      I'm going to print this out in huge letters and tape it to my wall. I'm going to hire a shadowy firm in Russia to email this advice to 3 million random strangers. I'm going to hack the web page of the 2008 Olympics and put this up in it's place.

      Indeed, it could be said that I find it helpful.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2014-12-17 22:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (36 votes), past polls