Module: Puppet::Pops::PuppetStack Private

Defined in:
lib/puppet/pops/puppet_stack.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

will be represented with the text ‘unknown` and `0´ respectively.

Constant Summary collapse

PP_ENTRY_PATTERN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Pattern matching an entry in the ruby stack that is a puppet entry

/^(.*\.pp)?:([0-9]+):in (`stack'|`block in call_function'|`<eval>')/

Class Method Summary collapse

Class Method Details

.stack(file, line, obj, message, args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sends a message to an obj such that it appears to come from file, line when calling stacktrace.



26
27
28
29
30
31
32
33
34
35
# File 'lib/puppet/pops/puppet_stack.rb', line 26

def self.stack(file, line, obj, message, args, &block)
  file = '' if file.nil?
  line = 0 if line.nil?

  if block_given?
    Kernel.eval("obj.send(message, *args, &block)", Kernel.binding(), file, line)
  else
    Kernel.eval("obj.send(message, *args)", Kernel.binding(), file, line)
  end
end

.stacktraceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
40
41
42
43
44
# File 'lib/puppet/pops/puppet_stack.rb', line 37

def self.stacktrace
  caller().reduce([]) do |memo, loc|
    if loc =~ PP_ENTRY_PATTERN
      memo << [$1.nil? ? 'unknown' : $1, $2.to_i]
    end
    memo
  end
end

.top_of_stackObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



48
49
50
51
52
53
54
55
# File 'lib/puppet/pops/puppet_stack.rb', line 48

def self.top_of_stack
  caller.each do |loc|
    if loc =~ PP_ENTRY_PATTERN
      return [$1.nil? ? 'unknown' : $1, $2.to_i]
    end
  end
  []
end