File: retobj.t

package info (click to toggle)
libcontextual-return-perl 0.004014-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 348 kB
  • sloc: perl: 1,453; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 602 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use Contextual::Return;

sub foo {
    return
        PUREBOOL  { $_ = RETOBJ; next handler; }
        BOOL      { 1 }
        DEFAULT   { 42 }
    ;
}

package Other;
use Test::More 'no_plan';

is do{ ::foo() ? 'true' : 'false' }, 'true'         => 'PURE BOOLEAN context';

is $_, 42                                           => 'Pure boolean assigned';

is ref $_, 'Contextual::Return::Value'              => 'RETOBJ is object';

my $x;
undef $_;
is do{ ($x = ::foo()) ? 'true' : 'false' }, 'true'  => 'BOOLEAN context';

ok !defined $_                                      => 'RETOBJ not assigned';