11 # First we must set up some selfloader files
12 mkdir $dir, 0755 or die "Can't mkdir $dir: $!";
14 open(FOO, ">$dir/Foo.pm") or die;
19 sub new { bless {}, shift }
24 sub never; # declared but definition should never be read
28 sub foo { shift; shift || "foo" };
30 sub bar { shift; shift || "bar" }
32 sub bazmarkhianish { shift; shift || "baz" }
35 sub bleat { shift; shift || "baa" }
38 sub never { die "D'oh" }
43 open(BAR, ">$dir/Bar.pm") or die;
50 sub new { bless {}, shift }
60 sub never { die "D'oh" }
80 print "not " unless $foo->foo eq 'foo'; # selfloaded first time
83 print "not " unless $foo->foo eq 'foo'; # regular call
86 # Try an undefined method
90 if ($@ =~ /^Undefined subroutine/) {
93 print "not ok 3 $@\n";
96 # Used to be trouble with this
104 print "not ok 4 $@\n";
107 # Pass regular expression variable to autoloaded function. This used
108 # to go wrong in AutoLoader because it used regular expressions to generate
109 # autoloaded filename.
111 print "not " unless $1 eq 'foo';
114 print "not " unless $foo->bar($1) eq 'foo';
117 print "not " unless $foo->bar($1) eq 'foo';
120 print "not " unless $foo->bazmarkhianish($1) eq 'foo';
123 print "not " unless $foo->bazmarkhianish($1) eq 'foo';
126 # Check nested packages inside __DATA__
127 print "not " unless sheep::bleat() eq 'baa';
130 # Now check inheritance:
134 # Before anything is SelfLoaded there is no declaration of Foo::b so we should
136 print "not " unless $bar->b() eq 'b Baz';
139 # There is no Bar::c so we should get Baz::c
140 print "not " unless $bar->c() eq 'c Baz';
143 # This selfloads Bar::a because it is stubbed. It also stubs Bar::b as a side
145 print "not " unless $bar->a() eq 'a Bar';
148 print "not " unless $bar->b() eq 'b Bar';
151 print "not " unless $bar->c() eq 'c Baz';
156 # Check that __END__ is honoured
157 # Try an subroutine that should never be noticed by selfloader
161 if ($@ =~ /^Undefined subroutine/) {
164 print "not ok 16 $@\n";
167 # Try to read from the data file handle
168 my $foodata = <Foo::DATA>;
170 if (defined $foodata) {
171 print "not ok 17 # $foodata\n";
176 # Check that __END__ DATA is honoured
177 # Try an subroutine that should never be noticed by selfloader
181 if ($@ =~ /^Undefined subroutine/) {
184 print "not ok 18 $@\n";
187 # Try to read from the data file handle
188 my $bardata = <Bar::DATA>;
190 if ($bardata ne "sub never { die \"D'oh\" }\n") {
191 print "not ok 19 # $bardata\n";
198 return unless $dir && -d $dir;
199 unlink "$dir/Foo.pm", "$dir/Bar.pm";