expression type | example output |
---|---|
literal undef | nil |
literal default | "default" |
literal integer | 1 |
literal float | 3.14 |
literal false | false |
literal true | true |
literal string | "hello" |
literal regexp | "/this|that.*/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$h = { 'b' => ['banana', 'bandana'], 'o' => ['orange', 'ovaltine'] } | |
$h2 = $h.map |$k, $v | { [$k,$v[0]] } | |
notice "h2 = ${h2}" | |
notice Hash($h2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" /> | |
<meta name="generator" content="Railroad Diagram Generator 1.52.1729" /> | |
<style type="text/css"> | |
::-moz-selection | |
{ | |
color: #FFFEF8; | |
background: #1E1800; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Puppet::Functions.create_function(:any2bool) do | |
dispatch :any2bool do | |
param 'Any', :to_be_converted | |
end | |
def any2bool(to_be_converted) | |
call_function('new', Puppet::Pops::Types::PBooleanType::DEFAULT, to_be_converted) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Resolves a given value - if given a Deferred it will be called and all other values are returned as is. | |
# | |
function resolve(Any $x) { | |
if $x =~ Deferred { $x.call } else { $x } | |
} | |
# Resolves and evaluates a condition and either resolves and evaluates the given when_true, | |
# or the given when_false depending on the outcome of the evaluation of the condition. | |
# The result is undef if the selected when_true/when_false is undefined. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StringJoiner joiner = new StringJoiner(","); | |
for (Item item : list) { | |
joiner.add(item.toString()); | |
} | |
return joiner.toString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myjoin(Array $a, String $delimiter) { | |
$formats = { | |
Array => { | |
# no delimiters = '% ', and 'a' means array | |
format => '% a', | |
separator => $delimiter, | |
# format strings without delimiters = '%s' | |
string_formats => { String => '%s' } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mymodule::my_privates ( | |
Variant[String, Numeric] $key, | |
Hash $options, | |
Puppet::LookupContext $context, | |
) { | |
case $key { | |
'mymodule::secret1' : { Sensitive('There is no Santa on the evening coach') } | |
'mymodule::secret2' : { Sensitive('All your base are belong to us') } | |
default: { $context.not_found } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%- | |
$pin = "release a=${name}" # default value | |
if $pin_release.length > 0 | |
$options = [ | |
if $release.length > 0 { "a=${release}" }, | |
if $codename.length > 0 { "n=${codename}" }, | |
if $release_version.length > 0 { "v=${release_version}"}, | |
if $component.length > 0 { "c=${component}" }, | |
if $originator.length > 0 { "o=${originator}" }, | |
if $label.length > 0 { "l=${label}" }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example of local variables set inside of an EPP template | |
# | |
$template = @(EOF) | |
<% | |
# this is an element with arbitrary puppet code | |
$hash = { a => 1, b => 2, c => 3 } | |
-%> | |
The keys are: | |
<%- $hash.each |$key, $value| { -%> |