~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to lib/puppet/parser/templatewrapper.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-07-25 01:00:37 UTC
  • mfrom: (1.1.24 upstream) (3.1.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110725010037-875vuxs10eboqgw3
Tags: 2.7.1-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/puppetmaster-passenger.postinst: Use cacrl instead of hostcrl to
    set the location of the CRL in apache2 configuration. Fix apache2
    configuration on upgrade as well (LP: #641001)
  - move all puppet dependencies to puppet-common since all the code
    actually located in puppet-common.
  - move libagueas from a recommend to a dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
    @__scope__
19
19
  end
20
20
 
 
21
  def script_line
 
22
    # find which line in the template (if any) we were called from
 
23
    (caller.find { |l| l =~ /#{file}:/ }||"")[/:(\d+):/,1]
 
24
  end
 
25
 
21
26
  # Should return true if a variable is defined, false if it is not
22
27
  def has_variable?(name)
23
 
    if scope.lookupvar(name.to_s, false) != :undefined
24
 
      true
25
 
    else
26
 
      false
27
 
    end
 
28
    scope.lookupvar(name.to_s, :file => file, :line => script_line) != :undefined
28
29
  end
29
30
 
30
31
  # Allow templates to access the defined classes
55
56
  # the missing_method definition here until we declare the syntax finally
56
57
  # dead.
57
58
  def method_missing(name, *args)
58
 
    # We have to tell lookupvar to return :undefined to us when
59
 
    # appropriate; otherwise it converts to "".
60
 
    value = scope.lookupvar(name.to_s, false)
 
59
    value = scope.lookupvar(name.to_s,:file => file,:line => script_line)
61
60
    if value != :undefined
62
61
      return value
63
62
    else
64
63
      # Just throw an error immediately, instead of searching for
65
64
      # other missingmethod things or whatever.
66
 
      raise Puppet::ParseError, "Could not find value for '#{name}'"
 
65
      raise Puppet::ParseError.new("Could not find value for '#{name}'",@file,script_line)
67
66
    end
68
67
  end
69
68
 
103
102
    result = nil
104
103
    benchmark(:debug, "Interpolated template #{template_source}") do
105
104
      template = ERB.new(self.string, 0, "-")
 
105
      template.filename = file
106
106
      result = template.result(binding)
107
107
    end
108
108