----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Monday, June 25, 2001 5:36 PM
Subject: Problem with filetest -x _ on Win2k AS Perl build 626




I was running Pod::Find::pod_find to list pod-containing files in
C:/perl/bin and I expected to see several .bat files in the list.

But there were none, although several of them contain pod (e.g.
pod2html.bat).

I looked into Pod::Find, drilled down into _check_and_extract_name() and
I found the code ...

sub _check_and_extract_name {
    my ($file, $verbose, $root_rx) = @_;

    # check extension or executable flag
    # this involves testing the .bat extension on Win32!
    unless(-f $file && -T _ && ($file =~ /\.(pod|pm|plx?)\z/i || -x _ ))
{
      return undef;
    }

return undef unless contains_pod($file,$verbose);

    # ... proceed with adding the accepted file to the lost of pods ...

... that decides to accept or reject a file, based on the extension and
on file tests.

A .bat file being a -f, -T and -x, it should be accepted, from reading above
unless clause.
***But this is not what happens - .bat files are rejected.***

After some experimenting I found two workarounds that fix the problem:


# change the order of terms in the && expression
    unless(-f $file _ && ($file =~ /\.(pod|pm|plx?)\z/i || -x _ ) && -T)
{
      return undef;

# replace -x _ by -x $file
    unless(-f $file && -T _ && ($file =~ /\.(pod|pm|plx?)\z/i || -x $file
)) {
      return undef;

What is bugging me is that changing the order of evaluation of the 3 terms

in the && expression can change the boolean result - this looks like a bug
to me.

I experimented some more and found that the malfunction of -x _ occurs
inside
a logical
expression, but not in a series of simple statements. The script below
demonstrates
these findings.
My Pod::Find is version 0.21.

Can anyone confirm my findings (or tell me if I am mistaken somewhere)?
If the bug is confirmed, should I ask the module author
([EMAIL PROTECTED])
to
add the workaround, or report the bug to ActiveState, or to someone else?


Rudif


#---------------------------------------------------------------------
#!perl -w
use strict;
use Pod::Find;

#
# Test Pod::Find::pod_find on C:/perl/bin
#

my $dir = 'C:/perl/bin';
my %pods = Pod::Find::pod_find({ -verbose => 1}, $dir);
my @pods = keys %pods;
my $n = keys %pods;
printf "Found $n files containing pods: @pods\n";
printf "NOTE 1: above finds .pl but not .bat files containing pods\n\n";

#
# Test using _ variable in filestests
#

my $bat = 'c:/perl/bin/pod2html.bat';
my $exe = 'c:/perl/bin/perl.exe';

filetest ($bat);
filetest ($exe);
printf "NOTE 2: above shows that -x _ basically works as advertized\n\n";

sub filetest {
my $file = shift;
    print "$file: ";
    stat($file);
    print " Readable" if -r _;
    print " Writable" if -w _;
    print " Executable" if -x _;
    print " Text" if -T _;
    print " Binary" if -B _;
    print "\n";
}


#
# Demo the bug and workarounds
#

# simplified from Pod::Find, -x _ does not work
printf "1 $bat ok for pod: %d\n", (-f $bat && -T _  && -x _);
# 4 workarounds
printf "2 $bat ok for pod: %d\n", (-f $bat && -x _    && -T _);
printf "3 $bat ok for pod: %d\n", (-f $bat && -x $bat && -T _);
printf "4 $bat ok for pod: %d\n", (-f $bat && -T _    && -x $bat);
printf "5 $bat ok for pod: %d\n", (-f $bat && -T $bat && -x $bat);
printf "NOTE 3: above shows that -x _ does not work as advertized in case
1\n\n";

#---------------------------------------------------------------------

Hi,
Just to confirm that I get the same (on same platform). Seems to me that the
use of '-T _' could be destroying perl's knowledge of just which file is
represented by '_' , which means that any subsequent references to '_' are
misunderstood.

As to why '-T _' should have such an effect, I don't know. Maybe it's a
consequence of the file having to be read when '-T' is called.

Cheers,
Rob





_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to