18 # First we must set up some selfloader files
19 mkdir $dir, 0755 or die "Can't mkdir $dir: $!";
21 open(FOO, ">$dir${sep}Foo.pm") or die;
26 sub new { bless {}, shift }
31 sub never; # declared but definition should never be read
35 sub foo { shift; shift || "foo" };
37 sub bar { shift; shift || "bar" }
39 sub bazmarkhianish { shift; shift || "baz" }
42 sub bleat { shift; shift || "baa" }
45 sub never { die "D'oh" }
50 open(BAR, ">$dir${sep}Bar.pm") or die;
57 sub new { bless {}, shift }
67 sub never { die "D'oh" }
87 print "not " unless $foo->foo eq 'foo'; # selfloaded first time
90 print "not " unless $foo->foo eq 'foo'; # regular call
93 # Try an undefined method
97 if ($@ =~ /^Undefined subroutine/) {
100 print "not ok 3 $@\n";
103 # Used to be trouble with this
111 print "not ok 4 $@\n";
114 # Pass regular expression variable to autoloaded function. This used
115 # to go wrong in AutoLoader because it used regular expressions to generate
116 # autoloaded filename.
118 print "not " unless $1 eq 'foo';
121 print "not " unless $foo->bar($1) eq 'foo';
124 print "not " unless $foo->bar($1) eq 'foo';
127 print "not " unless $foo->bazmarkhianish($1) eq 'foo';
130 print "not " unless $foo->bazmarkhianish($1) eq 'foo';
133 # Check nested packages inside __DATA__
134 print "not " unless sheep::bleat() eq 'baa';
137 # Now check inheritance:
141 # Before anything is SelfLoaded there is no declaration of Foo::b so we should
143 print "not " unless $bar->b() eq 'b Baz';
146 # There is no Bar::c so we should get Baz::c
147 print "not " unless $bar->c() eq 'c Baz';
150 # This selfloads Bar::a because it is stubbed. It also stubs Bar::b as a side
152 print "not " unless $bar->a() eq 'a Bar';
155 print "not " unless $bar->b() eq 'b Bar';
158 print "not " unless $bar->c() eq 'c Baz';
163 # Check that __END__ is honoured
164 # Try an subroutine that should never be noticed by selfloader
168 if ($@ =~ /^Undefined subroutine/) {
171 print "not ok 16 $@\n";
174 # Try to read from the data file handle
175 my $foodata = <Foo::DATA>;
177 if (defined $foodata) {
178 print "not ok 17 # $foodata\n";
183 # Check that __END__ DATA is honoured
184 # Try an subroutine that should never be noticed by selfloader
188 if ($@ =~ /^Undefined subroutine/) {
191 print "not ok 18 $@\n";
194 # Try to read from the data file handle
195 my $bardata = <Bar::DATA>;
197 if ($bardata ne "sub never { die \"D'oh\" }\n") {
198 print "not ok 19 # $bardata\n";
205 return unless $dir && -d $dir;
206 unlink "$dir${sep}Foo.pm", "$dir${sep}Bar.pm";