snoopyjc / pythonizer

Automatic translator from Perl to Python
https://snoopyjc.org/pythonizer/
Artistic License 2.0
12 stars 1 forks source link

If a BEGIN block is defined before a use statement, the use statement is still run first #325

Closed snoopyjc closed 1 year ago

snoopyjc commented 1 year ago

If a BEGIN block is defined before a use statement, the use statement is still run first. For example:

BEGIN { $ENV{DBI_PUREPERL} = 2 }
use DBI;

generates:

import DBI as _DBI
...
def __BEGIN__1():
    os.environ["DBI_PUREPERL"] = "2"
...
__BEGIN__1()
snoopyjc commented 1 year ago

Implemented a special case of a BEGIN block first in the perl input code that doesn't reference any package variables. This is because we allow it to run before init_package is called.

Also fixed pythonizer_importer to not split the error message into multiple lines, and also change double quotes in it to single quotes, since it's returned in a double-quoted string.

snoopyjc commented 1 year ago

Fixed in 1.029