File: lvalue.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 (58 lines) | stat: -rw-r--r-- 1,223 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use Test::More 'no_plan';
use Contextual::Return;

{
    sub foo : lvalue {
        my $x = 0;
        my $wantarray = wantarray;
        RVALUE { 
            BOOL { $x > 0 }
            STR  { "[$x]" }
            NUM  {   $x   }
        }
        LVALUE {
            $x = $_[0] * $_;
            is $CALLER::_, 'wunderbar' => 'Caller::_';
        }
        NVALUE {
            ok !defined $wantarray     => 'NVALUE context';
        }
    }
}

$_ = 'wunderbar';

for my $foo (foo 10) {
    is $foo+0,   0      => "Pre-numerication";
    is "$foo", "[0]"    => "Pre-stringification";
    ok !$foo            => "Pre-boolification";
    $foo = 99;
    is $foo+0,   990    => "Post-numerication";
    is "$foo", "[990]"  => "Post-stringification";
    ok $foo             => "Post-boolification";
}

is 0+foo,    0    => "Ex-numerication";
is "".foo, "[0]"  => "Ex-stringification";
ok !foo()         => "Ex-boolification";
foo(1) = 99;
is 0+foo,    0    => "Ex-post-numerication";
is "".foo, "[0]"  => "Ex-post-stringification";
ok !$foo          => "Ex-post-boolification";

foo();

my $f = \foo();


{
    sub foo2 : lvalue {
        LVALUE {
            ok 1;
        }
    }
}

for my $foo (foo2) {
    $foo = 99;
}