summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/vardef.rb
blob: 1e7f874bc76a87115ebce19ac92c7d9713cfdf19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'puppet/parser/ast/branch'

class Puppet::Parser::AST
    # Define a variable.  Stores the value in the current scope.
    class VarDef < AST::Branch
        attr_accessor :name, :value

        @settor = true

        # Look up our name and value, and store them appropriately.  The
        # lexer strips off the syntax stuff like '$'.
        def evaluate(hash)
            scope = hash[:scope]
            name = @name.safeevaluate(:scope => scope)
            value = @value.safeevaluate(:scope => scope)

            parsewrap do
                scope.setvar(name,value, @file, @line)
            end
        end

        def each
            [@name,@value].each { |child| yield child }
        end
    end

end