So, had a look into B::Deparse and I can confirm that it doesn't even try to handle __END__ .
As I expected it only tries to read the data from the <DATA> of the last package and always assumes that a __DATA__ line was leading.¹
That's the corresponding code chunk
# Print __DATA__ section, if necessary
no strict 'refs';
my $laststash = defined $self->{'curcop'}
? $self->{'curcop'}->stash->NAME : $self->{'curstash'};
if (defined *{$laststash."::DATA"}{IO}) {
print "package $laststash;\n"
unless $laststash eq $self->{'curstash'};
print "__DATA__\n";
print readline(*{$laststash."::DATA"});
}
Theoretically it's not that difficult to decide if there was a preceding __END__ or __DATA__ , one only needs to seek back.
my $laststash = "main";
my $data=\*{$laststash."::DATA"};
$last = tell $data;
seek $data,-20,1; # -20 is just a temporary hack for proof
+of concept
my $endline;
$endline = readline($data) while tell $data < $last;
print $endline;
print <$data>;
#package Test;
# __DATA__
# data
# data
__END__
end
end
this will print
__END__
end
end
and after uncommenting __DATA__
__DATA__
# data
# data
__END__
end
end
The real issue is finding the real file handle, cause __END__ always belongs to *main::DATA no matter which package was used.
This issue needs some testing and even more documentation, cause I'm not 100% sure how multiple __END__ or __DATA__ sections in different files are handled.
I suppose (IIRC) that the last (current) __END__ dominates, but which filehandles are then even defined?
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
¹) could be called a bug! |