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

Pod::Perldoc's containspod method

Sean M. Burke
September 9, 2003 21:52
Pod::Perldoc's containspod method
Message ID:
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;
     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 

(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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About