Skip to content

incompatibility of package-block and __DATA__  #22613

Closed as not planned
Closed as not planned
@happy-barney

Description

@happy-barney

When using package block syntax and __DATA__ in single file, __DATA__ doesn't belong to package
but to the main.

__DATA__ documentation states:

Text after __DATA__ may be read via the filehandle "PACKNAME::DATA",
    where "PACKNAME" is the package that was current when the __DATA__ token
    was encountered.

Technically it is correct, __DATA__ token is not specified inside package block (ie, package block prevents usage of __DATA__)
But with code like in example that may be misleading.
It may also harm adoption of syntax.

Example:

use strict;
use warnings;

package Foo {
    print while <DATA>;
}

__DATA__
hello
world

Output

Name "Foo::DATA" used only once: possible typo at example.pl line 7.
readline() on unopened filehandle DATA at example.pl line 7.

All Perls v5.12 .. v5.40 are affected.

Proposal:

a) support __DATA__ inside package block (ie, it will be treated as } as well
b) treat insignificant content following } as content still belonging to the latest package block

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions