Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-1754

We need proper references

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Open
    • Priority: (None)
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Language
    • Labels:
      None

      Description

      CFEngine variables can get ugly. Consider:

      <pre>
      ${mybundle.mydata[${mybundle.i}][command]}
      </pre>

      Now, you can do something like this:

      <pre>
      "p" string => "mybundle";

      ${${p}.mydata[${${p}.i}][command]}
      </pre>

      It's less ugly but not as good as it could be. You can try further attempts, but the results are always mixed. What is needed is a proper reference.

      <pre>
      "command" ref => "${mybundle.mydata[${mybundle.i}][command]}";
      </pre>

      The key here, is that the RHS is not evaluated here. The string is stored as is for later us. So that anytime we call

      <pre>
      ${command}
      </pre>

      then the RHS of the reference is evaluated. This makes our policy easier to read. Consider this:

      <pre>
      "${${d}[${${p}.i}][command]}" -> { "${${d}[${${p}.i}][promisee]}" }
      comment => "Run desired command",
      handle => "efl_command_commands",
      ifvarclass => "${${d}[${${p}.i}][class]}",
      contain => contain_efl_command( "${${d}[${${p}.i}][useshell]}" ),
      module => "${${d}[${${p}.i}][module]}",
      classes => efl_rkn( "${${d}[${${p}.i}][command]}",
      "efl_command_commands" ),
      action => efl_delta_reporting( "efl_command_commands",
      "${${d}[${${p}.i}][command]}", "${${d}[${${p}.i}][promisee]}",
      "${${d}[${${p}.i}][ifelapsed]}"); ';
      </pre>

      Versus this:

      <pre>
      "${command}" -> { "${promisee}" }
      comment => "Run desired command",
      handle => "efl_command_commands",
      ifvarclass => "${class}",
      contain => contain_efl_command( "${useshell}" ),
      module => "${module}",
      classes => efl_rkn( "${command}", "efl_command_commands" ),
      action => efl_delta_reporting( "efl_command_commands",
      "${command}", "${promisee}", "${ifelapsed}"); ';
      </pre>

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                neilhwatson Neil Watson
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated: