An idiom for :include {once}
Adriaan de Groot <adridg-FlD2LfDziEhmR6Xm/[email protected]>
| Newsgroups | gmane.comp.tools.aap.user |
|---|---|
| Message-ID | <[email protected]> |
When you use :include, you can specify {once} as an attribute, to prevent AAP
from including the file more than once. This is useful when the included file
contains :route commands, which cannot be redefined.
Unfortunately, this places the burden of deciding what to include once _at the
point of inclusion_, not in the included file. And it's the included file,
after all, that knows whether it can be included more than once or not.
Hence, {once} isn't a very useful mechanism for including things once because
the recipe doing the :including pretty much needs to specify {once} for
_every_ include, just to be safe.
Once workaround is to make {once} default for include, and add a {noonce} to
allow multiple inclusion explicitly.
Or, here's an idiom comparable to C's #ifndef #define idiom to prevent
multiple inclusion in the file that is being included.
filename_aap_seen?=1
@if _no.filename_aap_seen == "1":
# Normal content of file
filename_aap_seen=2
This assumes - just like the C idiom - that noone else messes with the
..._seen variables. Because the filename_aap_seen variable is given a value,
the first assignment is done exactly once, and the bottom assignment prevents
the @if statement from being executed a second time.
Another form of the same idiom is
@if not globals().get("_no.filename_aap_seen"):
# Normal contents
filename_aap_seen=1
--
pub 1024D/FEA2A3FE 2002-06-18 Adriaan de Groot <[email protected]>
Key fingerprint = 934E 31AA 80A7 723F 54F9 50ED 76AC EE01 FEA2 A3FE
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01