puppet 4.7.1-universal-darwin → 4.8.0-universal-darwin

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (276) hide show
  1. data/Gemfile +0 -3
  2. data/MAINTAINERS +76 -0
  3. data/README.md +0 -6
  4. data/Rakefile +2 -2
  5. data/lib/puppet/agent.rb +3 -3
  6. data/lib/puppet/application/apply.rb +1 -1
  7. data/lib/puppet/configurer.rb +2 -2
  8. data/lib/puppet/data_providers.rb +1 -0
  9. data/lib/puppet/data_providers/data_adapter.rb +1 -0
  10. data/lib/puppet/data_providers/data_function_support.rb +1 -0
  11. data/lib/puppet/data_providers/function_env_data_provider.rb +1 -0
  12. data/lib/puppet/data_providers/function_module_data_provider.rb +1 -0
  13. data/lib/puppet/data_providers/hiera_config.rb +1 -0
  14. data/lib/puppet/data_providers/hiera_env_data_provider.rb +1 -0
  15. data/lib/puppet/data_providers/hiera_interpolate.rb +1 -0
  16. data/lib/puppet/data_providers/hiera_module_data_provider.rb +1 -0
  17. data/lib/puppet/data_providers/hiera_support.rb +1 -2
  18. data/lib/puppet/data_providers/json_data_provider_factory.rb +2 -0
  19. data/lib/puppet/data_providers/yaml_data_provider_factory.rb +2 -0
  20. data/lib/puppet/defaults.rb +20 -1
  21. data/lib/puppet/environments.rb +5 -2
  22. data/lib/puppet/face/catalog.rb +1 -1
  23. data/lib/puppet/face/epp.rb +57 -11
  24. data/lib/puppet/face/module/install.rb +6 -6
  25. data/lib/puppet/functions.rb +23 -24
  26. data/lib/puppet/functions/alert.rb +14 -0
  27. data/lib/puppet/functions/binary_file.rb +25 -0
  28. data/lib/puppet/functions/break.rb +22 -0
  29. data/lib/puppet/functions/contain.rb +33 -0
  30. data/lib/puppet/functions/crit.rb +14 -0
  31. data/lib/puppet/functions/debug.rb +14 -0
  32. data/lib/puppet/functions/emerg.rb +14 -0
  33. data/lib/puppet/functions/epp.rb +1 -1
  34. data/lib/puppet/functions/err.rb +14 -0
  35. data/lib/puppet/functions/find_file.rb +31 -0
  36. data/lib/puppet/functions/include.rb +21 -0
  37. data/lib/puppet/functions/info.rb +14 -0
  38. data/lib/puppet/functions/new.rb +1 -1
  39. data/lib/puppet/functions/next.rb +23 -0
  40. data/lib/puppet/functions/notice.rb +14 -0
  41. data/lib/puppet/functions/regsubst.rb +12 -16
  42. data/lib/puppet/functions/require.rb +37 -0
  43. data/lib/puppet/functions/return.rb +22 -0
  44. data/lib/puppet/functions/strftime.rb +35 -0
  45. data/lib/puppet/functions/warning.rb +14 -0
  46. data/lib/puppet/generate/models/type/type.rb +4 -0
  47. data/lib/puppet/generate/templates/type/pcore.erb +2 -1
  48. data/lib/puppet/indirector/face.rb +6 -1
  49. data/lib/puppet/network/http/error.rb +2 -2
  50. data/lib/puppet/network/http/handler.rb +2 -2
  51. data/lib/puppet/node/environment.rb +11 -0
  52. data/lib/puppet/parser/ast.rb +5 -0
  53. data/lib/puppet/parser/ast/pops_bridge.rb +17 -4
  54. data/lib/puppet/parser/compiler.rb +29 -1
  55. data/lib/puppet/parser/functions.rb +6 -0
  56. data/lib/puppet/parser/functions/assert_type.rb +1 -1
  57. data/lib/puppet/parser/functions/binary_file.rb +24 -0
  58. data/lib/puppet/parser/functions/break.rb +39 -0
  59. data/lib/puppet/parser/functions/contain.rb +7 -15
  60. data/lib/puppet/parser/functions/defined.rb +2 -2
  61. data/lib/puppet/parser/functions/dig.rb +1 -1
  62. data/lib/puppet/parser/functions/each.rb +1 -1
  63. data/lib/puppet/parser/functions/epp.rb +2 -2
  64. data/lib/puppet/parser/functions/filter.rb +1 -1
  65. data/lib/puppet/parser/functions/find_file.rb +28 -0
  66. data/lib/puppet/parser/functions/hiera.rb +4 -4
  67. data/lib/puppet/parser/functions/hiera_array.rb +1 -1
  68. data/lib/puppet/parser/functions/hiera_hash.rb +1 -1
  69. data/lib/puppet/parser/functions/hiera_include.rb +1 -1
  70. data/lib/puppet/parser/functions/include.rb +4 -8
  71. data/lib/puppet/parser/functions/inline_epp.rb +1 -1
  72. data/lib/puppet/parser/functions/lest.rb +1 -1
  73. data/lib/puppet/parser/functions/lookup.rb +4 -2
  74. data/lib/puppet/parser/functions/map.rb +1 -1
  75. data/lib/puppet/parser/functions/match.rb +1 -1
  76. data/lib/puppet/parser/functions/new.rb +414 -18
  77. data/lib/puppet/parser/functions/next.rb +38 -0
  78. data/lib/puppet/parser/functions/reduce.rb +1 -1
  79. data/lib/puppet/parser/functions/regsubst.rb +4 -2
  80. data/lib/puppet/parser/functions/require.rb +4 -27
  81. data/lib/puppet/parser/functions/return.rb +71 -0
  82. data/lib/puppet/parser/functions/reverse_each.rb +1 -1
  83. data/lib/puppet/parser/functions/scanf.rb +13 -8
  84. data/lib/puppet/parser/functions/slice.rb +1 -1
  85. data/lib/puppet/parser/functions/split.rb +1 -1
  86. data/lib/puppet/parser/functions/step.rb +1 -1
  87. data/lib/puppet/parser/functions/strftime.rb +185 -0
  88. data/lib/puppet/parser/functions/then.rb +1 -1
  89. data/lib/puppet/parser/functions/type.rb +1 -1
  90. data/lib/puppet/parser/functions/with.rb +3 -3
  91. data/lib/puppet/parser/resource.rb +8 -5
  92. data/lib/puppet/parser/scope.rb +1 -1
  93. data/lib/puppet/plugins/configuration.rb +8 -0
  94. data/lib/puppet/plugins/data_providers.rb +1 -0
  95. data/lib/puppet/plugins/data_providers/data_provider.rb +7 -28
  96. data/lib/puppet/plugins/data_providers/registry.rb +1 -0
  97. data/lib/puppet/pops.rb +4 -0
  98. data/lib/puppet/pops/evaluator/access_operator.rb +36 -5
  99. data/lib/puppet/pops/evaluator/closure.rb +81 -12
  100. data/lib/puppet/pops/evaluator/compare_operator.rb +24 -1
  101. data/lib/puppet/pops/evaluator/evaluator_impl.rb +29 -5
  102. data/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +1 -1
  103. data/lib/puppet/pops/evaluator/runtime3_converter.rb +53 -62
  104. data/lib/puppet/pops/evaluator/runtime3_support.rb +15 -6
  105. data/lib/puppet/pops/functions/dispatch.rb +9 -2
  106. data/lib/puppet/pops/functions/dispatcher.rb +3 -1
  107. data/lib/puppet/pops/functions/function.rb +19 -2
  108. data/lib/puppet/pops/issues.rb +9 -0
  109. data/lib/puppet/pops/label_provider.rb +2 -2
  110. data/lib/puppet/pops/loader/loader.rb +17 -0
  111. data/lib/puppet/pops/loader/static_loader.rb +0 -41
  112. data/lib/puppet/pops/lookup.rb +12 -0
  113. data/lib/puppet/pops/lookup/context.rb +86 -0
  114. data/lib/puppet/pops/lookup/explainer.rb +46 -6
  115. data/lib/puppet/pops/lookup/invocation.rb +19 -0
  116. data/lib/puppet/pops/lookup/sub_lookup.rb +1 -1
  117. data/lib/puppet/pops/model/factory.rb +20 -8
  118. data/lib/puppet/pops/model/model_label_provider.rb +3 -0
  119. data/lib/puppet/pops/model/model_meta.rb +2 -0
  120. data/lib/puppet/pops/model/model_tree_dumper.rb +14 -0
  121. data/lib/puppet/pops/parser/egrammar.ra +11 -6
  122. data/lib/puppet/pops/parser/eparser.rb +1112 -1086
  123. data/lib/puppet/pops/parser/heredoc_support.rb +1 -2
  124. data/lib/puppet/pops/pcore.rb +1 -0
  125. data/lib/puppet/pops/puppet_stack.rb +3 -3
  126. data/lib/puppet/pops/resource/param.rb +5 -1
  127. data/lib/puppet/pops/resource/resource_type_impl.rb +8 -4
  128. data/lib/puppet/pops/resource/resource_type_set.pcore +1 -0
  129. data/lib/puppet/pops/serialization/abstract_reader.rb +19 -2
  130. data/lib/puppet/pops/serialization/abstract_writer.rb +16 -3
  131. data/lib/puppet/pops/serialization/deserializer.rb +5 -1
  132. data/lib/puppet/pops/serialization/extension.rb +2 -0
  133. data/lib/puppet/pops/serialization/json.rb +76 -26
  134. data/lib/puppet/pops/serialization/serializer.rb +5 -1
  135. data/lib/puppet/pops/serialization/time_factory.rb +2 -1
  136. data/lib/puppet/pops/time/timespan.rb +718 -0
  137. data/lib/puppet/pops/time/timestamp.rb +148 -0
  138. data/lib/puppet/pops/types/p_binary_type.rb +220 -0
  139. data/lib/puppet/pops/types/p_object_type.rb +12 -6
  140. data/lib/puppet/pops/types/p_sensitive_type.rb +5 -1
  141. data/lib/puppet/pops/types/p_timespan_type.rb +141 -0
  142. data/lib/puppet/pops/types/p_timestamp_type.rb +69 -0
  143. data/lib/puppet/pops/types/string_converter.rb +62 -0
  144. data/lib/puppet/pops/types/type_asserter.rb +1 -1
  145. data/lib/puppet/pops/types/type_calculator.rb +17 -3
  146. data/lib/puppet/pops/types/type_factory.rb +35 -1
  147. data/lib/puppet/pops/types/type_formatter.rb +64 -11
  148. data/lib/puppet/pops/types/type_mismatch_describer.rb +110 -61
  149. data/lib/puppet/pops/types/type_parser.rb +18 -4
  150. data/lib/puppet/pops/types/types.rb +98 -63
  151. data/lib/puppet/pops/validation.rb +9 -1
  152. data/lib/puppet/pops/validation/checker4_0.rb +7 -0
  153. data/lib/puppet/property.rb +1 -1
  154. data/lib/puppet/provider.rb +3 -6
  155. data/lib/puppet/provider/mcx/mcxcontent.rb +1 -1
  156. data/lib/puppet/provider/mount/parsed.rb +18 -4
  157. data/lib/puppet/provider/nameservice/directoryservice.rb +15 -7
  158. data/lib/puppet/provider/package/gem.rb +6 -1
  159. data/lib/puppet/provider/package/pip.rb +0 -1
  160. data/lib/puppet/provider/package/pkg.rb +5 -1
  161. data/lib/puppet/provider/package/pkgng.rb +1 -1
  162. data/lib/puppet/provider/package/yum.rb +10 -0
  163. data/lib/puppet/provider/service/launchd.rb +1 -0
  164. data/lib/puppet/provider/user/directoryservice.rb +6 -6
  165. data/lib/puppet/provider/yumrepo/inifile.rb +1 -1
  166. data/lib/puppet/provider/zpool/zpool.rb +1 -1
  167. data/lib/puppet/resource.rb +54 -12
  168. data/lib/puppet/resource/capability_finder.rb +15 -9
  169. data/lib/puppet/resource/catalog.rb +25 -6
  170. data/lib/puppet/resource/type.rb +3 -1
  171. data/lib/puppet/settings.rb +1 -1
  172. data/lib/puppet/settings/environment_conf.rb +12 -4
  173. data/lib/puppet/syntax_checkers/base64.rb +41 -0
  174. data/lib/puppet/syntax_checkers/json.rb +0 -2
  175. data/lib/puppet/transaction.rb +6 -0
  176. data/lib/puppet/transaction/additional_resource_generator.rb +5 -0
  177. data/lib/puppet/transaction/report.rb +7 -2
  178. data/lib/puppet/type.rb +2 -1
  179. data/lib/puppet/type/file/checksum.rb +1 -0
  180. data/lib/puppet/type/file/content.rb +4 -4
  181. data/lib/puppet/type/mount.rb +44 -0
  182. data/lib/puppet/type/ssh_authorized_key.rb +1 -1
  183. data/lib/puppet/type/tidy.rb +3 -0
  184. data/lib/puppet/type/user.rb +12 -6
  185. data/lib/puppet/util/log.rb +25 -0
  186. data/lib/puppet/util/plist.rb +8 -3
  187. data/lib/puppet/version.rb +1 -1
  188. data/lib/puppet_x.rb +7 -1
  189. data/spec/integration/application/apply_spec.rb +118 -0
  190. data/spec/integration/parser/compiler_spec.rb +28 -0
  191. data/spec/integration/parser/pcore_resource_spec.rb +40 -3
  192. data/spec/integration/provider/mount_spec.rb +2 -1
  193. data/spec/integration/util/windows/principal_spec.rb +2 -2
  194. data/spec/integration/util/windows/registry_spec.rb +4 -4
  195. data/spec/lib/puppet_spec/compiler.rb +5 -1
  196. data/spec/lib/puppet_spec/unindent.rb +5 -0
  197. data/spec/shared_contexts/types_setup.rb +6 -0
  198. data/spec/shared_examples/rhel_package_provider.rb +16 -0
  199. data/spec/spec_helper.rb +1 -0
  200. data/spec/unit/agent_spec.rb +11 -0
  201. data/spec/unit/application/lookup_spec.rb +94 -3
  202. data/spec/unit/capability_spec.rb +22 -0
  203. data/spec/unit/configurer_spec.rb +8 -0
  204. data/spec/unit/face/epp_face_spec.rb +22 -3
  205. data/spec/unit/functions/assert_type_spec.rb +3 -3
  206. data/spec/unit/functions/binary_file_spec.rb +46 -0
  207. data/spec/unit/functions/break_spec.rb +89 -0
  208. data/spec/unit/{parser/functions → functions}/contain_spec.rb +68 -3
  209. data/spec/unit/functions/find_file_spec.rb +69 -0
  210. data/spec/unit/functions/include_spec.rb +175 -0
  211. data/spec/unit/functions/logging_spec.rb +54 -0
  212. data/spec/unit/functions/lookup_spec.rb +3 -3
  213. data/spec/unit/functions/new_spec.rb +105 -5
  214. data/spec/unit/functions/next_spec.rb +93 -0
  215. data/spec/unit/functions/require_spec.rb +83 -0
  216. data/spec/unit/functions/return_spec.rb +105 -0
  217. data/spec/unit/{parser/functions → functions}/shared.rb +14 -11
  218. data/spec/unit/functions/strftime_spec.rb +152 -0
  219. data/spec/unit/functions4_spec.rb +22 -0
  220. data/spec/unit/indirector/face_spec.rb +10 -2
  221. data/spec/unit/network/http/error_spec.rb +1 -2
  222. data/spec/unit/network/http/handler_spec.rb +6 -5
  223. data/spec/unit/parser/functions/hiera_array_spec.rb +1 -1
  224. data/spec/unit/parser/functions/hiera_hash_spec.rb +1 -1
  225. data/spec/unit/parser/functions/hiera_include_spec.rb +1 -1
  226. data/spec/unit/parser/functions/hiera_spec.rb +1 -1
  227. data/spec/unit/parser/functions/lookup_spec.rb +1 -1
  228. data/spec/unit/parser/functions/regsubst_spec.rb +1 -1
  229. data/spec/unit/parser/functions/split_spec.rb +1 -1
  230. data/spec/unit/pops/evaluator/access_ops_spec.rb +81 -1
  231. data/spec/unit/pops/evaluator/arithmetic_ops_spec.rb +170 -0
  232. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +29 -4
  233. data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +112 -4
  234. data/spec/unit/pops/loaders/dependency_loader_spec.rb +12 -0
  235. data/spec/unit/pops/loaders/static_loader_spec.rb +0 -26
  236. data/spec/unit/pops/lookup/context_spec.rb +149 -0
  237. data/spec/unit/pops/parser/parse_functions_spec.rb +19 -0
  238. data/spec/unit/pops/parser/parse_lambda_spec.rb +19 -0
  239. data/spec/unit/pops/puppet_stack_spec.rb +1 -1
  240. data/spec/unit/pops/resource/resource_type_impl_spec.rb +74 -0
  241. data/spec/unit/pops/serialization/packer_spec.rb +34 -14
  242. data/spec/unit/pops/serialization/serialization_spec.rb +67 -5
  243. data/spec/unit/pops/time/timespan_spec.rb +121 -0
  244. data/spec/unit/pops/types/p_binary_type_spec.rb +243 -0
  245. data/spec/unit/pops/types/p_object_type_spec.rb +7 -7
  246. data/spec/unit/pops/types/p_sensitive_type_spec.rb +1 -1
  247. data/spec/unit/pops/types/p_timespan_type_spec.rb +273 -0
  248. data/spec/unit/pops/types/p_timestamp_type_spec.rb +311 -0
  249. data/spec/unit/pops/types/p_type_set_type_spec.rb +13 -13
  250. data/spec/unit/pops/types/ruby_generator_spec.rb +12 -12
  251. data/spec/unit/pops/types/string_converter_spec.rb +89 -0
  252. data/spec/unit/pops/types/type_asserter_spec.rb +3 -3
  253. data/spec/unit/pops/types/type_calculator_spec.rb +113 -5
  254. data/spec/unit/pops/types/type_formatter_spec.rb +40 -0
  255. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +49 -38
  256. data/spec/unit/pops/types/type_parser_spec.rb +87 -4
  257. data/spec/unit/pops/types/types_spec.rb +1 -1
  258. data/spec/unit/pops/validator/validator_spec.rb +23 -0
  259. data/spec/unit/provider/mount/parsed_spec.rb +47 -29
  260. data/spec/unit/provider/package/pkg_spec.rb +109 -99
  261. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +1 -0
  262. data/spec/unit/provider/user/aix_spec.rb +1 -1
  263. data/spec/unit/provider/user/directoryservice_spec.rb +101 -30
  264. data/spec/unit/resource/capability_finder_spec.rb +29 -7
  265. data/spec/unit/resource/catalog_spec.rb +127 -0
  266. data/spec/unit/ssl/certificate_request_spec.rb +1 -1
  267. data/spec/unit/transaction/additional_resource_generator_spec.rb +30 -0
  268. data/spec/unit/transaction/persistence_spec.rb +1 -6
  269. data/spec/unit/transaction/report_spec.rb +23 -0
  270. data/spec/unit/transaction_spec.rb +38 -0
  271. data/spec/unit/type/mount_spec.rb +5 -0
  272. data/spec/unit/util/plist_spec.rb +14 -2
  273. metadata +71 -12
  274. data/spec/integration/parser/functions/require_spec.rb +0 -43
  275. data/spec/unit/parser/functions/include_spec.rb +0 -55
  276. data/spec/unit/parser/functions/require_spec.rb +0 -68
@@ -0,0 +1,38 @@
1
+ Puppet::Parser::Functions::newfunction(
2
+ :next,
3
+ :arity => -2,
4
+ :doc => <<-DOC
5
+ Immediately returns the given optional value from a block (lambda), function, class body or user defined type body.
6
+ If a value is not given, an `undef` value is returned. This function does not return to the immediate caller.
7
+
8
+ The signal produced to return a value bubbles up through
9
+ the call stack until reaching a code block (lambda), function, class definition or
10
+ definition of a user defined type at which point the value given to the function will
11
+ be produced as the result of that body of code. An error is raised
12
+ if the signal to return a value reaches the end of the call stack.
13
+
14
+ **Example:** Using `next` in `each`
15
+
16
+ ```puppet
17
+ $data = [1,2,3]
18
+ $data.each |$x| { if $x == 2 { next() } notice $x }
19
+ ```
20
+
21
+ Would notice the values `1` and `3`
22
+
23
+ **Example:** Using `next` to produce a value
24
+
25
+ If logic consists of deeply nested conditionals it may be complicated to get out of the innermost conditional.
26
+ A call to `next` can then simplify the logic. This example however, only shows the principle.
27
+ ```puppet
28
+ $data = [1,2,3]
29
+ notice $data.map |$x| { if $x == 2 { next($x*100) }; $x*10 }
30
+ ```
31
+ Would notice the value `[10, 200, 30]`
32
+
33
+ * Also see functions `return` and `break`
34
+ * Since 4.8.0
35
+ DOC
36
+ ) do |args|
37
+ Error.is4x('next')
38
+ end
@@ -102,5 +102,5 @@ $combine = $data.reduce( [d, 4] ) |$memo, $value| {
102
102
  - Since 4.0.0
103
103
  DOC
104
104
  ) do |args|
105
- function_fail(["reduce() is only available when parser/evaluator future is in effect"])
105
+ Error.is4x('reduce')
106
106
  end
@@ -24,7 +24,8 @@
24
24
  # other dealings in this Software without prior written authorization
25
25
  # from Thomas Bellman.
26
26
 
27
- Puppet::Parser::Functions::newfunction(
27
+ module Puppet::Parser::Functions
28
+ newfunction(
28
29
  :regsubst, :type => :rvalue,
29
30
  :arity => -4,
30
31
 
@@ -56,5 +57,6 @@ Put angle brackets around each octet in the node's IP address:
56
57
 
57
58
  $x = regsubst($ipaddress, '([0-9]+)', '<\\1>', 'G')
58
59
  ") do |args|
59
- function_fail(['regsubst() has been converted to 4x API'])
60
+ Error.is4x('regsubst')
61
+ end
60
62
  end
@@ -33,31 +33,8 @@ you may also directly use Class and Resource Type values that are produced when
33
33
  resource and relationship expressions.
34
34
 
35
35
  - Since 4.0.0 Class and Resource types, absolute names
36
- ") do |vals|
37
- # Make call patterns uniform and protected against nested arrays, also make
38
- # names absolute if so desired.
39
- vals = transform_and_assert_classnames(vals.is_a?(Array) ? vals.flatten : [vals])
40
-
41
- # This is the same as calling the include function (but faster) since it again
42
- # would otherwise need to perform the optional absolute name transformation
43
- # (for no reason since they are already made absolute here).
44
- #
45
- compiler.evaluate_classes(vals, self, false)
46
-
47
- vals.each do |klass|
48
- # lookup the class in the scopes
49
- if classobj = environment.known_resource_types.find_hostclass(klass)
50
- klass = classobj.name
51
- else
52
- raise Puppet::ParseError, "Could not find class #{klass}"
53
- end
54
-
55
- # This is a bit hackish, in some ways, but it's the only way
56
- # to configure a dependency that will make it to the client.
57
- # The 'obvious' way is just to add an edge in the catalog,
58
- # but that is considered a containment edge, not a dependency
59
- # edge, so it usually gets lost on the client.
60
- ref = Puppet::Resource.new(:class, klass)
61
- resource.set_parameter(:require, [resource[:require]].flatten.compact << ref)
62
- end
36
+ - Since 4.7.0 Returns an Array[Type[Class]] with references to the required classes
37
+ ") do |classes|
38
+ Puppet.warn_once(:deprecation, '3xfunction#require', "Calling function_require via the Scope class is deprecated. Use Scope#call_function instead")
39
+ call_function('require', classes)
63
40
  end
@@ -0,0 +1,71 @@
1
+ Puppet::Parser::Functions::newfunction(
2
+ :return,
3
+ :arity => -2,
4
+ :doc => <<-DOC
5
+ Immediately returns the given optional value from a function, class body or user defined type body.
6
+ If a value is not given, an `undef` value is returned. This function does not return to the immediate caller.
7
+ If called from within a lambda the return will return from the function evaluating the lambda.
8
+
9
+ The signal produced to return a value bubbles up through
10
+ the call stack until reaching a function, class definition or
11
+ definition of a user defined type at which point the value given to the function will
12
+ be produced as the result of that body of code. An error is raised
13
+ if the signal to return a value reaches the end of the call stack.
14
+
15
+ **Example:** Using `return`
16
+
17
+ ```puppet
18
+ function example($x) {
19
+ # handle trivial cases first for better readability of
20
+ # what follows
21
+ if $x == undef or $x == [] or $x == '' {
22
+ return false
23
+ }
24
+ # complex logic to determine if value is true
25
+ true
26
+ }
27
+ notice example([]) # would notice false
28
+ notice example(42) # would notice true
29
+ ```
30
+
31
+ **Example:** Using `return` in a class
32
+
33
+ ```puppet
34
+ class example($x) {
35
+ # handle trivial cases first for better readability of
36
+ # what follows
37
+ if $x == undef or $x == [] or $x == '' {
38
+ # Do some default configuration of this class
39
+ notice 'foo'
40
+ return()
41
+ }
42
+ # complex logic configuring the class if something more interesting
43
+ # was given in $x
44
+ notice 'bar'
45
+ }
46
+ ```
47
+
48
+ When used like this:
49
+
50
+ ```puppet
51
+ class { example: x => [] }
52
+ ```
53
+
54
+ The code would notice `'foo'`, but not `'bar'`.
55
+
56
+ When used like this:
57
+
58
+ ```puppet
59
+ class { example: x => [some_value] }
60
+ ```
61
+
62
+ The code would notice `'bar'` but not `'foo'`
63
+
64
+ Note that the returned value is ignored if used in a class or user defined type.
65
+
66
+ * Also see functions `return` and `break`
67
+ * Since 4.8.0
68
+ DOC
69
+ ) do |args|
70
+ Error.is4x('return')
71
+ end
@@ -79,5 +79,5 @@ $transformed_data = map(reverse_each($data)) |$item| { $item * 10 }
79
79
 
80
80
  DOC
81
81
  ) do |args|
82
- function_fail(["reverse_each() is only available when parser/evaluator future is in effect"])
82
+ Error.is4x('reverse_each')
83
83
  end
@@ -14,17 +14,22 @@ the format string. The result of the scan is an array, with each successfully sc
14
14
  The scanning stops if a scan is unsuccessful, and the scanned result up to that point is returned. If there
15
15
  was no successful scan, the result is an empty array.
16
16
 
17
- "42".scanf("%i")
17
+ ```puppet
18
+ "42".scanf("%i")
19
+ ```
18
20
 
19
21
  You can also optionally pass a lambda to scanf, to do additional validation or processing.
20
22
 
21
- "42".scanf("%i") |$x| {
22
- unless $x[0] =~ Integer {
23
- fail "Expected a well formed integer value, got '$x[0]'"
24
- }
25
- $x[0]
26
- }
27
- - since 4.0.0
23
+ ```puppet
24
+ "42".scanf("%i") |$x| {
25
+ unless $x[0] =~ Integer {
26
+ fail "Expected a well formed integer value, got '$x[0]'"
27
+ }
28
+ $x[0]
29
+ }
30
+ ```
31
+
32
+ - Since 4.0.0
28
33
  DOC
29
34
  ) do |args|
30
35
  data = args[0]
@@ -35,5 +35,5 @@ to empty arrays for a hash.
35
35
  - Since 4.0.0
36
36
  DOC
37
37
  ) do |args|
38
- function_fail(["slice() is only available when parser/evaluator future is in effect"])
38
+ Error.is4x('slice')
39
39
  end
@@ -23,6 +23,6 @@ a regexp meta-character (.), which must be escaped. A simple
23
23
  way to do that for a single character is to enclose it in square
24
24
  brackets; a backslash will also escape a single character.") do |args|
25
25
 
26
- function_fail(['split() has been converted to 4x API'])
26
+ Error.is4x('split')
27
27
  end
28
28
  end
@@ -80,5 +80,5 @@ $transformed_data contains [0,50,100,150,200]
80
80
 
81
81
  DOC
82
82
  ) do |args|
83
- function_fail(["step() is only available when parser/evaluator future is in effect"])
83
+ Error.is4x('step')
84
84
  end
@@ -0,0 +1,185 @@
1
+ Puppet::Parser::Functions::newfunction(
2
+ :strftime,
3
+ :type => :rvalue,
4
+ :arity => -3,
5
+ :doc => <<DOC
6
+ Formats timestamp or timespan according to the directives in the given format string. The directives begins with a percent (%) character.
7
+ Any text not listed as a directive will be passed through to the output string.
8
+
9
+ A third optional timezone argument can be provided. The first argument will then be formatted to represent a local time in that
10
+ timezone. The timezone can be any timezone that is recognized when using the '%z' or '%Z' formats, or the word 'current', in which
11
+ case the current timezone of the evaluating process will be used. The timezone argument is case insensitive.
12
+
13
+ The default timezone, when no argument is provided, or when using the keyword `default`, is 'UTC'.
14
+
15
+ The directive consists of a percent (%) character, zero or more flags, optional minimum field width and
16
+ a conversion specifier as follows:
17
+ ```
18
+ %[Flags][Width]Conversion
19
+ ```
20
+
21
+ ### Flags that controls padding
22
+
23
+ | Flag | Meaning
24
+ | ---- | ---------------
25
+ | - | Don't pad numerical output
26
+ | _ | Use spaces for padding
27
+ | 0 | Use zeros for padding
28
+
29
+ ### `Timestamp` specific flags
30
+
31
+ | Flag | Meaning
32
+ | ---- | ---------------
33
+ | # | Change case
34
+ | ^ | Use uppercase
35
+ | : | Use colons for %z
36
+
37
+ ### Format directives applicable to `Timestamp` (names and padding can be altered using flags):
38
+
39
+ **Date (Year, Month, Day):**
40
+
41
+ | Format | Meaning |
42
+ | ------ | ------- |
43
+ | Y | Year with century, zero-padded to at least 4 digits |
44
+ | C | year / 100 (rounded down such as 20 in 2009) |
45
+ | y | year % 100 (00..99) |
46
+ | m | Month of the year, zero-padded (01..12) |
47
+ | B | The full month name ("January") |
48
+ | b | The abbreviated month name ("Jan") |
49
+ | h | Equivalent to %b |
50
+ | d | Day of the month, zero-padded (01..31) |
51
+ | e | Day of the month, blank-padded ( 1..31) |
52
+ | j | Day of the year (001..366) |
53
+
54
+ **Time (Hour, Minute, Second, Subsecond):**
55
+
56
+ | Format | Meaning |
57
+ | ------ | ------- |
58
+ | H | Hour of the day, 24-hour clock, zero-padded (00..23) |
59
+ | k | Hour of the day, 24-hour clock, blank-padded ( 0..23) |
60
+ | I | Hour of the day, 12-hour clock, zero-padded (01..12) |
61
+ | l | Hour of the day, 12-hour clock, blank-padded ( 1..12) |
62
+ | P | Meridian indicator, lowercase ("am" or "pm") |
63
+ | p | Meridian indicator, uppercase ("AM" or "PM") |
64
+ | M | Minute of the hour (00..59) |
65
+ | S | Second of the minute (00..60) |
66
+ | L | Millisecond of the second (000..999). Digits under millisecond are truncated to not produce 1000 |
67
+ | N | Fractional seconds digits, default is 9 digits (nanosecond). Digits under a specified width are truncated to avoid carry up |
68
+
69
+ **Time (Hour, Minute, Second, Subsecond):**
70
+
71
+ | Format | Meaning |
72
+ | ------ | ------- |
73
+ | z | Time zone as hour and minute offset from UTC (e.g. +0900) |
74
+ | :z | hour and minute offset from UTC with a colon (e.g. +09:00) |
75
+ | ::z | hour, minute and second offset from UTC (e.g. +09:00:00) |
76
+ | Z | Abbreviated time zone name or similar information. (OS dependent) |
77
+
78
+ **Weekday:**
79
+
80
+ | Format | Meaning |
81
+ | ------ | ------- |
82
+ | A | The full weekday name ("Sunday") |
83
+ | a | The abbreviated name ("Sun") |
84
+ | u | Day of the week (Monday is 1, 1..7) |
85
+ | w | Day of the week (Sunday is 0, 0..6) |
86
+
87
+ **ISO 8601 week-based year and week number:**
88
+
89
+ The first week of YYYY starts with a Monday and includes YYYY-01-04.
90
+ The days in the year before the first week are in the last week of
91
+ the previous year.
92
+
93
+ | Format | Meaning |
94
+ | ------ | ------- |
95
+ | G | The week-based year |
96
+ | g | The last 2 digits of the week-based year (00..99) |
97
+ | V | Week number of the week-based year (01..53) |
98
+
99
+ **Week number:**
100
+
101
+ The first week of YYYY that starts with a Sunday or Monday (according to %U
102
+ or %W). The days in the year before the first week are in week 0.
103
+
104
+ | Format | Meaning |
105
+ | ------ | ------- |
106
+ | U | Week number of the year. The week starts with Sunday. (00..53) |
107
+ | W | Week number of the year. The week starts with Monday. (00..53) |
108
+
109
+ **Seconds since the Epoch:**
110
+
111
+ | Format | Meaning |
112
+ | s | Number of seconds since 1970-01-01 00:00:00 UTC. |
113
+
114
+ **Literal string:**
115
+
116
+ | Format | Meaning |
117
+ | ------ | ------- |
118
+ | n | Newline character (\n) |
119
+ | t | Tab character (\t) |
120
+ | % | Literal "%" character |
121
+
122
+ **Combination:**
123
+
124
+ | Format | Meaning |
125
+ | ------ | ------- |
126
+ | c | date and time (%a %b %e %T %Y) |
127
+ | D | Date (%m/%d/%y) |
128
+ | F | The ISO 8601 date format (%Y-%m-%d) |
129
+ | v | VMS date (%e-%^b-%4Y) |
130
+ | x | Same as %D |
131
+ | X | Same as %T |
132
+ | r | 12-hour time (%I:%M:%S %p) |
133
+ | R | 24-hour time (%H:%M) |
134
+ | T | 24-hour time (%H:%M:%S) |
135
+
136
+ **Example**: Using `strftime` with a `Timestamp`:
137
+
138
+ ~~~ puppet
139
+ $timestamp = Timestamp('2016-08-24T12:13:14')
140
+
141
+ # Notice the timestamp using a format that notices the ISO 8601 date format
142
+ notice($timestamp.strftime('%F')) # outputs '2016-08-24'
143
+
144
+ # Notice the timestamp using a format that notices weekday, month, day, time (as UTC), and year
145
+ notice($timestamp.strftime('%c')) # outputs 'Wed Aug 24 12:13:14 2016'
146
+
147
+ # Notice the timestamp using a specific timezone
148
+ notice($timestamp.strftime('%F %T %z', 'PST')) # outputs '2016-08-24 04:13:14 -0800'
149
+
150
+ # Notice the timestamp using timezone that is current for the evaluating process
151
+ notice($timestamp.strftime('%F %T', 'current')) # outputs the timestamp using the timezone for the current process
152
+ ~~~
153
+
154
+ ### Format directives applicable to `Timespan`:
155
+
156
+ | Format | Meaning |
157
+ | ------ | ------- |
158
+ | D | Number of Days |
159
+ | H | Hour of the day, 24-hour clock |
160
+ | M | Minute of the hour (00..59) |
161
+ | S | Second of the minute (00..59) |
162
+ | L | Millisecond of the second (000..999). Digits under millisecond are truncated to not produce 1000. |
163
+ | N | Fractional seconds digits, default is 9 digits (nanosecond). Digits under a specified length are truncated to avoid carry up |
164
+
165
+ The format directive that represents the highest magnitude in the format will be allowed to overflow.
166
+ I.e. if no "%D" is used but a "%H" is present, then the hours will be more than 23 in case the
167
+ timespan reflects more than a day.
168
+
169
+ **Example**: Using `strftime` with a Timespan and a format
170
+
171
+ ~~~ puppet
172
+ $duration = Timespan({ hours => 3, minutes => 20, seconds => 30 })
173
+
174
+ # Notice the duration using a format that outputs <hours>:<minutes>:<seconds>
175
+ notice($duration.strftime('%H:%M:%S')) # outputs '03:20:30'
176
+
177
+ # Notice the duration using a format that outputs <minutes>:<seconds>
178
+ notice($duration.strftime('%M:%S')) # outputs '200:30'
179
+ ~~~
180
+
181
+ - Since 4.8.0
182
+ DOC
183
+ ) do |args|
184
+ Error.is4x('strftime')
185
+ end
@@ -69,5 +69,5 @@ was not a String.
69
69
 
70
70
  DOC
71
71
  ) do |args|
72
- function_fail(["then() is only available when parser/evaluator future is in effect"])
72
+ Error.is4x('then')
73
73
  end
@@ -49,5 +49,5 @@ function type(Any $value, InferenceFidelity $fidelity = 'detailed') # returns Ty
49
49
 
50
50
  DOC
51
51
  ) do |args|
52
- function_fail(["type() is only available when parser/evaluator future is in effect"])
52
+ Error.is4x('type')
53
53
  end
@@ -13,8 +13,8 @@ class using variables whose values cannot be accessed outside of the lambda.
13
13
 
14
14
  ~~~ puppet
15
15
  # Concatenate three strings into a single string formatted as a list.
16
- $fruit = with("apples", "oranges", "bananas") |$x, $y, $z| {
17
- "${x}, ${y}, and ${z}"
16
+ $fruit = with("apples", "oranges", "bananas") |$x, $y, $z| {
17
+ "${x}, ${y}, and ${z}"
18
18
  }
19
19
  $check_var = $x
20
20
  # $fruit contains "apples, oranges, and bananas"
@@ -24,5 +24,5 @@ $check_var = $x
24
24
  - Since 4.0.0
25
25
  DOC
26
26
  ) do |args|
27
- function_fail(["with() is only available when parser/evaluator future is in effect"])
27
+ Error.is4x('with')
28
28
  end