File: scalar-to-list.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 (39 lines) | stat: -rw-r--r-- 863 bytes parent folder | download | duplicates (8)
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
28
29
30
31
32
33
34
35
36
37
38
39
use Test::More 'no_plan';
use Contextual::Return;

sub scalar_only {
    return (
        SCALAR { "scalar" }
    );
}

is join(q{ }, qw(It got a), scalar_only()), "It got a scalar" => 'Fell back to scalar';

sub str_num {
    return (
        STR { "scalar" }
        NUM { 1        }
    );
}

is join(q{ }, qw(It got a), str_num()), "It got a scalar" => 'Fell back to str';
is join(q{ }, qw(It got a), 0+str_num()), "It got a 1" => 'Fell back to num';

sub num_only {
    return (
        NUM { 1        }
    );
}

is join(q{ }, qw(It got a), num_only()), "It got a 1" => 'Fell back to num';

sub listy {
    return (
       LIST { qw(list of strings) }
        STR { "scalar" }
        NUM { 1        }
    );
}

is join(q{ }, qw(It got a), listy()), "It got a list of strings"
                                                       => 'List not preempted';