MMCT TEAM
Server IP : 111.118.215.189  /  Your IP : 18.216.95.250
Web Server : Apache
System : Linux md-in-83.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : a1673wkz ( 2475)
PHP Version : 8.2.25
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/share/ruby/vendor_ruby/puppet/parser/ast/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/share/ruby/vendor_ruby/puppet/parser/ast/function.rb
require 'puppet/parser/ast/branch'

class Puppet::Parser::AST
  # An AST object to call a function.
  class Function < AST::Branch

    associates_doc

    attr_accessor :name, :arguments, :pblock

    def evaluate(scope)
      # Make sure it's a defined function
      raise Puppet::ParseError, "Unknown function #{@name}" unless Puppet::Parser::Functions.function(@name)

      # Now check that it's been used correctly
      case @ftype
      when :rvalue
        raise Puppet::ParseError, "Function '#{@name}' does not return a value" unless Puppet::Parser::Functions.rvalue?(@name)

      when :statement
        # It is harmless to produce an ignored rvalue, the alternative is to mark functions
        # as appropriate for both rvalue and statements
        # Keeping the old behavior when a pblock is not present. This since it is not known
        # if the lambda contains a statement or not (at least not without a costly search).
        # The purpose of the check is to protect a user for producing a meaningless rvalue where the
        # operation has no side effects.
        #
        if !pblock && Puppet::Parser::Functions.rvalue?(@name)
          raise Puppet::ParseError,
            "Function '#{@name}' must be the value of a statement"
        end
      else
        raise Puppet::DevError, "Invalid function type #{@ftype.inspect}"
      end

      # We don't need to evaluate the name, because it's plaintext
      args = @arguments.safeevaluate(scope).map { |x| x == :undef ? '' : x }

      # append a puppet lambda (unevaluated) if it is defined
      args << pblock if pblock

      scope.send("function_#{@name}", args)
    end

    def initialize(hash)
      @ftype = hash[:ftype] || :rvalue
      hash.delete(:ftype) if hash.include? :ftype

      super(hash)

      # Lastly, check the parity
    end

    def to_s
      args = arguments.is_a?(ASTArray) ? arguments.to_s.gsub(/\[(.*)\]/,'\1') : arguments
      "#{name}(#{args})"
    end
  end
end

MMCT - 2023