develooper Front page | perl.perl5.porters | Postings from September 2003

Pod::Perldoc's containspod method

From:
Sean M. Burke
Date:
September 9, 2003 21:52
Subject:
Pod::Perldoc's containspod method
Message ID:
5.2.1.1.1.20030909204221.023d0ec0@mailstore.pobox.com
So, Pod::Perldoc contains this routine that tests whether something 
contains pod:

sub containspod {
     my($self, $file, $readit) = @_;
     return 1 if !$readit && $file =~ /\.pod\z/i;
     local($_);
     open(TEST,"<", $file) 	or die "Can't open $file: $!";
     while (<TEST>) {
	if (/^=head/) {
	    close(TEST) 	or die "Can't close $file: $!";
	    return 1;
	}
     }
     close(TEST) 		or die "Can't close $file: $!";
     return 0;
}

It occurs to me that this code may get called on binaries now and 
then.  Would it be behoovey to add a "return 1 if -B $file;" early on?  Are 
there any portability problems with the -B (is binary) switch?  It just 
gives me the willies of the above code line-while'ing over the guts of 
binaries.

(BTW, I'm the person who refactored perldoc into Pod::Perldoc, but that 
doesn't make me a big expert on how it works.  If I've presumed something 
wrong about its workings, let me know!)
--
Sean M. Burke    http://search.cpan.org/~sburke/




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About