How can I detect if the current reading of a file is done directly from the command line, or is done via loading/requiring?
There is a well known way:
__FILE__ == $0
but this does not work correctly when there is a possibility that the main file loads itself.
It was too easy. I will just assign a flag and check it. A slightly tricky thing was the ordering of the relevant assignments. (a) condition, (b) assigning to a flag, and (c) loading have to come in this order:
If I wanted them in a different order, I have to embed some of these and force this order.