On Sun, Oct 26, 2003 at 04:45:48PM +1100, Andrew Savige wrote: > Michael G Schwern wrote: > > Since skip_all will exit immediately you can fold that big "everything > > inside the else block" away. > > > > eval 'use Test::Pod'; > > my $have_testpod = !$@ and $Test::Pod::VERSION >= 0.95; > > plan skip_all => "Test::Pod v0.95 required for testing POD" > > unless $have_testpod; > > > > my @files; > > my $blib = File::Spec->catfile(qw(blib lib)); > > ... > > There is a misprint in this line: > my $have_testpod = !$@ and $Test::Pod::VERSION >= 0.95; > It should read: > my $have_testpod = !$@ && $Test::Pod::VERSION >= 0.95;
I deliberately used and instead of &&. I'd noticed the original was using explicit parens to disambiuate the precendence to make sure there was no chance of it accidentally evaluating as: (!$@ && $Test::Pod::VERSION) >= 0.95 for those of us that don't have the symbol table memorized. Instead of parens, I went with 'and'. But looking at the precdence table, either version will work. > Based on the excellent work from Lester & Schwern, I could not restrain > myself from shortening this a little more (since it will be included > in many distributions). The logic escapes me. Clarity is more important than length if you're going to be sticking this code all over the place. But if we're going to encourage people to copy this code, Test::Pod should probably just have a subroutine to do this for you. That's what libraries are for! > My current short version is: > > use Test::More; > use File::Spec; > use File::Find; > use strict; > eval 'use Test::Pod'; > plan skip_all => "Test::Pod v0.95 required for testing POD" > if $@ || $Test::Pod::VERSION < 0.95; > my @files; > find( sub {push @files, $File::Find::name if /\.p(?:l|m|od)$/}, > File::Spec->catfile( qw(blib lib) ) ); > plan tests => scalar @files; > foreach my $file (@files) { pod_file_ok($file) } > > Two questions: > > 1) Is using $File::Find::name portable on VMS and Mac OS? > (I'm confused about File::Find's use of 'Unix' names). Since you're just looking at the end of the filename, yes. It doesn't matter if the path is Unixy or native. In fact, since the directory name doesn't matter you can match against $_. > 2) Which is preferred: > eval 'use Test::Pod'; > or: > eval { require Test::Pod }; > ... > Test::Pod->import; > or does it not matter? Doesn't really matter. If I was going to be strict about it I'd say do this: BEGIN { eval { require Test::Pod }; plan skip_all => "Test::Pod v0.95 required for testing POD" if $@ || $Test::Pod::VERSION < 0.95; Test::Pod->import; } or this: BEGIN { eval q{ use Test::Pod 0.95 }; plan skip_all => "Test::Pod v0.95 required for testing POD" if $@; } so that the functions are imported at compile time. This means you can use them without parens. I like the latter since its most straight forward and concise. -- Michael G Schwern [EMAIL PROTECTED] http://www.pobox.com/~schwern/ WOOHOO! I'm going to Disneyland! http://www.goats.com/archive/980805.html