1N/A#!./perl
1N/A
1N/ABEGIN {
1N/A unless (-d 'blib') {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A require Config; import Config;
1N/A keys %Config; # Silence warning
1N/A if ($Config{extensions} !~ /\bList\/Util\b/) {
1N/A print "1..0 # Skip: List::Util was not built\n";
1N/A exit 0;
1N/A }
1N/A }
1N/A}
1N/A
1N/Ause List::Util qw(first);
1N/A
1N/Aprint "1..8\n";
1N/A
1N/Aprint "not " unless defined &first;
1N/Aprint "ok 1\n";
1N/A
1N/Aprint "not " unless 9 == first { 8 == ($_ - 1) } 9,4,5,6;
1N/Aprint "ok 2\n";
1N/A
1N/Aprint "not " if defined(first { 0 } 1,2,3,4);
1N/Aprint "ok 3\n";
1N/A
1N/Aprint "not " if defined(first { 0 });
1N/Aprint "ok 4\n";
1N/A
1N/Amy $foo = first { $_->[1] le "e" and "e" le $_->[2] }
1N/A [qw(a b c)], [qw(d e f)], [qw(g h i)];
1N/Aprint "not " unless $foo->[0] eq 'd';
1N/Aprint "ok 5\n";
1N/A
1N/A# Check that eval{} inside the block works correctly
1N/Amy $i = 0;
1N/Aprint "not " unless 5 == first { eval { die }; ($i == 5, $i = $_)[0] } 0,1,2,3,4,5,5;
1N/Aprint "ok 6\n";
1N/A
1N/Aprint "not " if defined eval { first { die if $_ } 0,0,1 };
1N/Aprint "ok 7\n";
1N/A
1N/A($x) = foobar();
1N/A$x = '' unless defined $x;
1N/Aprint "${x}ok 8\n";
1N/A
1N/Asub foobar { first { !defined(wantarray) || wantarray } "not ","not ","not " }
1N/A