File: lastres.pm

package info (click to toggle)
liblist-moreutils-xs-perl 0.430-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,116 kB
  • sloc: perl: 9,038; ansic: 159; makefile: 3
file content (27 lines) | stat: -rw-r--r-- 497 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
BEGIN
{
    $INC{'List/MoreUtils.pm'} or *last_result = __PACKAGE__->can("lastres");
}

use Test::More;
use Test::LMU;

my $x = lastres { 2 * ($_ > 5) } 4 .. 9;
is($x, 2);
$x = lastres { $_ > 5 } 1 .. 4;
is($x, undef);

# Test aliases
$x = last_result { $_ > 5 } 4 .. 9;
is($x, 1);
$x = last_result { $_ > 5 } 1 .. 4;
is($x, undef);

leak_free_ok(
    lastres => sub {
        $x = lastres { $_ > 5 } 4 .. 9;
    }
);
is_dying('lastres without sub' => sub { &lastres(42, 4711); });

done_testing;