Daniel Dan - 2013-11-04

New scoping level introduced for '#adapt:' command

Propagation of VCL variable values:
Having executed #set x = 10, the VCL Processor propagates value of x to all files reached along #adapt links. The first executed #set x overrides any subsequently found #set x commands in adapted files. An exception from the above rule is the situation where two #set commands assign values to the same variable in the same file.

In VCL 1.1 if we introduce a new scoping level along these lines. When we declare variables in an #adapt command, the scope of the declared variable will be on a middle level between the current file and the adapted file.
It will be on lower level than the current file, so it does not override it (the value will be set back when exiting the #adapt command's body), and higher level than the adapted file (it overrides the variable's value in the adapted file).
See examples below:

Example 1:

SPC.vcl:

#set a = 5          % scoping level: "SPC.vcl"
#adapt: "file1.vcl"
  #set a = 10       % scoping level: "between SPC.vcl and file1.vcl"
#endadapt           % closing scoping level "between SPC.vcl and file1.vcl", 
                    % value of a will be 5 again

value of a is in end of SPC is : ?@a?

file1.vcl:

value of a is in beginning of file1.vcl is : ?@a?
#set a = 20         % scoping level "file1.vcl" variable 
                    % a does not get overridden by this command

value of a is in end of file1.vcl is : ?@a?
~~~~~~~~~~~~~~~

output:

~~~~~~~~~~~~~~~
value of a is in beginning of file.vcl is : 10
value of a is in end of file.vcl is : 10
value of a is in end of SPC is : 5
~~~~~~~~~~~~~~~

Example 2:
--------------
SPC.vcl

adapt: "file1.vcl"

#set a = 10 % scoping level: "between SPC.vcl and file1.vcl"

endadapt % closing scoping level "between SPC.vcl and file1.vcl",

                % value of a will be 5 again

value of a is in end of SPC is : ?@a?
~~~~~~~~~~~~~

file1.vcl:

value of a is in beginning of file1.vcl is : ?@a?
#set a = 20         % scoping level "file1.vcl" variable 
                    % a does not get overridden by this command

value of a is in end of file1.vcl is : ?@a?
~~~~~~~~~~~~~~~

output:

~~~~~~~~~~~~~~~
value of a is in beginning of file.vcl is : 10
value of a is in end of file.vcl is : 10
value of a is in end of SPC is : 
Error stream: Error in file: SPC.vcl line: 4: Variable a is not defined
~~~~~~~~~~~~~~~

Example 3:
----------------------
SPC.vcl:

set a = 5 % scoping level: "SPC.vcl"

adapt: "file1.vcl"

#set a = 10 % scoping level: "between SPC.vcl and file1.vcl"

endadapt % closing scoping level "between SPC.vcl and file1.vcl",

                % value of a will be 5 again

value of a is in end of SPC is : ?@a?

file1.vcl:

value of a is in beginning of file1.vcl is : ?@a?

set a = 20 % scoping level "file1.vcl" variable

                % a does not get overridden by this command

adapt: "file2.vcl"

#set a = 555 % scoping level: "between file1.vcl and file2.vcl"
% a does not get overridden by this command
% scope "between SPC.vcl and file1.vcl" is on higher level

endadapt

value of a is in end of file1.vcl is : ?@a?

file2.vcl:

~~~~~~~~~~~~~~
value of a is in beginning of file2.vcl is : ?@a?
  #set a = 20       % scoping level "file2.vcl" variable 
                    % a does not get overridden by this command

value of a is in end of file2.vcl is : ?@a?

output:

value of a is in beginning of file1.vcl is : 10
value of a is in beginning of file2.vcl is : 10
value of a is in end of file2.vcl is : 10
value of a is in end of file1.vcl is : 10
value of a is in end of SPC is : 5

New scoping level is valid for inserts into breakpoints too.

 

Last edit: Daniel Dan 2013-11-04