File: lvalue.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 (45 lines) | stat: -rw-r--r-- 1,103 bytes parent folder | download | duplicates (3)
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
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();