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!


In reply to Re: Why shows B::Deparse __END__ as __DATA__? by LanX
in thread Why shows B::Deparse __END__ as __DATA__? by karlgoethebier

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.