9 if ($_[0] =~ /^Hides field 'b1' in base class/) {
22 use fields qw(b1 b2 b3);
26 use fields qw(b1 _b2 b2);
28 sub new { bless [], shift }
32 use fields qw(d1 d2 d3);
36 use fields qw(_d1 _d2);
41 use fields qw(b1 d1 _b1 _d1); # hide b1
45 use fields qw(_d3 d3);
56 package Foo::Bar::Baz;
58 use fields qw(foo bar baz);
60 # Test repeatability for when modules get reloaded.
62 use fields qw(b1 b2 b3);
66 use fields qw(b1 d1 _b1 _d1); # hide b1
73 for my $k (sort {$h->{$a} <=> $h->{$b}} keys %$h) {
77 my $str = join(",", @tmp);
78 print "$h => $str\n" if $DEBUG;
83 B1 => "b1:1,b2:2,b3:3",
84 B2 => "_b1:1,b1:2,_b2:3,b2:4",
85 D1 => "b1:1,b2:2,b3:3,d1:4,d2:5,d3:6",
86 D2 => "b1:1,b2:2,b3:3,_d1:4,_d2:5,d1:6,d2:7",
87 D3 => "b2:4,b1:5,d1:6,_b1:7,_d1:8",
88 D4 => "b2:4,b1:5,d1:6,_d3:9,d3:10",
90 'Foo::Bar::Baz' => 'b1:1,b2:2,b3:3,foo:4,bar:5,baz:6',
93 print "1..", int(keys %expect)+21, "\n";
95 while (my($class, $exp) = each %expect) {
97 my $fstr = fstr(\%{$class."::FIELDS"});
98 print "EXP: $exp\nGOT: $fstr\nnot " unless $fstr eq $exp;
99 print "ok ", ++$testno, "\n";
102 # Did we get the appropriate amount of warnings?
103 print "not " unless $w == 1;
104 print "ok ", ++$testno, "\n";
106 # A simple object creation and AVHV attribute access test
107 my B2 $obj1 = D3->new;
112 print "not " unless $obj1->[2] eq "B2" && $obj1->[5] eq "D3";
113 print "ok ", ++$testno, "\n";
115 # We should get compile time failures field name typos
116 eval q(my D3 $obj3 = $obj2; $obj3->{notthere} = "");
117 print "not " unless $@ && $@ =~ /^No such pseudo-hash field "notthere"/;
118 print "ok ", ++$testno, "\n";
121 @$obj1{"_b1", "b1"} = (17, 29);
122 print "not " unless "@$obj1[1,2]" eq "17 29";
123 print "ok ", ++$testno, "\n";
124 @$obj1[1,2] = (44,28);
125 print "not " unless "@$obj1{'b1','_b1','b1'}" eq "28 44 28";
126 print "ok ", ++$testno, "\n";
128 my $ph = fields::phash(a => 1, b => 2, c => 3);
129 print "not " unless fstr($ph) eq 'a:1,b:2,c:3';
130 print "ok ", ++$testno, "\n";
132 $ph = fields::phash([qw/a b c/], [1, 2, 3]);
133 print "not " unless fstr($ph) eq 'a:1,b:2,c:3';
134 print "ok ", ++$testno, "\n";
136 $ph = fields::phash([qw/a b c/], [1]);
137 print "not " if exists $ph->{b} or exists $ph->{c} or !exists $ph->{a};
138 print "ok ", ++$testno, "\n";
140 eval '$ph = fields::phash("odd")';
141 print "not " unless $@ && $@ =~ /^Odd number of/;
142 print "ok ", ++$testno, "\n";
146 # check if fields autovivify
149 use fields qw(foo bar);
150 sub new { bless [], $_[0]; }
153 my Foo $a = Foo->new();
154 $a->{foo} = ['a', 'ok ' . ++$testno, 'c'];
155 $a->{bar} = { A => 'ok ' . ++$testno };
156 print $a->{foo}[1], "\n";
157 print $a->{bar}->{A}, "\n";
160 # check if fields autovivify
163 use fields qw(foo bar);
164 sub new { return fields::new($_[0]) }
167 my Bar $a = Bar::->new();
168 $a->{foo} = ['a', 'ok ' . ++$testno, 'c'];
169 $a->{bar} = { A => 'ok ' . ++$testno };
170 print $a->{foo}[1], "\n";
171 print $a->{bar}->{A}, "\n";
181 package Test::Version;
183 use base qw(No::Version);
184 print "# $No::Version::VERSION\nnot " unless $No::Version::VERSION =~ /set by base\.pm/;
185 print "ok ", ++$testno ,"\n";
187 # Test Inverse of $VERSION bug base.pm should not clobber existing $VERSION
188 package Has::Version;
190 BEGIN { $Has::Version::VERSION = '42' };
192 package Test::Version2;
194 use base qw(Has::Version);
195 print "#$Has::Version::VERSION\nnot " unless $Has::Version::VERSION eq '42';
196 print "ok ", ++$testno ," # Has::Version\n";
206 $Eval2::VERSION = "1.02";
208 $Eval1::VERSION = "1.01";
213 printf "# %s\nnot ", $@ if $@;
214 print "ok ", ++$testno ," # eval1\n";
216 print "# $Eval1::VERSION\nnot " unless $Eval1::VERSION == 1.01;
217 print "ok ", ++$testno ," # Eval1::VERSION\n";
219 print "# $Eval2::VERSION\nnot " unless $Eval2::VERSION == 1.02;
220 print "ok ", ++$testno ," # Eval2::VERSION\n";
223 eval q{use base reallyReAlLyNotexists;};
224 print "not " unless $@;
225 print "ok ", ++$testno, " # really not I\n";
227 eval q{use base reallyReAlLyNotexists;};
228 print "not " unless $@;
229 print "ok ", ++$testno, " # really not II\n";
231 BEGIN { $Has::Version_0::VERSION = 0 }
233 package Test::Version3;
235 use base qw(Has::Version_0);
236 print "#$Has::Version_0::VERSION\nnot " unless $Has::Version_0::VERSION == 0;
237 print "ok ", ++$testno ," # Version_0\n";