]> git.vpit.fr Git - perl/modules/Lexical-Types.git/blob - t/12-padsv.t
Test and document constant as types
[perl/modules/Lexical-Types.git] / t / 12-padsv.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 7;
7
8 sub Str::TYPEDSCALAR {
9  my $buf = (caller(0))[2];
10  open $_[1], '<', \$buf;
11  ()
12 }
13
14 {
15  use Lexical::Types;
16
17  my Str $x;
18  our $r = <$x>;
19  is $r, __LINE__-2, 'trick for our - readline';
20
21  my Str $y;
22  my $s = <$y>;
23  is $s, __LINE__-2, 'trick for my - readline';
24
25  my $z = 7;
26  is $z, 7, 'trick for others';
27 }
28
29 my $count;
30 sub Int::TYPEDSCALAR { return ++$count }
31
32 { package INT; }
33
34 {
35  use Lexical::Types as => sub { $_[0] eq 'Int' ? @_ : () };
36
37  my Int ($x, $y);
38  is $x, 1, 'successive padany 1';
39  is $y, 2, 'successive padany 2';
40
41  my INT ($z, $t);
42  is $z, undef, 'successive padany 3';
43  is $t, undef, 'successive padany 4';
44 }