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" }
44 sub never { die "D'oh" }
49 open(BAR, ">$dir${sep}Bar.pm") or die;
56 sub new { bless {}, shift }
58 sub with_whitespace_in_front;
66 sub with_whitespace_in_front {
67 "with_whitespace_in_front Bar"
71 sub never { die "D'oh" }
91 print "not " unless $foo->foo eq 'foo'; # selfloaded first time
94 print "not " unless $foo->foo eq 'foo'; # regular call
97 # Try an undefined method
101 if ($@ =~ /^Undefined subroutine/) {
104 print "not ok 3 $@\n";
107 # Used to be trouble with this
115 print "not ok 4 $@\n";
118 # Pass regular expression variable to autoloaded function. This used
119 # to go wrong in AutoLoader because it used regular expressions to generate
120 # autoloaded filename.
122 print "not " unless $1 eq 'foo';
125 print "not " unless $foo->bar($1) eq 'foo';
128 print "not " unless $foo->bar($1) eq 'foo';
131 print "not " unless $foo->bazmarkhianish($1) eq 'foo';
134 print "not " unless $foo->bazmarkhianish($1) eq 'foo';
137 # Check nested packages inside __DATA__
138 print "not " unless sheep::bleat() eq 'baa';
141 # Now check inheritance:
145 # Before anything is SelfLoaded there is no declaration of Foo::b so we should
147 print "not " unless $bar->b() eq 'b Baz';
150 # There is no Bar::c so we should get Baz::c
151 print "not " unless $bar->c() eq 'c Baz';
154 # check that subs with whitespace in front work
155 print "not " unless $bar->with_whitespace_in_front() eq 'with_whitespace_in_front Bar';
158 # This selfloads Bar::a because it is stubbed. It also stubs Bar::b as a side
160 print "not " unless $bar->a() eq 'a Bar';
163 print "not " unless $bar->b() eq 'b Bar';
166 print "not " unless $bar->c() eq 'c Baz';
171 # Check that __END__ is honoured
172 # Try an subroutine that should never be noticed by selfloader
176 if ($@ =~ /^Undefined subroutine/) {
179 print "not ok 17 $@\n";
182 # Try to read from the data file handle
183 my $foodata = <Foo::DATA>;
185 if (defined $foodata) {
186 print "not ok 18 # $foodata\n";
191 # Check that __END__ DATA is honoured
192 # Try an subroutine that should never be noticed by selfloader
196 if ($@ =~ /^Undefined subroutine/) {
199 print "not ok 19 $@\n";
202 # Try to read from the data file handle
203 my $bardata = <Bar::DATA>;
205 if ($bardata ne "sub never { die \"D'oh\" }\n") {
206 print "not ok 20 # $bardata\n";
213 return unless $dir && -d $dir;
214 unlink "$dir${sep}Foo.pm", "$dir${sep}Bar.pm";