use strict; use warnings; use Test::More tests => 10; BEGIN { use_ok('Lambda') } { my $x; my $f = lambda($x => sub { $x }); is($f->('lex'), 'lex', 'lex1'); is($f->('LEX'), 'LEX', 'lex2'); is($x, undef, 'lex restore'); } { local our $x; my $f = lambda($x => sub { $x }); is($f->('pkg'), 'pkg', 'pkg1'); is($f->('PKG'), 'PKG', 'pkg2'); is($x, undef, 'pkg restore'); } { my $f = do { my $x; lambda($x => sub { $x }) }; is($f->('out of scope'), 'out of scope', 'out of scope'); } { my $y = 'test'; my $x; lambda($x => sub { $x = uc($x) })->($y); is($y, 'TEST', 'alias'); } { package Unfetchable; use Tie::Scalar qw( ); our @ISA = 'Tie::StdScalar'; sub FETCH { } } { tie my $x, 'Unfetchable'; my $f = lambda($x => sub { $x }); is($f->('test'), 'test', 'tied'); }