File: RECOVER_RESULT.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 (27 lines) | stat: -rw-r--r-- 603 bytes parent folder | download | duplicates (7)
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
use Contextual::Return;

sub bar {
    return 'in bar';
}

sub foo {
    return
        BOOL      { 0 }
        LIST      { 1,2,3 }
        NUM       { 42 }
        STR       { 'forty-two' }
        SCALAR    { 86 }
        RECOVER   { RESULT { wantarray ? 1..9 : 99 } }
    ;
}

package Other;
use Test::More qw< no_plan >;

is_deeply [ ::foo() ], [1..9]                  => 'LIST context';

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

is 0+::foo(), 99                                => 'NUMERIC context';

is "".::foo(), '99'                             => 'STRING context';