1#!./perl 2 3BEGIN { 4 unless (-d 'blib') { 5 chdir 't' if -d 't'; 6 @INC = '../lib'; 7 require Config; import Config; 8 keys %Config; # Silence warning 9 if ($Config{extensions} !~ /\bList\/Util\b/) { 10 print "1..0 # Skip: List::Util was not built\n"; 11 exit 0; 12 } 13 } 14} 15 16use List::Util qw(first); 17 18print "1..8\n"; 19 20print "not " unless defined &first; 21print "ok 1\n"; 22 23print "not " unless 9 == first { 8 == ($_ - 1) } 9,4,5,6; 24print "ok 2\n"; 25 26print "not " if defined(first { 0 } 1,2,3,4); 27print "ok 3\n"; 28 29print "not " if defined(first { 0 }); 30print "ok 4\n"; 31 32my $foo = first { $_->[1] le "e" and "e" le $_->[2] } 33 [qw(a b c)], [qw(d e f)], [qw(g h i)]; 34print "not " unless $foo->[0] eq 'd'; 35print "ok 5\n"; 36 37# Check that eval{} inside the block works correctly 38my $i = 0; 39print "not " unless 5 == first { eval { die }; ($i == 5, $i = $_)[0] } 0,1,2,3,4,5,5; 40print "ok 6\n"; 41 42print "not " if defined eval { first { die if $_ } 0,0,1 }; 43print "ok 7\n"; 44 45($x) = foobar(); 46$x = '' unless defined $x; 47print "${x}ok 8\n"; 48 49sub foobar { first { !defined(wantarray) || wantarray } "not ","not ","not " } 50 51