-
Notifications
You must be signed in to change notification settings - Fork 576
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
Allow curfile to work in Perl Config files #1494
Conversation
I'm not totally against this, but the #line hack can be very finicky and I don't think this is really necessary. It's just as easy to store paths relative to your app home dir in the config file, and have the reader append it to the homedir. |
Hm, if the filename contains a newline, that might be a problem, so I "fixed" that in the updated commit ( |
I was surprised by the failure on Windows:
I hope my attempted fix of adding |
Spaces in the filename also break the #line directive, but this will just make |
Spaces in a filename work if it's double quoted, but then double quotes in the filename don't work. It's really just not well designed for generated code. |
Hrm, that is indeed not great. On the one hand, I could just add quotes around the filename and hope nothing breaks - but on the other hand, I guess the "defensive" way to code it would be to not include the
Background for why I suggested this in the first place: I'd like to use the same configuration in a non-Mojo script by |
Also allows __FILE__ and __LINE__ to work correctly.
- Formatting - Potential for '#line' directive to be broken across lines - Tests on Windows failing due to \ vs /
I looked at Perl's code and indeed there is no way to escape double quotes in So, I've simplified the code changes accordingly, added more tests to cover the special cases, and added a line in the documentation. I feel like I've done everything I can for now - I hope this passes muster. |
This pull request is now in conflicts. Could you fix it @haukex? 🙏 |
While i might vote in favour of the feature itself if done in the most minimalistic way possible, there is a lot of special cases in this PR i do not agree with. So 👎 from me on this specific implementation of the feature. |
Or to be more precise, there is already |
@kraih |
I personally don't love that the file is evaluated at all and I've been tending to use JSON and YAML config wherever possible. Meanwhile if your case for it is
then I really disagree. My understanding of the reasoning for evaluating was to give access to the app itself. In a non-mojo context, the app having no meaning, you're using a config file as a generic runnable file. If you need that I'd suggest simply doing so, |
I'm also against adding this functionality to the config. 👎 |
Thanks for the feedback everyone. |
In case someone stumbles over this in the future, the current solution is:
Without the need for imports. |
Summary
Allows
__FILE__
,__LINE__
, andMojo::File::curfile
to work correctly in Perl config files.Motivation
Allows one to create filenames relative to the current configuration file in the config. For example: