3 # We skip this on 5.9.0 and up since pseudohashes were removed and a lot of
6 print "1..0 # skip pseudo-hashes removed in 5.9.0\n";
14 $SIG{__WARN__} = sub {
15 if ($_[0] =~ /^Hides field 'b1' in base class/) {
28 use fields qw(b1 b2 b3);
32 use fields qw(b1 _b2 b2);
34 sub new { bless [], shift }
38 use fields qw(d1 d2 d3);
42 use fields qw(_d1 _d2);
47 use fields qw(b1 d1 _b1 _d1); # hide b1
51 use fields qw(_d3 d3);
62 package Foo::Bar::Baz;
64 use fields qw(foo bar baz);
66 # Test repeatability for when modules get reloaded.
68 use fields qw(b1 b2 b3);
72 use fields qw(b1 d1 _b1 _d1); # hide b1
77 local $SIG{__WARN__} = sub {
78 return if $_[0] =~ /^Pseudo-hashes are deprecated/
83 for my $k (sort {$h->{$a} <=> $h->{$b}} keys %$h) {
87 my $str = join(",", @tmp);
88 print "$h => $str\n" if $DEBUG;
93 B1 => "b1:1,b2:2,b3:3",
94 B2 => "_b1:1,b1:2,_b2:3,b2:4",
95 D1 => "b1:1,b2:2,b3:3,d1:4,d2:5,d3:6",
96 D2 => "b1:1,b2:2,b3:3,_d1:4,_d2:5,d1:6,d2:7",
97 D3 => "b2:4,b1:5,d1:6,_b1:7,_d1:8",
98 D4 => "b2:4,b1:5,d1:6,_d3:9,d3:10",
100 'Foo::Bar::Baz' => 'b1:1,b2:2,b3:3,foo:4,bar:5,baz:6',
103 print "1..", int(keys %expect)+21, "\n";
105 while (my($class, $exp) = each %expect) {
107 my $fstr = fstr(\%{$class."::FIELDS"});
108 print "EXP: $exp\nGOT: $fstr\nnot " unless $fstr eq $exp;
109 print "ok ", ++$testno, "\n";
112 # Did we get the appropriate amount of warnings?
113 print "not " unless $w == 1;
114 print "ok ", ++$testno, "\n";
116 # A simple object creation and AVHV attribute access test
117 my B2 $obj1 = D3->new;
122 print "not " unless $obj1->[2] eq "B2" && $obj1->[5] eq "D3";
123 print "ok ", ++$testno, "\n";
125 # We should get compile time failures field name typos
126 eval q(my D3 $obj3 = $obj2; $obj3->{notthere} = "");
127 print "not " unless $@ && $@ =~ /^No such pseudo-hash field "notthere"/;
128 print "ok ", ++$testno, "\n";
131 @$obj1{"_b1", "b1"} = (17, 29);
132 print "not " unless "@$obj1[1,2]" eq "17 29";
133 print "ok ", ++$testno, "\n";
134 @$obj1[1,2] = (44,28);
135 print "not " unless "@$obj1{'b1','_b1','b1'}" eq "28 44 28";
136 print "ok ", ++$testno, "\n";
139 local $SIG{__WARN__} = sub {
140 return if $_[0] =~ /^Pseudo-hashes are deprecated/
143 my $ph = fields::phash(a => 1, b => 2, c => 3);
144 print "not " unless fstr($ph) eq 'a:1,b:2,c:3';
145 print "ok ", ++$testno, "\n";
147 $ph = fields::phash([qw/a b c/], [1, 2, 3]);
148 print "not " unless fstr($ph) eq 'a:1,b:2,c:3';
149 print "ok ", ++$testno, "\n";
151 $ph = fields::phash([qw/a b c/], [1]);
152 print "not " if exists $ph->{b} or exists $ph->{c} or !exists $ph->{a};
153 print "ok ", ++$testno, "\n";
155 eval '$ph = fields::phash("odd")';
156 print "not " unless $@ && $@ =~ /^Odd number of/;
157 print "ok ", ++$testno, "\n";
162 # check if fields autovivify
165 use fields qw(foo bar);
166 sub new { bless [], $_[0]; }
169 my Foo $a = Foo->new();
170 $a->{foo} = ['a', 'ok ' . ++$testno, 'c'];
171 $a->{bar} = { A => 'ok ' . ++$testno };
172 print $a->{foo}[1], "\n";
173 print $a->{bar}->{A}, "\n";
176 # check if fields autovivify
179 use fields qw(foo bar);
180 sub new { return fields::new($_[0]) }
183 my Bar $a = Bar::->new();
184 $a->{foo} = ['a', 'ok ' . ++$testno, 'c'];
185 $a->{bar} = { A => 'ok ' . ++$testno };
186 print $a->{foo}[1], "\n";
187 print $a->{bar}->{A}, "\n";
197 package Test::Version;
199 use base qw(No::Version);
200 print "# $No::Version::VERSION\nnot " unless $No::Version::VERSION =~ /set by base\.pm/;
201 print "ok ", ++$testno ,"\n";
203 # Test Inverse of $VERSION bug base.pm should not clobber existing $VERSION
204 package Has::Version;
206 BEGIN { $Has::Version::VERSION = '42' };
208 package Test::Version2;
210 use base qw(Has::Version);
211 print "#$Has::Version::VERSION\nnot " unless $Has::Version::VERSION eq '42';
212 print "ok ", ++$testno ," # Has::Version\n";
222 $Eval2::VERSION = "1.02";
224 $Eval1::VERSION = "1.01";
229 printf "# %s\nnot ", $@ if $@;
230 print "ok ", ++$testno ," # eval1\n";
232 print "# $Eval1::VERSION\nnot " unless $Eval1::VERSION == 1.01;
233 print "ok ", ++$testno ," # Eval1::VERSION\n";
235 print "# $Eval2::VERSION\nnot " unless $Eval2::VERSION == 1.02;
236 print "ok ", ++$testno ," # Eval2::VERSION\n";
239 eval q{use base reallyReAlLyNotexists;};
240 print "not " unless $@;
241 print "ok ", ++$testno, " # really not I\n";
243 eval q{use base reallyReAlLyNotexists;};
244 print "not " unless $@;
245 print "ok ", ++$testno, " # really not II\n";
247 BEGIN { $Has::Version_0::VERSION = 0 }
249 package Test::Version3;
251 use base qw(Has::Version_0);
252 print "#$Has::Version_0::VERSION\nnot " unless $Has::Version_0::VERSION == 0;
253 print "ok ", ++$testno ," # Version_0\n";