Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use do rather than require to load a mojo application #2097

Merged
merged 1 commit into from
Aug 25, 2023

Conversation

haarg
Copy link
Contributor

@haarg haarg commented Aug 24, 2023

Summary

Use do rather than require to load a mojo application to fix compatibility with new module_true core feature.

Motivation

The return value of require is usually not a reasonable thing to rely on, aside from it being true. The first time requiring a file, it will return the value of the last statement in the file. The second time requiring a file, it will return a simple true value.

Mojo was bypassing this problem by deleting the %INC entry for the file, forcing it to always be loaded again. But the new module_true core feature will cause require to always return a simple true value rather than the last statement in the file. This does not apply to do though.

References

#2094

The return value of require is usually not a reasonable thing to rely
on, aside from it being true. The first time requiring a file, it will
return the value of the last statement in the file. The second time
requiring a file, it will return a simple true value.

Mojo was bypassing this problem by deleting the %INC entry for the file,
forcing it to always be loaded again. But the new module_true core
feature will cause require to always return a simple true value rather
than the last statement in the file. This does not apply to do though.

Switch to using do to be compatible with code using the new feature.
@haarg haarg force-pushed the fix-module-true-compat branch from 0cc3b20 to 693fc6c Compare August 24, 2023 14:12
Copy link
Member

@jberger jberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally I approve, however I wonder if in the test it should explicitly load the module_true pragma rather than the feature bundle, and if it should do so after Mojolicious::Lite. That way if some "fixup" is ever attempted in either of those places we'd still be explicitly testing the pragma not the generic scenario? Maybe both?

Copy link
Member

@jhthorsen jhthorsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Bringing Mojo into the future 👍

@mergify mergify bot merged commit d84c8a8 into mojolicious:main Aug 25, 2023
@kraih
Copy link
Member

kraih commented Sep 18, 2023

There is a report that this might have caused a regression: #2109, #2110

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants