File: 01basic.t

package info (click to toggle)
liblexical-underscore-perl 0.004-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 156 kB
  • sloc: perl: 19; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 636 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
no if $] > 5.018000, warnings => qw(experimental);

use Test::More;
BEGIN {
	$] >= 5.010 or plan skip_all => "test requires Perl >= 5.010";
	$]  < 5.023 or plan skip_all => "test requires Perl < 5.023";
	plan tests => 6;
};

use lexical::underscore;

sub foo {
	my $_ = 101;
	bar();
	is($_, 42);
}

sub bar {
	$_ = 102;
	baz();
}

sub baz {
	my $_ = 103;
	quux();
}

sub quux {
	my $_ = 104;
	
	is(${ lexical::underscore() }, 103);
	is(${ lexical::underscore(-1) }, 104);
	is(${ lexical::underscore(0) }, 103);
	is(${ lexical::underscore(1) }, 102);
	is(${ lexical::underscore(2) }, 101);
	
	${ lexical::underscore(2) } = 42;
}

foo();