File: retobj.t

package info (click to toggle)
libcontextual-return-perl 0.003001-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 324 kB
  • ctags: 52
  • sloc: perl: 1,187; makefile: 2
file content (21 lines) | stat: -rw-r--r-- 513 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
is do{ ($x = ::foo()) ? 'true' : 'false' }, 'true'  => 'BOOLEAN context';