module Puppet::Pops::PuppetStack

Utility class for keeping track of the “Puppet stack”, ie the file and line numbers of Puppet Code that created the current context.

To use this make a call with:

“`rb Puppet::Pops::PuppetStack.stack(file, line, receiver, message, args) “`

To get the stack call:

“`rb Puppet::Pops::PuppetStack.stacktrace “`

or

“`rb Puppet::Pops::PuppetStack.top_of_stack “`

To support testing, a given file that is an empty string, or nil as well as a nil line number are supported. Such stack frames will be represented with the text `unknown` and `0´ respectively.

Public Class Methods

stack(file, line, obj, message, args, &block) click to toggle source
   # File lib/puppet/pops/puppet_stack.rb
32 def self.stack(file, line, obj, message, args, &block)
33   file = 'unknown' if (file.nil? || file == '')
34   line = 0 if line.nil?
35 
36   result = nil
37   @stack.value.unshift([file, line])
38   begin
39     if block_given?
40       result = obj.send(message, *args, &block)
41     else
42       result = obj.send(message, *args)
43     end
44   ensure
45     @stack.value.shift()
46   end
47   result
48 end
stacktrace() click to toggle source
   # File lib/puppet/pops/puppet_stack.rb
50 def self.stacktrace
51   @stack.value.dup
52 end
top_of_stack() click to toggle source

Returns an Array with the top of the puppet stack, or an empty Array if there was no such entry.

   # File lib/puppet/pops/puppet_stack.rb
56 def self.top_of_stack
57   @stack.value.first || []
58 end