12 unshift @INC, '../lib';
16 # First we must set up some selfloader files
17 mkdir $dir, 0755 or die "Can't mkdir $dir: $!";
19 open(FOO, ">$dir${sep}Foo.pm") or die;
24 sub new { bless {}, shift }
29 sub never; # declared but definition should never be read
33 sub foo { shift; shift || "foo" };
35 sub bar { shift; shift || "bar" }
37 sub bazmarkhianish { shift; shift || "baz" }
40 sub bleat { shift; shift || "baa" }
42 sub never { die "D'oh" }
47 open(BAR, ">$dir${sep}Bar.pm") or die;
54 sub new { bless {}, shift }
56 sub with_whitespace_in_front;
64 sub with_whitespace_in_front {
65 "with_whitespace_in_front Bar"
69 sub never { die "D'oh" }
89 print "not " unless $foo->foo eq 'foo'; # selfloaded first time
92 print "not " unless $foo->foo eq 'foo'; # regular call
95 # Try an undefined method
99 if ($@ =~ /^Undefined subroutine/) {
102 print "not ok 3 $@\n";
105 # Used to be trouble with this
113 print "not ok 4 $@\n";
116 # Pass regular expression variable to autoloaded function. This used
117 # to go wrong in AutoLoader because it used regular expressions to generate
118 # autoloaded filename.
120 print "not " unless $1 eq 'foo';
123 print "not " unless $foo->bar($1) eq 'foo';
126 print "not " unless $foo->bar($1) eq 'foo';
129 print "not " unless $foo->bazmarkhianish($1) eq 'foo';
132 print "not " unless $foo->bazmarkhianish($1) eq 'foo';
135 # Check nested packages inside __DATA__
136 print "not " unless sheep::bleat() eq 'baa';
139 # Now check inheritance:
143 # Before anything is SelfLoaded there is no declaration of Foo::b so we should
145 print "not " unless $bar->b() eq 'b Baz';
148 # There is no Bar::c so we should get Baz::c
149 print "not " unless $bar->c() eq 'c Baz';
152 # check that subs with whitespace in front work
153 print "not " unless $bar->with_whitespace_in_front() eq 'with_whitespace_in_front Bar';
156 # This selfloads Bar::a because it is stubbed. It also stubs Bar::b as a side
158 print "not " unless $bar->a() eq 'a Bar';
161 print "not " unless $bar->b() eq 'b Bar';
164 print "not " unless $bar->c() eq 'c Baz';
169 # Check that __END__ is honoured
170 # Try an subroutine that should never be noticed by selfloader
174 if ($@ =~ /^Undefined subroutine/) {
177 print "not ok 17 $@\n";
180 # Try to read from the data file handle
182 local $SIG{__WARN__} = sub { my $warn = shift; };
183 my $foodata = <Foo::DATA>;
185 if (defined $foodata) {
186 print "not ok 18 # $foodata\n";
192 # Check that __END__ DATA is honoured
193 # Try an subroutine that should never be noticed by selfloader
197 if ($@ =~ /^Undefined subroutine/) {
200 print "not ok 19 $@\n";
203 # Try to read from the data file handle
204 my $bardata = <Bar::DATA>;
206 if ($bardata ne "sub never { die \"D'oh\" }\n") {
207 print "not ok 20 # $bardata\n";
214 return unless $dir && -d $dir;
215 unlink "$dir${sep}Foo.pm", "$dir${sep}Bar.pm";