puppet 5.4.0-x86-mingw32 → 5.5.0-x86-mingw32

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 (441) hide show
  1. data/Gemfile +3 -3
  2. data/MAINTAINERS +0 -19
  3. data/README.md +5 -5
  4. data/Rakefile +26 -0
  5. data/conf/auth.conf +5 -0
  6. data/ext/project_data.yaml +1 -0
  7. data/ext/regexp_nodes/regexp_nodes.rb +3 -4
  8. data/lib/puppet/application/apply.rb +1 -1
  9. data/lib/puppet/application/cert.rb +3 -1
  10. data/lib/puppet/application/device.rb +100 -13
  11. data/lib/puppet/application/facts.rb +5 -0
  12. data/lib/puppet/application/lookup.rb +12 -2
  13. data/lib/puppet/configurer.rb +37 -17
  14. data/lib/puppet/confine.rb +4 -1
  15. data/lib/puppet/datatypes.rb +1 -1
  16. data/lib/puppet/environments.rb +1 -1
  17. data/lib/puppet/error.rb +6 -3
  18. data/lib/puppet/external/dot.rb +0 -7
  19. data/lib/puppet/external/nagios/parser.rb +1 -1
  20. data/lib/puppet/face/config.rb +92 -10
  21. data/lib/puppet/face/epp.rb +31 -6
  22. data/lib/puppet/face/facts.rb +49 -0
  23. data/lib/puppet/face/help.rb +33 -35
  24. data/lib/puppet/face/help/action.erb +1 -1
  25. data/lib/puppet/face/help/face.erb +1 -1
  26. data/lib/puppet/face/man.rb +55 -12
  27. data/lib/puppet/face/parser.rb +30 -3
  28. data/lib/puppet/file_bucket/file.rb +0 -2
  29. data/lib/puppet/file_serving/base.rb +10 -10
  30. data/lib/puppet/forge.rb +3 -3
  31. data/lib/puppet/forge/errors.rb +3 -3
  32. data/lib/puppet/functions.rb +1 -3
  33. data/lib/puppet/functions/alert.rb +1 -1
  34. data/lib/puppet/functions/all.rb +6 -6
  35. data/lib/puppet/functions/annotate.rb +10 -10
  36. data/lib/puppet/functions/any.rb +6 -6
  37. data/lib/puppet/functions/assert_type.rb +4 -4
  38. data/lib/puppet/functions/binary_file.rb +14 -2
  39. data/lib/puppet/functions/break.rb +31 -2
  40. data/lib/puppet/functions/call.rb +4 -4
  41. data/lib/puppet/functions/contain.rb +19 -3
  42. data/lib/puppet/functions/convert_to.rb +6 -5
  43. data/lib/puppet/functions/crit.rb +1 -1
  44. data/lib/puppet/functions/debug.rb +1 -1
  45. data/lib/puppet/functions/defined.rb +11 -9
  46. data/lib/puppet/functions/dig.rb +26 -2
  47. data/lib/puppet/functions/each.rb +8 -8
  48. data/lib/puppet/functions/emerg.rb +1 -1
  49. data/lib/puppet/functions/empty.rb +79 -0
  50. data/lib/puppet/functions/err.rb +1 -1
  51. data/lib/puppet/functions/eyaml_lookup_key.rb +3 -1
  52. data/lib/puppet/functions/filter.rb +7 -7
  53. data/lib/puppet/functions/find_file.rb +15 -1
  54. data/lib/puppet/functions/flatten.rb +64 -0
  55. data/lib/puppet/functions/hiera.rb +6 -6
  56. data/lib/puppet/functions/hiera_array.rb +6 -6
  57. data/lib/puppet/functions/hiera_hash.rb +6 -6
  58. data/lib/puppet/functions/hiera_include.rb +8 -8
  59. data/lib/puppet/functions/include.rb +28 -2
  60. data/lib/puppet/functions/info.rb +1 -1
  61. data/lib/puppet/functions/inline_epp.rb +2 -2
  62. data/lib/puppet/functions/join.rb +56 -0
  63. data/lib/puppet/functions/json_data.rb +2 -2
  64. data/lib/puppet/functions/keys.rb +25 -0
  65. data/lib/puppet/functions/length.rb +44 -0
  66. data/lib/puppet/functions/lest.rb +39 -1
  67. data/lib/puppet/functions/lookup.rb +2 -1
  68. data/lib/puppet/functions/map.rb +10 -9
  69. data/lib/puppet/functions/match.rb +6 -6
  70. data/lib/puppet/functions/new.rb +995 -2
  71. data/lib/puppet/functions/next.rb +1 -1
  72. data/lib/puppet/functions/notice.rb +1 -1
  73. data/lib/puppet/functions/reduce.rb +6 -6
  74. data/lib/puppet/functions/regsubst.rb +9 -3
  75. data/lib/puppet/functions/require.rb +36 -2
  76. data/lib/puppet/functions/return.rb +1 -1
  77. data/lib/puppet/functions/reverse_each.rb +71 -2
  78. data/lib/puppet/functions/slice.rb +23 -9
  79. data/lib/puppet/functions/split.rb +12 -10
  80. data/lib/puppet/functions/step.rb +73 -1
  81. data/lib/puppet/functions/strftime.rb +176 -2
  82. data/lib/puppet/functions/then.rb +65 -2
  83. data/lib/puppet/functions/tree_each.rb +19 -19
  84. data/lib/puppet/functions/type.rb +42 -1
  85. data/lib/puppet/functions/unique.rb +13 -13
  86. data/lib/puppet/functions/unwrap.rb +8 -4
  87. data/lib/puppet/functions/values.rb +25 -0
  88. data/lib/puppet/functions/versioncmp.rb +1 -1
  89. data/lib/puppet/functions/warning.rb +1 -1
  90. data/lib/puppet/functions/with.rb +6 -4
  91. data/lib/puppet/functions/yaml_data.rb +3 -1
  92. data/lib/puppet/indirector/certificate_status/file.rb +1 -1
  93. data/lib/puppet/indirector/facts/facter.rb +1 -3
  94. data/lib/puppet/indirector/facts/rest.rb +21 -0
  95. data/lib/puppet/indirector/facts/yaml.rb +0 -4
  96. data/lib/puppet/indirector/rest.rb +2 -2
  97. data/lib/puppet/module.rb +3 -3
  98. data/lib/puppet/module/task.rb +2 -3
  99. data/lib/puppet/module_tool/applications/application.rb +4 -4
  100. data/lib/puppet/module_tool/applications/builder.rb +2 -2
  101. data/lib/puppet/module_tool/applications/checksummer.rb +3 -3
  102. data/lib/puppet/module_tool/applications/unpacker.rb +2 -2
  103. data/lib/puppet/module_tool/metadata.rb +3 -3
  104. data/lib/puppet/network/authconfig.rb +1 -1
  105. data/lib/puppet/network/format_support.rb +1 -1
  106. data/lib/puppet/network/formats.rb +5 -7
  107. data/lib/puppet/network/http/api/indirected_routes.rb +1 -0
  108. data/lib/puppet/network/http/api/master/v3/environment.rb +2 -2
  109. data/lib/puppet/network/http/api/master/v3/environments.rb +2 -2
  110. data/lib/puppet/network/http/error.rb +3 -3
  111. data/lib/puppet/network/resolver.rb +1 -2
  112. data/lib/puppet/parser/compiler.rb +12 -5
  113. data/lib/puppet/parser/compiler/catalog_validator/env_relationship_validator.rb +1 -1
  114. data/lib/puppet/parser/functions/fqdn_rand.rb +15 -4
  115. data/lib/puppet/parser/functions/new.rb +31 -46
  116. data/lib/puppet/parser/parser_factory.rb +1 -1
  117. data/lib/puppet/parser/resource.rb +1 -1
  118. data/lib/puppet/parser/type_loader.rb +11 -11
  119. data/lib/puppet/pops/evaluator/closure.rb +1 -1
  120. data/lib/puppet/pops/evaluator/collector_transformer.rb +1 -1
  121. data/lib/puppet/pops/evaluator/epp_evaluator.rb +2 -2
  122. data/lib/puppet/pops/evaluator/runtime3_resource_support.rb +2 -2
  123. data/lib/puppet/pops/evaluator/runtime3_support.rb +5 -2
  124. data/lib/puppet/pops/functions/dispatch.rb +1 -1
  125. data/lib/puppet/pops/issue_reporter.rb +18 -1
  126. data/lib/puppet/pops/issues.rb +6 -3
  127. data/lib/puppet/pops/loader/ruby_data_type_instantiator.rb +1 -2
  128. data/lib/puppet/pops/loader/ruby_function_instantiator.rb +1 -2
  129. data/lib/puppet/pops/loader/task_instantiator.rb +5 -5
  130. data/lib/puppet/pops/loader/type_definition_instantiator.rb +4 -1
  131. data/lib/puppet/pops/loaders.rb +18 -7
  132. data/lib/puppet/pops/lookup/global_data_provider.rb +1 -1
  133. data/lib/puppet/pops/lookup/lookup_adapter.rb +55 -6
  134. data/lib/puppet/pops/model/factory.rb +6 -3
  135. data/lib/puppet/pops/model/model_tree_dumper.rb +4 -0
  136. data/lib/puppet/pops/model/pn_transformer.rb +400 -0
  137. data/lib/puppet/pops/parser/egrammar.ra +1 -1
  138. data/lib/puppet/pops/parser/eparser.rb +1 -1
  139. data/lib/puppet/pops/parser/heredoc_support.rb +1 -1
  140. data/lib/puppet/pops/parser/lexer_support.rb +3 -2
  141. data/lib/puppet/pops/parser/locator.rb +0 -2
  142. data/lib/puppet/pops/parser/pn_parser.rb +316 -0
  143. data/lib/puppet/pops/pcore.rb +17 -17
  144. data/lib/puppet/pops/pn.rb +236 -0
  145. data/lib/puppet/pops/serialization/json.rb +7 -7
  146. data/lib/puppet/pops/types/class_loader.rb +6 -3
  147. data/lib/puppet/pops/types/implementation_registry.rb +28 -35
  148. data/lib/puppet/pops/types/p_object_type.rb +3 -3
  149. data/lib/puppet/pops/types/p_timespan_type.rb +2 -2
  150. data/lib/puppet/pops/types/p_type_set_type.rb +24 -1
  151. data/lib/puppet/pops/types/ruby_generator.rb +3 -4
  152. data/lib/puppet/pops/types/type_calculator.rb +1 -1
  153. data/lib/puppet/pops/types/type_factory.rb +0 -4
  154. data/lib/puppet/pops/types/type_mismatch_describer.rb +1 -1
  155. data/lib/puppet/pops/types/type_parser.rb +14 -7
  156. data/lib/puppet/pops/types/types.rb +1 -1
  157. data/lib/puppet/pops/utils.rb +2 -2
  158. data/lib/puppet/pops/validation/checker4_0.rb +6 -2
  159. data/lib/puppet/provider/group/groupadd.rb +3 -1
  160. data/lib/puppet/provider/group/windows_adsi.rb +4 -7
  161. data/lib/puppet/provider/nameservice.rb +3 -3
  162. data/lib/puppet/provider/package/pacman.rb +4 -4
  163. data/lib/puppet/provider/package/pip.rb +3 -3
  164. data/lib/puppet/provider/package/pkgdmg.rb +3 -3
  165. data/lib/puppet/provider/package/pkgutil.rb +2 -2
  166. data/lib/puppet/provider/package/portage.rb +9 -9
  167. data/lib/puppet/provider/package/zypper.rb +2 -2
  168. data/lib/puppet/provider/service/base.rb +1 -1
  169. data/lib/puppet/provider/service/smf.rb +3 -2
  170. data/lib/puppet/provider/service/systemd.rb +1 -1
  171. data/lib/puppet/provider/user/useradd.rb +6 -2
  172. data/lib/puppet/provider/user/windows_adsi.rb +1 -1
  173. data/lib/puppet/provider/yumrepo/inifile.rb +20 -9
  174. data/lib/puppet/provider/zfs/zfs.rb +1 -1
  175. data/lib/puppet/reference/configuration.rb +2 -0
  176. data/lib/puppet/reference/type.rb +11 -11
  177. data/lib/puppet/resource.rb +1 -1
  178. data/lib/puppet/resource/capability_finder.rb +5 -5
  179. data/lib/puppet/resource/catalog.rb +6 -3
  180. data/lib/puppet/resource/status.rb +9 -2
  181. data/lib/puppet/resource/type.rb +1 -1
  182. data/lib/puppet/settings.rb +31 -19
  183. data/lib/puppet/settings/base_setting.rb +5 -0
  184. data/lib/puppet/settings/config_file.rb +1 -1
  185. data/lib/puppet/settings/ttl_setting.rb +5 -0
  186. data/lib/puppet/ssl/certificate_factory.rb +2 -2
  187. data/lib/puppet/ssl/certificate_request.rb +0 -2
  188. data/lib/puppet/syntax_checkers/json.rb +1 -1
  189. data/lib/puppet/transaction/additional_resource_generator.rb +2 -2
  190. data/lib/puppet/transaction/event.rb +1 -1
  191. data/lib/puppet/transaction/report.rb +18 -12
  192. data/lib/puppet/type.rb +9 -13
  193. data/lib/puppet/type/augeas.rb +2 -2
  194. data/lib/puppet/type/cron.rb +11 -6
  195. data/lib/puppet/type/exec.rb +1 -1
  196. data/lib/puppet/type/file.rb +4 -5
  197. data/lib/puppet/type/host.rb +1 -1
  198. data/lib/puppet/type/k5login.rb +30 -54
  199. data/lib/puppet/type/package.rb +3 -3
  200. data/lib/puppet/type/schedule.rb +12 -12
  201. data/lib/puppet/type/scheduled_task.rb +2 -2
  202. data/lib/puppet/type/ssh_authorized_key.rb +5 -5
  203. data/lib/puppet/type/sshkey.rb +2 -2
  204. data/lib/puppet/type/tidy.rb +1 -1
  205. data/lib/puppet/type/user.rb +1 -1
  206. data/lib/puppet/type/yumrepo.rb +26 -5
  207. data/lib/puppet/util.rb +0 -4
  208. data/lib/puppet/util/backups.rb +1 -1
  209. data/lib/puppet/util/inifile.rb +3 -4
  210. data/lib/puppet/util/json.rb +68 -0
  211. data/lib/puppet/util/json_lockfile.rb +3 -3
  212. data/lib/puppet/util/log.rb +2 -5
  213. data/lib/puppet/util/log/destinations.rb +2 -2
  214. data/lib/puppet/util/network_device/cisco/facts.rb +1 -1
  215. data/lib/puppet/util/plist.rb +1 -1
  216. data/lib/puppet/util/reference.rb +1 -8
  217. data/lib/puppet/util/tagging.rb +1 -1
  218. data/lib/puppet/util/warnings.rb +0 -2
  219. data/lib/puppet/util/windows/adsi.rb +15 -18
  220. data/lib/puppet/util/windows/com.rb +2 -1
  221. data/lib/puppet/util/windows/file.rb +2 -2
  222. data/lib/puppet/util/windows/principal.rb +7 -6
  223. data/lib/puppet/util/windows/sid.rb +60 -7
  224. data/lib/puppet/util/windows/taskscheduler.rb +0 -9
  225. data/lib/puppet/version.rb +1 -1
  226. data/lib/puppet_pal.rb +53 -48
  227. data/locales/ja/puppet.po +1357 -912
  228. data/locales/puppet.pot +549 -466
  229. data/man/man5/puppet.conf.5 +103 -20
  230. data/man/man8/puppet-agent.8 +6 -2
  231. data/man/man8/puppet-apply.8 +2 -2
  232. data/man/man8/puppet-ca.8 +1 -1
  233. data/man/man8/puppet-catalog.8 +1 -1
  234. data/man/man8/puppet-cert.8 +1 -1
  235. data/man/man8/puppet-certificate.8 +1 -1
  236. data/man/man8/puppet-certificate_request.8 +1 -1
  237. data/man/man8/puppet-certificate_revocation_list.8 +1 -1
  238. data/man/man8/puppet-config.8 +35 -1
  239. data/man/man8/puppet-describe.8 +1 -1
  240. data/man/man8/puppet-device.8 +33 -11
  241. data/man/man8/puppet-doc.8 +1 -1
  242. data/man/man8/puppet-epp.8 +34 -12
  243. data/man/man8/puppet-facts.8 +50 -1
  244. data/man/man8/puppet-filebucket.8 +38 -11
  245. data/man/man8/puppet-generate.8 +1 -1
  246. data/man/man8/puppet-help.8 +1 -1
  247. data/man/man8/puppet-key.8 +1 -1
  248. data/man/man8/puppet-lookup.8 +1 -1
  249. data/man/man8/puppet-man.8 +10 -4
  250. data/man/man8/puppet-master.8 +1 -1
  251. data/man/man8/puppet-module.8 +15 -6
  252. data/man/man8/puppet-node.8 +1 -1
  253. data/man/man8/puppet-parser.8 +31 -8
  254. data/man/man8/puppet-plugin.8 +1 -1
  255. data/man/man8/puppet-report.8 +1 -1
  256. data/man/man8/puppet-resource.8 +1 -1
  257. data/man/man8/puppet-script.8 +67 -0
  258. data/man/man8/puppet-status.8 +1 -1
  259. data/man/man8/puppet.8 +3 -3
  260. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome2/lib/puppet_x/awesome2/echo_scheme_handler.rb +1 -1
  261. data/spec/integration/application/apply_spec.rb +15 -15
  262. data/spec/integration/application/lookup_spec.rb +21 -0
  263. data/spec/integration/faces/config_spec.rb +16 -4
  264. data/spec/integration/network/http/api/indirected_routes_spec.rb +5 -5
  265. data/spec/integration/parser/catalog_spec.rb +1 -1
  266. data/spec/integration/parser/collection_spec.rb +2 -2
  267. data/spec/integration/parser/compiler_spec.rb +17 -18
  268. data/spec/integration/parser/pcore_resource_spec.rb +2 -2
  269. data/spec/integration/parser/scope_spec.rb +2 -2
  270. data/spec/integration/ssl/certificate_authority_spec.rb +7 -7
  271. data/spec/integration/ssl/certificate_revocation_list_spec.rb +1 -1
  272. data/spec/integration/ssl/key_spec.rb +1 -1
  273. data/spec/integration/transaction/report_spec.rb +3 -3
  274. data/spec/integration/transaction_spec.rb +0 -1
  275. data/spec/integration/type/file_spec.rb +10 -11
  276. data/spec/integration/type_spec.rb +1 -2
  277. data/spec/integration/util/windows/adsi_spec.rb +86 -1
  278. data/spec/integration/util/windows/principal_spec.rb +11 -2
  279. data/spec/integration/util/windows/security_spec.rb +2 -2
  280. data/spec/lib/matchers/json.rb +4 -4
  281. data/spec/lib/puppet_spec/language.rb +34 -35
  282. data/spec/lib/puppet_spec/module_tool/shared_functions.rb +2 -2
  283. data/spec/shared_behaviours/file_server_terminus.rb +0 -2
  284. data/spec/shared_behaviours/things_that_declare_options.rb +2 -2
  285. data/spec/spec_helper.rb +1 -1
  286. data/spec/unit/application/cert_spec.rb +21 -9
  287. data/spec/unit/application/device_spec.rb +96 -2
  288. data/spec/unit/application/face_base_spec.rb +2 -2
  289. data/spec/unit/application/lookup_spec.rb +0 -1
  290. data/spec/unit/configurer_spec.rb +14 -0
  291. data/spec/unit/confine_spec.rb +16 -0
  292. data/spec/unit/data_providers/hiera_data_provider_spec.rb +4 -4
  293. data/spec/unit/datatypes_spec.rb +49 -0
  294. data/spec/unit/environments_spec.rb +7 -0
  295. data/spec/unit/face/config_spec.rb +116 -12
  296. data/spec/unit/face/epp_face_spec.rb +53 -2
  297. data/spec/unit/face/facts_spec.rb +53 -0
  298. data/spec/unit/face/help_spec.rb +62 -69
  299. data/spec/unit/face/man_spec.rb +26 -0
  300. data/spec/unit/face/module/list_spec.rb +0 -1
  301. data/spec/unit/face/parser_spec.rb +78 -0
  302. data/spec/unit/file_bucket/dipper_spec.rb +0 -4
  303. data/spec/unit/file_serving/content_spec.rb +0 -1
  304. data/spec/unit/file_serving/fileset_spec.rb +0 -1
  305. data/spec/unit/file_serving/metadata_spec.rb +0 -1
  306. data/spec/unit/file_serving/terminus_selector_spec.rb +0 -2
  307. data/spec/unit/forge_spec.rb +1 -2
  308. data/spec/unit/functions/assert_type_spec.rb +1 -1
  309. data/spec/unit/functions/empty_spec.rb +77 -0
  310. data/spec/unit/functions/epp_spec.rb +1 -1
  311. data/spec/unit/functions/flatten_spec.rb +31 -0
  312. data/spec/unit/functions/include_spec.rb +2 -2
  313. data/spec/unit/functions/inline_epp_spec.rb +1 -1
  314. data/spec/unit/functions/join_spec.rb +33 -0
  315. data/spec/unit/functions/keys_spec.rb +31 -0
  316. data/spec/unit/functions/length_spec.rb +50 -0
  317. data/spec/unit/functions/lookup_fixture_spec.rb +1 -1
  318. data/spec/unit/functions/lookup_spec.rb +52 -0
  319. data/spec/unit/functions/shared.rb +1 -1
  320. data/spec/unit/functions/values_spec.rb +30 -0
  321. data/spec/unit/functions/versioncmp_spec.rb +1 -1
  322. data/spec/unit/functions4_spec.rb +30 -32
  323. data/spec/unit/graph/title_hash_prioritizer_spec.rb +2 -1
  324. data/spec/unit/indirector/catalog/compiler_spec.rb +0 -15
  325. data/spec/unit/indirector/facts/rest_spec.rb +45 -0
  326. data/spec/unit/indirector/facts/yaml_spec.rb +6 -0
  327. data/spec/unit/indirector/file_bucket_file/file_spec.rb +2 -2
  328. data/spec/unit/indirector/indirection_spec.rb +1 -1
  329. data/spec/unit/indirector/node/ldap_spec.rb +2 -2
  330. data/spec/unit/indirector/request_spec.rb +0 -2
  331. data/spec/unit/indirector/rest_spec.rb +2 -2
  332. data/spec/unit/indirector_spec.rb +0 -1
  333. data/spec/unit/info_service_spec.rb +1 -1
  334. data/spec/unit/interface/action_manager_spec.rb +1 -1
  335. data/spec/unit/interface/action_spec.rb +1 -1
  336. data/spec/unit/module_spec.rb +0 -5
  337. data/spec/unit/module_tool/applications/builder_spec.rb +1 -1
  338. data/spec/unit/module_tool/applications/unpacker_spec.rb +4 -4
  339. data/spec/unit/network/formats_spec.rb +5 -13
  340. data/spec/unit/network/http/api/indirected_routes_spec.rb +6 -2
  341. data/spec/unit/network/http/connection_spec.rb +1 -1
  342. data/spec/unit/network/http/handler_spec.rb +3 -2
  343. data/spec/unit/node/environment_spec.rb +1 -1
  344. data/spec/unit/node_spec.rb +3 -3
  345. data/spec/unit/parser/compiler_spec.rb +9 -2
  346. data/spec/unit/parser/environment_compiler_spec.rb +8 -8
  347. data/spec/unit/parser/functions/create_resources_spec.rb +1 -1
  348. data/spec/unit/parser/functions/fail_spec.rb +1 -1
  349. data/spec/unit/parser/functions/fqdn_rand_spec.rb +24 -0
  350. data/spec/unit/parser/functions/realize_spec.rb +1 -1
  351. data/spec/unit/parser/resource_spec.rb +0 -1
  352. data/spec/unit/parser/scope_spec.rb +3 -3
  353. data/spec/unit/parser/type_loader_spec.rb +1 -1
  354. data/spec/unit/pops/adaptable_spec.rb +0 -1
  355. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +0 -3
  356. data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +0 -4
  357. data/spec/unit/pops/factory_rspec_helper.rb +1 -1
  358. data/spec/unit/pops/factory_spec.rb +5 -5
  359. data/spec/unit/pops/issues_spec.rb +23 -8
  360. data/spec/unit/pops/loaders/loaders_spec.rb +24 -2
  361. data/spec/unit/pops/loaders/static_loader_spec.rb +1 -1
  362. data/spec/unit/pops/lookup/interpolation_spec.rb +5 -0
  363. data/spec/unit/pops/lookup/lookup_spec.rb +56 -0
  364. data/spec/unit/pops/model/pn_transformer_spec.rb +53 -0
  365. data/spec/unit/pops/parser/lexer2_spec.rb +14 -5
  366. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +9 -9
  367. data/spec/unit/pops/parser/parse_calls_spec.rb +1 -1
  368. data/spec/unit/pops/parser/parse_functions_spec.rb +1 -1
  369. data/spec/unit/pops/parser/parse_heredoc_spec.rb +3 -3
  370. data/spec/unit/pops/parser/parse_lambda_spec.rb +1 -1
  371. data/spec/unit/pops/parser/parse_resource_spec.rb +35 -35
  372. data/spec/unit/pops/parser/pn_parser_spec.rb +101 -0
  373. data/spec/unit/pops/pn_spec.rb +148 -0
  374. data/spec/unit/pops/types/iterable_spec.rb +1 -1
  375. data/spec/unit/pops/types/p_object_type_spec.rb +5 -5
  376. data/spec/unit/pops/types/p_timespan_type_spec.rb +11 -4
  377. data/spec/unit/pops/types/p_timestamp_type_spec.rb +9 -2
  378. data/spec/unit/pops/types/p_type_set_type_spec.rb +106 -2
  379. data/spec/unit/pops/types/ruby_generator_spec.rb +3 -8
  380. data/spec/unit/pops/types/string_converter_spec.rb +3 -3
  381. data/spec/unit/pops/types/type_calculator_spec.rb +1 -1
  382. data/spec/unit/pops/validator/validator_spec.rb +3 -1
  383. data/spec/unit/property_spec.rb +2 -2
  384. data/spec/unit/provider/aixobject_spec.rb +1 -1
  385. data/spec/unit/provider/cron/crontab_spec.rb +3 -3
  386. data/spec/unit/provider/exec/posix_spec.rb +6 -6
  387. data/spec/unit/provider/group/groupadd_spec.rb +4 -4
  388. data/spec/unit/provider/group/windows_adsi_spec.rb +79 -22
  389. data/spec/unit/provider/ldap_spec.rb +0 -1
  390. data/spec/unit/provider/nameservice_spec.rb +5 -5
  391. data/spec/unit/provider/package/rpm_spec.rb +3 -4
  392. data/spec/unit/provider/package/yum_spec.rb +6 -2
  393. data/spec/unit/provider/parsedfile_spec.rb +1 -1
  394. data/spec/unit/provider/service/base_spec.rb +2 -4
  395. data/spec/unit/provider/service/init_spec.rb +2 -2
  396. data/spec/unit/provider/service/openrc_spec.rb +2 -2
  397. data/spec/unit/provider/service/redhat_spec.rb +2 -2
  398. data/spec/unit/provider/service/smf_spec.rb +2 -0
  399. data/spec/unit/provider/service/systemd_spec.rb +3 -3
  400. data/spec/unit/provider/service/upstart_spec.rb +7 -7
  401. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +0 -4
  402. data/spec/unit/provider/sshkey/parsed_spec.rb +0 -2
  403. data/spec/unit/provider/user/useradd_spec.rb +15 -9
  404. data/spec/unit/provider/user/windows_adsi_spec.rb +4 -4
  405. data/spec/unit/provider/yumrepo/inifile_spec.rb +76 -0
  406. data/spec/unit/puppet_pal_2pec.rb +4 -5
  407. data/spec/unit/resource/catalog_spec.rb +8 -3
  408. data/spec/unit/resource/status_spec.rb +15 -4
  409. data/spec/unit/resource/type_spec.rb +2 -3
  410. data/spec/unit/settings_spec.rb +9 -4
  411. data/spec/unit/ssl/certificate_authority_spec.rb +1 -9
  412. data/spec/unit/ssl/certificate_request_spec.rb +1 -2
  413. data/spec/unit/transaction/report_spec.rb +41 -0
  414. data/spec/unit/transaction_spec.rb +1 -1
  415. data/spec/unit/type/exec_spec.rb +7 -9
  416. data/spec/unit/type/file/selinux_spec.rb +0 -1
  417. data/spec/unit/type/file_spec.rb +4 -3
  418. data/spec/unit/type/k5login_spec.rb +79 -10
  419. data/spec/unit/type/mount_spec.rb +1 -1
  420. data/spec/unit/type/nagios_spec.rb +6 -6
  421. data/spec/unit/type/user_spec.rb +1 -1
  422. data/spec/unit/type/yumrepo_spec.rb +18 -0
  423. data/spec/unit/type/zfs_spec.rb +1 -1
  424. data/spec/unit/type_spec.rb +14 -15
  425. data/spec/unit/util/docs_spec.rb +1 -1
  426. data/spec/unit/util/execution_spec.rb +0 -1
  427. data/spec/unit/util/inifile_spec.rb +35 -4
  428. data/spec/unit/util/log/destinations_spec.rb +2 -2
  429. data/spec/unit/util/log_spec.rb +6 -5
  430. data/spec/unit/util/network_device/cisco/device_spec.rb +2 -2
  431. data/spec/unit/util/plist_spec.rb +3 -3
  432. data/spec/unit/util/selinux_spec.rb +2 -2
  433. data/spec/unit/util/tagging_spec.rb +1 -7
  434. data/spec/unit/util/windows/adsi_spec.rb +31 -27
  435. data/spec/unit/util/windows/sid_spec.rb +86 -15
  436. data/spec/unit/util_spec.rb +2 -2
  437. data/spec/watchr.rb +0 -1
  438. data/tasks/benchmark.rake +37 -0
  439. data/tasks/manpages.rake +1 -1
  440. metadata +83 -11
  441. checksums.yaml +0 -7
@@ -19,8 +19,8 @@ Puppet::Functions.create_function(:json_data) do
19
19
  path = options['path']
20
20
  context.cached_file_data(path) do |content|
21
21
  begin
22
- JSON.parse(content)
23
- rescue JSON::ParserError => ex
22
+ Puppet::Util::Json.load(content)
23
+ rescue Puppet::Util::Json::ParseError => ex
24
24
  # Filename not included in message, so we add it here.
25
25
  raise Puppet::DataBinding::LookupError, "Unable to parse (%{path}): %{message}" % { path: path, message: ex.message }
26
26
  end
@@ -0,0 +1,25 @@
1
+ # Returns the keys of a hash as an Array
2
+ #
3
+ # @example Using `keys`
4
+ #
5
+ # ```puppet
6
+ # $hsh = {"apples" => 3, "oranges" => 4 }
7
+ # $hsh.keys()
8
+ # keys($hsh)
9
+ # # both results in the array ["apples", "oranges"]
10
+ # ```
11
+ #
12
+ # * Note that a hash in the puppet language accepts any data value (including `undef`) unless
13
+ # it is constrained with a `Hash` data type that narrows the allowed data types.
14
+ # * For an empty hash, an empty array is returned.
15
+ # * The order of the keys is the same as the order in the hash (typically the order in which they were added).
16
+ #
17
+ Puppet::Functions.create_function(:keys) do
18
+ dispatch :keys do
19
+ param 'Hash', :hsh
20
+ end
21
+
22
+ def keys(hsh)
23
+ hsh.keys
24
+ end
25
+ end
@@ -0,0 +1,44 @@
1
+ # Returns the length of an Array, Hash, String, or Binary value.
2
+ #
3
+ # The returned value is a positive integer indicating the number
4
+ # of elements in the container; counting (possibly multibyte) characters for a `String`,
5
+ # bytes in a `Binary`, number of elements in an `Array`, and number of
6
+ # key-value associations in a Hash.
7
+ #
8
+ # @example Using `length`
9
+ #
10
+ # ```puppet
11
+ # "roses".length() # 5
12
+ # length("violets") # 7
13
+ # [10, 20].length # 2
14
+ # {a => 1, b => 3}.length # 2
15
+ # ```
16
+ #
17
+ # @since 5.5.0 - also supporting Binary
18
+ #
19
+ Puppet::Functions.create_function(:length) do
20
+ dispatch :collection_length do
21
+ param 'Collection', :arg
22
+ end
23
+
24
+ dispatch :string_length do
25
+ param 'String', :arg
26
+ end
27
+
28
+ dispatch :binary_length do
29
+ param 'Binary', :arg
30
+ end
31
+
32
+ def collection_length(col)
33
+ col.size
34
+ end
35
+
36
+ def string_length(s)
37
+ s.length
38
+ end
39
+
40
+ def binary_length(bin)
41
+ bin.length
42
+ end
43
+
44
+ end
@@ -1,4 +1,42 @@
1
- # (Documented in 3.x stub)
1
+ # Calls a [lambda](https://docs.puppet.com/puppet/latest/reference/lang_lambdas.html)
2
+ # without arguments if the value given to `lest` is `undef`.
3
+ # Returns the result of calling the lambda if the argument is `undef`, otherwise the
4
+ # given argument.
5
+ #
6
+ # The `lest` function is useful in a chain of `then` calls, or in general
7
+ # as a guard against `undef` values. The function can be used to call `fail`, or to
8
+ # return a default value.
9
+ #
10
+ # These two expressions are equivalent:
11
+ #
12
+ # ```puppet
13
+ # if $x == undef { do_things() }
14
+ # lest($x) || { do_things() }
15
+ # ```
16
+ #
17
+ # @example Using the `lest` function
18
+ #
19
+ # ```puppet
20
+ # $data = {a => [ b, c ] }
21
+ # notice $data.dig(a, b, c)
22
+ # .then |$x| { $x * 2 }
23
+ # .lest || { fail("no value for $data[a][b][c]" }
24
+ # ```
25
+ #
26
+ # Would fail the operation because $data[a][b][c] results in `undef`
27
+ # (there is no `b` key in `a`).
28
+ #
29
+ # In contrast - this example:
30
+ #
31
+ # ```puppet
32
+ # $data = {a => { b => { c => 10 } } }
33
+ # notice $data.dig(a, b, c)
34
+ # .then |$x| { $x * 2 }
35
+ # .lest || { fail("no value for $data[a][b][c]" }
36
+ # ```
37
+ #
38
+ # Would notice the value `20`
39
+ #
2
40
  # @since 4.5.0
3
41
  #
4
42
  Puppet::Functions.create_function(:lest) do
@@ -207,7 +207,8 @@ Puppet::Functions.create_function(:lookup, Puppet::Functions::InternalFunction)
207
207
  end
208
208
 
209
209
  def do_lookup(scope, name, value_type, default_value, has_default, override, default_values_hash, merge, &block)
210
- Puppet::Pops::Lookup.lookup(name, value_type, default_value, has_default, merge, Puppet::Pops::Lookup::Invocation.new(scope, override, default_values_hash), &block)
210
+ Puppet::Pops::Lookup.lookup(name, value_type, default_value, has_default, merge,
211
+ Puppet::Pops::Lookup::Invocation.new(scope, override, default_values_hash), &block)
211
212
  end
212
213
 
213
214
  def hash_args(options_hash)
@@ -20,24 +20,24 @@
20
20
  #
21
21
  # @example Using the `map` function with an array and a one-parameter lambda
22
22
  #
23
- # ~~~ puppet
23
+ # ```puppet
24
24
  # # For the array $data, return an array containing each value multiplied by 10
25
25
  # $data = [1,2,3]
26
26
  # $transformed_data = $data.map |$items| { $items * 10 }
27
27
  # # $transformed_data contains [10,20,30]
28
- # ~~~
28
+ # ```
29
29
  #
30
30
  # When the first argument is a hash, Puppet passes each key and value pair to the lambda
31
31
  # as an array in the form `[key, value]`.
32
32
  #
33
33
  # @example Using the `map` function with a hash and a one-parameter lambda
34
34
  #
35
- # ~~~ puppet
35
+ # ```puppet
36
36
  # # For the hash $data, return an array containing the keys
37
37
  # $data = {'a'=>1,'b'=>2,'c'=>3}
38
38
  # $transformed_data = $data.map |$items| { $items[0] }
39
39
  # # $transformed_data contains ['a','b','c']
40
- # ~~~
40
+ # ```
41
41
  #
42
42
  # When the first argument is an array and the lambda has two parameters, Puppet passes the
43
43
  # array's indexes (enumerated from 0) in the first parameter and its values in the second
@@ -45,24 +45,24 @@
45
45
  #
46
46
  # @example Using the `map` function with an array and a two-parameter lambda
47
47
  #
48
- # ~~~ puppet
48
+ # ```puppet
49
49
  # # For the array $data, return an array containing the indexes
50
50
  # $data = [1,2,3]
51
51
  # $transformed_data = $data.map |$index,$value| { $index }
52
52
  # # $transformed_data contains [0,1,2]
53
- # ~~~
53
+ # ```
54
54
  #
55
55
  # When the first argument is a hash, Puppet passes its keys to the first parameter and its
56
56
  # values to the second parameter.
57
57
  #
58
58
  # @example Using the `map` function with a hash and a two-parameter lambda
59
59
  #
60
- # ~~~ puppet
60
+ # ```puppet
61
61
  # # For the hash $data, return an array containing each value
62
62
  # $data = {'a'=>1,'b'=>2,'c'=>3}
63
63
  # $transformed_data = $data.map |$key,$value| { $value }
64
64
  # # $transformed_data contains [1,2,3]
65
- # ~~~
65
+ # ```
66
66
  #
67
67
  # @since 4.0.0
68
68
  #
@@ -125,10 +125,11 @@ Puppet::Functions.create_function(:map) do
125
125
  index = 0
126
126
  loop do
127
127
  result << yield(index, enum.next)
128
- index = index +1
128
+ index = index + 1
129
129
  end
130
130
  rescue StopIteration
131
131
  end
132
+
132
133
  result
133
134
  end
134
135
  end
@@ -13,24 +13,24 @@
13
13
  #
14
14
  # @example Matching a regular expression in a string
15
15
  #
16
- # ~~~ ruby
16
+ # ```puppet
17
17
  # $matches = "abc123".match(/[a-z]+[1-9]+/)
18
18
  # # $matches contains [abc123]
19
- # ~~~
19
+ # ```
20
20
  #
21
21
  # @example Matching a regular expressions with grouping captures in a string
22
22
  #
23
- # ~~~ ruby
23
+ # ```puppet
24
24
  # $matches = "abc123".match(/([a-z]+)([1-9]+)/)
25
25
  # # $matches contains [abc123, abc, 123]
26
- # ~~~
26
+ # ```
27
27
  #
28
28
  # @example Matching a regular expression with grouping captures in an array of strings
29
29
  #
30
- # ~~~ ruby
30
+ # ```puppet
31
31
  # $matches = ["abc123","def456"].match(/([a-z]+)([1-9]+)/)
32
32
  # # $matches contains [[abc123, abc, 123], [def456, def, 456]]
33
- # ~~~
33
+ # ```
34
34
  #
35
35
  # @since 4.0.0
36
36
  #
@@ -1,5 +1,998 @@
1
- # Returns a new instance of a data type.
2
- # (The documentation is maintained in the corresponding 3.x stub)
1
+ # Creates a new instance/object of a given data type.
2
+ #
3
+ # This function makes it possible to create new instances of
4
+ # concrete data types. If a block is given it is called with the
5
+ # just created instance as an argument.
6
+ #
7
+ # Calling this function is equivalent to directly
8
+ # calling the data type:
9
+ #
10
+ # @example `new` and calling type directly are equivalent
11
+ #
12
+ # ```puppet
13
+ # $a = Integer.new("42")
14
+ # $b = Integer("42")
15
+ # ```
16
+ #
17
+ # These would both convert the string `"42"` to the decimal value `42`.
18
+ #
19
+ # @example arguments by position or by name
20
+ #
21
+ # ```puppet
22
+ # $a = Integer.new("42", 8)
23
+ # $b = Integer({from => "42", radix => 8})
24
+ # ```
25
+ #
26
+ # This would convert the octal (radix 8) number `"42"` in string form
27
+ # to the decimal value `34`.
28
+ #
29
+ # The new function supports two ways of giving the arguments:
30
+ #
31
+ # * by name (using a hash with property to value mapping)
32
+ # * by position (as regular arguments)
33
+ #
34
+ # Note that it is not possible to create new instances of
35
+ # some abstract data types (for example `Variant`). The data type `Optional[T]` is an
36
+ # exception as it will create an instance of `T` or `undef` if the
37
+ # value to convert is `undef`.
38
+ #
39
+ # The arguments that can be given is determined by the data type.
40
+ #
41
+ # > An assertion is always made that the produced value complies with the given type constraints.
42
+ #
43
+ # @example data type constraints are checked
44
+ #
45
+ # ```puppet
46
+ # Integer[0].new("-100")
47
+ # ```
48
+ #
49
+ # Would fail with an assertion error (since value is less than 0).
50
+ #
51
+ # The following sections show the arguments and conversion rules
52
+ # per data type built into the Puppet Type System.
53
+ #
54
+ # Conversion to Optional[T] and NotUndef[T]
55
+ # -----------------------------------------
56
+ #
57
+ # Conversion to these data types is the same as a conversion to the type argument `T`.
58
+ # In the case of `Optional[T]` it is accepted that the argument to convert may be `undef`.
59
+ # It is however not acceptable to give other arguments (than `undef`) that cannot be
60
+ # converted to `T`.
61
+ #
62
+ # Conversion to Integer
63
+ # ---------------------
64
+ #
65
+ # A new `Integer` can be created from `Integer`, `Float`, `Boolean`, and `String` values.
66
+ # For conversion from `String` it is possible to specify the radix (base).
67
+ #
68
+ # ```puppet
69
+ # type Radix = Variant[Default, Integer[2,2], Integer[8,8], Integer[10,10], Integer[16,16]]
70
+ #
71
+ # function Integer.new(
72
+ # String $value,
73
+ # Radix $radix = 10,
74
+ # Boolean $abs = false
75
+ # )
76
+ #
77
+ # function Integer.new(
78
+ # Variant[Numeric, Boolean] $value,
79
+ # Boolean $abs = false
80
+ # )
81
+ # ```
82
+ #
83
+ # * When converting from `String` the default radix is 10.
84
+ # * If radix is not specified an attempt is made to detect the radix from the start of the string:
85
+ # * `0b` or `0B` is taken as radix 2.
86
+ # * `0x` or `0X` is taken as radix 16.
87
+ # * `0` as radix 8.
88
+ # * All others are decimal.
89
+ # * Conversion from `String` accepts an optional sign in the string.
90
+ # * For hexadecimal (radix 16) conversion an optional leading "0x", or "0X" is accepted.
91
+ # * For octal (radix 8) an optional leading "0" is accepted.
92
+ # * For binary (radix 2) an optional leading "0b" or "0B" is accepted.
93
+ # * When `radix` is set to `default`, the conversion is based on the leading.
94
+ # characters in the string. A leading "0" for radix 8, a leading "0x", or "0X" for
95
+ # radix 16, and leading "0b" or "0B" for binary.
96
+ # * Conversion from `Boolean` results in 0 for `false` and 1 for `true`.
97
+ # * Conversion from `Integer`, `Float`, and `Boolean` ignores the radix.
98
+ # * `Float` value fractions are truncated (no rounding).
99
+ # * When `abs` is set to `true`, the result will be an absolute integer.
100
+ #
101
+ # @example Converting to Integer in multiple ways
102
+ #
103
+ # ```puppet
104
+ # $a_number = Integer("0xFF", 16) # results in 255
105
+ # $a_number = Integer("010") # results in 8
106
+ # $a_number = Integer("010", 10) # results in 10
107
+ # $a_number = Integer(true) # results in 1
108
+ # $a_number = Integer(-38, 10, true) # results in 38
109
+ # ```
110
+ #
111
+ # Conversion to Float
112
+ # -------------------
113
+ #
114
+ # A new `Float` can be created from `Integer`, `Float`, `Boolean`, and `String` values.
115
+ # For conversion from `String` both float and integer formats are supported.
116
+ #
117
+ # ```puppet
118
+ # function Float.new(
119
+ # Variant[Numeric, Boolean, String] $value,
120
+ # Boolean $abs = true
121
+ # )
122
+ # ```
123
+ #
124
+ #
125
+ # * For an integer, the floating point fraction of `.0` is added to the value.
126
+ # * A `Boolean` `true` is converted to 1.0, and a `false` to 0.0
127
+ # * In `String` format, integer prefixes for hex and binary are understood (but not octal since
128
+ # floating point in string format may start with a '0').
129
+ # * When `abs` is set to `true`, the result will be an absolute floating point value.
130
+ #
131
+ # Conversion to Numeric
132
+ # ---------------------
133
+ #
134
+ # A new `Integer` or `Float` can be created from `Integer`, `Float`, `Boolean` and
135
+ # `String` values.
136
+ #
137
+ # ```puppet
138
+ # function Numeric.new(
139
+ # Variant[Numeric, Boolean, String] $value,
140
+ # Boolean $abs = true
141
+ # )
142
+ # ```
143
+ #
144
+ # * If the value has a decimal period, or if given in scientific notation
145
+ # (e/E), the result is a `Float`, otherwise the value is an `Integer`. The
146
+ # conversion from `String` always uses a radix based on the prefix of the string.
147
+ # * Conversion from `Boolean` results in 0 for `false` and 1 for `true`.
148
+ # * When `abs` is set to `true`, the result will be an absolute `Float`or `Integer` value.
149
+ #
150
+ # @example Converting to Numeric in different ways
151
+ #
152
+ # ```puppet
153
+ # $a_number = Numeric(true) # results in 1
154
+ # $a_number = Numeric("0xFF") # results in 255
155
+ # $a_number = Numeric("010") # results in 8
156
+ # $a_number = Numeric("3.14") # results in 3.14 (a float)
157
+ # $a_number = Numeric(-42.3, true) # results in 42.3
158
+ # $a_number = Numeric(-42, true) # results in 42
159
+ # ```
160
+ #
161
+ # Conversion to Timespan
162
+ # -------------------
163
+ #
164
+ # A new `Timespan` can be created from `Integer`, `Float`, `String`, and `Hash` values. Several variants of the constructor are provided.
165
+ #
166
+ # #### Timespan from seconds
167
+ #
168
+ # When a Float is used, the decimal part represents fractions of a second.
169
+ #
170
+ # ```puppet
171
+ # function Timespan.new(
172
+ # Variant[Float, Integer] $value
173
+ # )
174
+ # ```
175
+ #
176
+ # #### Timespan from days, hours, minutes, seconds, and fractions of a second
177
+ #
178
+ # The arguments can be passed separately in which case the first four, days, hours, minutes, and seconds are mandatory and the rest are optional.
179
+ # All values may overflow and/or be negative. The internal 128-bit nano-second integer is calculated as:
180
+ #
181
+ # ```
182
+ # (((((days * 24 + hours) * 60 + minutes) * 60 + seconds) * 1000 + milliseconds) * 1000 + microseconds) * 1000 + nanoseconds
183
+ # ```
184
+ #
185
+ # ```puppet
186
+ # function Timespan.new(
187
+ # Integer $days, Integer $hours, Integer $minutes, Integer $seconds,
188
+ # Integer $milliseconds = 0, Integer $microseconds = 0, Integer $nanoseconds = 0
189
+ # )
190
+ # ```
191
+ #
192
+ # or, all arguments can be passed as a `Hash`, in which case all entries are optional:
193
+ #
194
+ # ```puppet
195
+ # function Timespan.new(
196
+ # Struct[{
197
+ # Optional[negative] => Boolean,
198
+ # Optional[days] => Integer,
199
+ # Optional[hours] => Integer,
200
+ # Optional[minutes] => Integer,
201
+ # Optional[seconds] => Integer,
202
+ # Optional[milliseconds] => Integer,
203
+ # Optional[microseconds] => Integer,
204
+ # Optional[nanoseconds] => Integer
205
+ # }] $hash
206
+ # )
207
+ # ```
208
+ #
209
+ # #### Timespan from String and format directive patterns
210
+ #
211
+ # The first argument is parsed using the format optionally passed as a string or array of strings. When an array is used, an attempt
212
+ # will be made to parse the string using the first entry and then with each entry in succession until parsing succeeds. If the second
213
+ # argument is omitted, an array of default formats will be used.
214
+ #
215
+ # An exception is raised when no format was able to parse the given string.
216
+ #
217
+ # ```puppet
218
+ # function Timespan.new(
219
+ # String $string, Variant[String[2],Array[String[2], 1]] $format = <default format>)
220
+ # )
221
+ # ```
222
+ #
223
+ # the arguments may also be passed as a `Hash`:
224
+ #
225
+ # ```puppet
226
+ # function Timespan.new(
227
+ # Struct[{
228
+ # string => String[1],
229
+ # Optional[format] => Variant[String[2],Array[String[2], 1]]
230
+ # }] $hash
231
+ # )
232
+ # ```
233
+ #
234
+ # The directive consists of a percent (%) character, zero or more flags, optional minimum field width and
235
+ # a conversion specifier as follows:
236
+ # ```
237
+ # %[Flags][Width]Conversion
238
+ # ```
239
+ #
240
+ # ##### Flags:
241
+ #
242
+ # | Flag | Meaning
243
+ # | ---- | ---------------
244
+ # | - | Don't pad numerical output
245
+ # | _ | Use spaces for padding
246
+ # | 0 | Use zeros for padding
247
+ #
248
+ # ##### Format directives:
249
+ #
250
+ # | Format | Meaning |
251
+ # | ------ | ------- |
252
+ # | D | Number of Days |
253
+ # | H | Hour of the day, 24-hour clock |
254
+ # | M | Minute of the hour (00..59) |
255
+ # | S | Second of the minute (00..59) |
256
+ # | L | Millisecond of the second (000..999) |
257
+ # | N | Fractional seconds digits |
258
+ #
259
+ # The format directive that represents the highest magnitude in the format will be allowed to
260
+ # overflow. I.e. if no "%D" is used but a "%H" is present, then the hours may be more than 23.
261
+ #
262
+ # The default array contains the following patterns:
263
+ #
264
+ # ```
265
+ # ['%D-%H:%M:%S', '%D-%H:%M', '%H:%M:%S', '%H:%M']
266
+ # ```
267
+ #
268
+ # Examples - Converting to Timespan
269
+ #
270
+ # ```puppet
271
+ # $duration = Timespan(13.5) # 13 seconds and 500 milliseconds
272
+ # $duration = Timespan({days=>4}) # 4 days
273
+ # $duration = Timespan(4, 0, 0, 2) # 4 days and 2 seconds
274
+ # $duration = Timespan('13:20') # 13 hours and 20 minutes (using default pattern)
275
+ # $duration = Timespan('10:03.5', '%M:%S.%L') # 10 minutes, 3 seconds, and 5 milli-seconds
276
+ # $duration = Timespan('10:03.5', '%M:%S.%N') # 10 minutes, 3 seconds, and 5 nano-seconds
277
+ # ```
278
+ #
279
+ # Conversion to Timestamp
280
+ # -------------------
281
+ #
282
+ # A new `Timestamp` can be created from `Integer`, `Float`, `String`, and `Hash` values. Several variants of the constructor are provided.
283
+ #
284
+ # #### Timestamp from seconds since epoch (1970-01-01 00:00:00 UTC)
285
+ #
286
+ # When a Float is used, the decimal part represents fractions of a second.
287
+ #
288
+ # ```puppet
289
+ # function Timestamp.new(
290
+ # Variant[Float, Integer] $value
291
+ # )
292
+ # ```
293
+ #
294
+ # #### Timestamp from String and patterns consisting of format directives
295
+ #
296
+ # The first argument is parsed using the format optionally passed as a string or array of strings. When an array is used, an attempt
297
+ # will be made to parse the string using the first entry and then with each entry in succession until parsing succeeds. If the second
298
+ # argument is omitted, an array of default formats will be used.
299
+ #
300
+ # A third optional timezone argument can be provided. The first argument will then be parsed as if it represents a local time in that
301
+ # timezone. The timezone can be any timezone that is recognized when using the '%z' or '%Z' formats, or the word 'current', in which
302
+ # case the current timezone of the evaluating process will be used. The timezone argument is case insensitive.
303
+ #
304
+ # The default timezone, when no argument is provided, or when using the keyword `default`, is 'UTC'.
305
+ #
306
+ # It is illegal to provide a timezone argument other than `default` in combination with a format that contains '%z' or '%Z' since that
307
+ # would introduce an ambiguity as to which timezone to use. The one extracted from the string, or the one provided as an argument.
308
+ #
309
+ # An exception is raised when no format was able to parse the given string.
310
+ #
311
+ # ```puppet
312
+ # function Timestamp.new(
313
+ # String $string,
314
+ # Variant[String[2],Array[String[2], 1]] $format = <default format>,
315
+ # String $timezone = default)
316
+ # )
317
+ # ```
318
+ #
319
+ # the arguments may also be passed as a `Hash`:
320
+ #
321
+ # ```puppet
322
+ # function Timestamp.new(
323
+ # Struct[{
324
+ # string => String[1],
325
+ # Optional[format] => Variant[String[2],Array[String[2], 1]],
326
+ # Optional[timezone] => String[1]
327
+ # }] $hash
328
+ # )
329
+ # ```
330
+ #
331
+ # The directive consists of a percent (%) character, zero or more flags, optional minimum field width and
332
+ # a conversion specifier as follows:
333
+ # ```
334
+ # %[Flags][Width]Conversion
335
+ # ```
336
+ #
337
+ # ##### Flags:
338
+ #
339
+ # | Flag | Meaning
340
+ # | ---- | ---------------
341
+ # | - | Don't pad numerical output
342
+ # | _ | Use spaces for padding
343
+ # | 0 | Use zeros for padding
344
+ # | # | Change names to upper-case or change case of am/pm
345
+ # | ^ | Use uppercase
346
+ # | : | Use colons for %z
347
+ #
348
+ # ##### Format directives (names and padding can be altered using flags):
349
+ #
350
+ # **Date (Year, Month, Day):**
351
+ #
352
+ # | Format | Meaning |
353
+ # | ------ | ------- |
354
+ # | Y | Year with century, zero-padded to at least 4 digits |
355
+ # | C | year / 100 (rounded down such as 20 in 2009) |
356
+ # | y | year % 100 (00..99) |
357
+ # | m | Month of the year, zero-padded (01..12) |
358
+ # | B | The full month name ("January") |
359
+ # | b | The abbreviated month name ("Jan") |
360
+ # | h | Equivalent to %b |
361
+ # | d | Day of the month, zero-padded (01..31) |
362
+ # | e | Day of the month, blank-padded ( 1..31) |
363
+ # | j | Day of the year (001..366) |
364
+ #
365
+ # **Time (Hour, Minute, Second, Subsecond):**
366
+ #
367
+ # | Format | Meaning |
368
+ # | ------ | ------- |
369
+ # | H | Hour of the day, 24-hour clock, zero-padded (00..23) |
370
+ # | k | Hour of the day, 24-hour clock, blank-padded ( 0..23) |
371
+ # | I | Hour of the day, 12-hour clock, zero-padded (01..12) |
372
+ # | l | Hour of the day, 12-hour clock, blank-padded ( 1..12) |
373
+ # | P | Meridian indicator, lowercase ("am" or "pm") |
374
+ # | p | Meridian indicator, uppercase ("AM" or "PM") |
375
+ # | M | Minute of the hour (00..59) |
376
+ # | S | Second of the minute (00..60) |
377
+ # | L | Millisecond of the second (000..999). Digits under millisecond are truncated to not produce 1000 |
378
+ # | N | Fractional seconds digits, default is 9 digits (nanosecond). Digits under a specified width are truncated to avoid carry up |
379
+ #
380
+ # **Time (Hour, Minute, Second, Subsecond):**
381
+ #
382
+ # | Format | Meaning |
383
+ # | ------ | ------- |
384
+ # | z | Time zone as hour and minute offset from UTC (e.g. +0900) |
385
+ # | :z | hour and minute offset from UTC with a colon (e.g. +09:00) |
386
+ # | ::z | hour, minute and second offset from UTC (e.g. +09:00:00) |
387
+ # | Z | Abbreviated time zone name or similar information. (OS dependent) |
388
+ #
389
+ # **Weekday:**
390
+ #
391
+ # | Format | Meaning |
392
+ # | ------ | ------- |
393
+ # | A | The full weekday name ("Sunday") |
394
+ # | a | The abbreviated name ("Sun") |
395
+ # | u | Day of the week (Monday is 1, 1..7) |
396
+ # | w | Day of the week (Sunday is 0, 0..6) |
397
+ #
398
+ # **ISO 8601 week-based year and week number:**
399
+ #
400
+ # The first week of YYYY starts with a Monday and includes YYYY-01-04.
401
+ # The days in the year before the first week are in the last week of
402
+ # the previous year.
403
+ #
404
+ # | Format | Meaning |
405
+ # | ------ | ------- |
406
+ # | G | The week-based year |
407
+ # | g | The last 2 digits of the week-based year (00..99) |
408
+ # | V | Week number of the week-based year (01..53) |
409
+ #
410
+ # **Week number:**
411
+ #
412
+ # The first week of YYYY that starts with a Sunday or Monday (according to %U
413
+ # or %W). The days in the year before the first week are in week 0.
414
+ #
415
+ # | Format | Meaning |
416
+ # | ------ | ------- |
417
+ # | U | Week number of the year. The week starts with Sunday. (00..53) |
418
+ # | W | Week number of the year. The week starts with Monday. (00..53) |
419
+ #
420
+ # **Seconds since the Epoch:**
421
+ #
422
+ # | Format | Meaning |
423
+ # | s | Number of seconds since 1970-01-01 00:00:00 UTC. |
424
+ #
425
+ # **Literal string:**
426
+ #
427
+ # | Format | Meaning |
428
+ # | ------ | ------- |
429
+ # | n | Newline character (\n) |
430
+ # | t | Tab character (\t) |
431
+ # | % | Literal "%" character |
432
+ #
433
+ # **Combination:**
434
+ #
435
+ # | Format | Meaning |
436
+ # | ------ | ------- |
437
+ # | c | date and time (%a %b %e %T %Y) |
438
+ # | D | Date (%m/%d/%y) |
439
+ # | F | The ISO 8601 date format (%Y-%m-%d) |
440
+ # | v | VMS date (%e-%^b-%4Y) |
441
+ # | x | Same as %D |
442
+ # | X | Same as %T |
443
+ # | r | 12-hour time (%I:%M:%S %p) |
444
+ # | R | 24-hour time (%H:%M) |
445
+ # | T | 24-hour time (%H:%M:%S) |
446
+ #
447
+ # The default array contains the following patterns:
448
+ #
449
+ # When a timezone argument (other than `default`) is explicitly provided:
450
+ #
451
+ # ```
452
+ # ['%FT%T.L', '%FT%T', '%F']
453
+ # ```
454
+ #
455
+ # otherwise:
456
+ #
457
+ # ```
458
+ # ['%FT%T.%L %Z', '%FT%T %Z', '%F %Z', '%FT%T.L', '%FT%T', '%F']
459
+ # ```
460
+ #
461
+ # Examples - Converting to Timestamp
462
+ #
463
+ # ```puppet
464
+ # $ts = Timestamp(1473150899) # 2016-09-06 08:34:59 UTC
465
+ # $ts = Timestamp({string=>'2015', format=>'%Y'}) # 2015-01-01 00:00:00.000 UTC
466
+ # $ts = Timestamp('Wed Aug 24 12:13:14 2016', '%c') # 2016-08-24 12:13:14 UTC
467
+ # $ts = Timestamp('Wed Aug 24 12:13:14 2016 PDT', '%c %Z') # 2016-08-24 19:13:14.000 UTC
468
+ # $ts = Timestamp('2016-08-24 12:13:14', '%F %T', 'PST') # 2016-08-24 20:13:14.000 UTC
469
+ # $ts = Timestamp('2016-08-24T12:13:14', default, 'PST') # 2016-08-24 20:13:14.000 UTC
470
+ #
471
+ # ```
472
+ #
473
+ # Conversion to Type
474
+ # ------------------
475
+ # A new `Type` can be create from its `String` representation.
476
+ #
477
+ # @example Creating a type from a string
478
+ #
479
+ # ```puppet
480
+ # $t = Type.new('Integer[10]')
481
+ # ```
482
+ #
483
+ # Conversion to String
484
+ # --------------------
485
+ #
486
+ # Conversion to `String` is the most comprehensive conversion as there are many
487
+ # use cases where a string representation is wanted. The defaults for the many options
488
+ # have been chosen with care to be the most basic "value in textual form" representation.
489
+ # The more advanced forms of formatting are intended to enable writing special purposes formatting
490
+ # functions in the Puppet language.
491
+ #
492
+ # A new string can be created from all other data types. The process is performed in
493
+ # several steps - first the data type of the given value is inferred, then the resulting data type
494
+ # is used to find the most significant format specified for that data type. And finally,
495
+ # the found format is used to convert the given value.
496
+ #
497
+ # The mapping from data type to format is referred to as the *format map*. This map
498
+ # allows different formatting depending on type.
499
+ #
500
+ # @example Positive Integers in Hexadecimal prefixed with '0x', negative in Decimal
501
+ #
502
+ # ```puppet
503
+ # $format_map = {
504
+ # Integer[default, 0] => "%d",
505
+ # Integer[1, default] => "%#x"
506
+ # }
507
+ # String("-1", $format_map) # produces '-1'
508
+ # String("10", $format_map) # produces '0xa'
509
+ # ```
510
+ #
511
+ # A format is specified on the form:
512
+ #
513
+ # ```
514
+ # %[Flags][Width][.Precision]Format
515
+ # ```
516
+ #
517
+ # `Width` is the number of characters into which the value should be fitted. This allocated space is
518
+ # padded if value is shorter. By default it is space padded, and the flag `0` will cause padding with `0`
519
+ # for numerical formats.
520
+ #
521
+ # `Precision` is the number of fractional digits to show for floating point, and the maximum characters
522
+ # included in a string format.
523
+ #
524
+ # Note that all data type supports the formats `s` and `p` with the meaning "default string representation" and
525
+ # "default programmatic string representation" (which for example means that a String is quoted in 'p' format).
526
+ #
527
+ # ### Signatures of String conversion
528
+ #
529
+ # ```puppet
530
+ # type Format = Pattern[/^%([\s\+\-#0\[\{<\(\|]*)([1-9][0-9]*)?(?:\.([0-9]+))?([a-zA-Z])/]
531
+ # type ContainerFormat = Struct[{
532
+ # format => Optional[String],
533
+ # separator => Optional[String],
534
+ # separator2 => Optional[String],
535
+ # string_formats => Hash[Type, Format]
536
+ # }]
537
+ # type TypeMap = Hash[Type, Variant[Format, ContainerFormat]]
538
+ # type Formats = Variant[Default, String[1], TypeMap]
539
+ #
540
+ # function String.new(
541
+ # Any $value,
542
+ # Formats $string_formats
543
+ # )
544
+ # ```
545
+ #
546
+ # Where:
547
+ #
548
+ # * `separator` is the string used to separate entries in an array, or hash (extra space should not be included at
549
+ # the end), defaults to `","`
550
+ # * `separator2` is the separator between key and value in a hash entry (space padding should be included as
551
+ # wanted), defaults to `" => "`.
552
+ # * `string_formats` is a data type to format map for values contained in arrays and hashes - defaults to `{Any => "%p"}`. Note that
553
+ # these nested formats are not applicable to data types that are containers; they are always formatted as per the top level
554
+ # format specification.
555
+ #
556
+ # @example Simple Conversion to String (using defaults)
557
+ #
558
+ # ```puppet
559
+ # $str = String(10) # produces '10'
560
+ # $str = String([10]) # produces '["10"]'
561
+ # ```
562
+ #
563
+ # @example Simple Conversion to String specifying the format for the given value directly
564
+ #
565
+ # ```puppet
566
+ # $str = String(10, "%#x") # produces '0x10'
567
+ # $str = String([10], "%(a") # produces '("10")'
568
+ # ```
569
+ #
570
+ # @example Specifying type for values contained in an array
571
+ #
572
+ # ```puppet
573
+ # $formats = {
574
+ # Array => {
575
+ # format => '%(a',
576
+ # string_formats => { Integer => '%#x' }
577
+ # }
578
+ # }
579
+ # $str = String([1,2,3], $formats) # produces '(0x1, 0x2, 0x3)'
580
+ # ```
581
+ #
582
+ # The given formats are merged with the default formats, and matching of values to convert against format is based on
583
+ # the specificity of the mapped type; for example, different formats can be used for short and long arrays.
584
+ #
585
+ # ### Integer to String
586
+ #
587
+ # | Format | Integer Formats
588
+ # | ------ | ---------------
589
+ # | d | Decimal, negative values produces leading '-'.
590
+ # | x X | Hexadecimal in lower or upper case. Uses ..f/..F for negative values unless + is also used. A `#` adds prefix 0x/0X.
591
+ # | o | Octal. Uses ..0 for negative values unless `+` is also used. A `#` adds prefix 0.
592
+ # | b B | Binary with prefix 'b' or 'B'. Uses ..1/..1 for negative values unless `+` is also used.
593
+ # | c | Numeric value representing a Unicode value, result is a one unicode character string, quoted if alternative flag # is used
594
+ # | s | Same as d, or d in quotes if alternative flag # is used.
595
+ # | p | Same as d.
596
+ # | eEfgGaA | Converts integer to float and formats using the floating point rules.
597
+ #
598
+ # Defaults to `d`.
599
+ #
600
+ # ### Float to String
601
+ #
602
+ # | Format | Float formats
603
+ # | ------ | -------------
604
+ # | f | Floating point in non exponential notation.
605
+ # | e E | Exponential notation with 'e' or 'E'.
606
+ # | g G | Conditional exponential with 'e' or 'E' if exponent < -4 or >= the precision.
607
+ # | a A | Hexadecimal exponential form, using 'x'/'X' as prefix and 'p'/'P' before exponent.
608
+ # | s | Converted to string using format p, then applying string formatting rule, alternate form # quotes result.
609
+ # | p | Same as f format with minimum significant number of fractional digits, prec has no effect.
610
+ # | dxXobBc | Converts float to integer and formats using the integer rules.
611
+ #
612
+ # Defaults to `p`.
613
+ #
614
+ # ### String to String
615
+ #
616
+ # | Format | String
617
+ # | ------ | ------
618
+ # | s | Unquoted string, verbatim output of control chars.
619
+ # | p | Programmatic representation - strings are quoted, interior quotes and control chars are escaped.
620
+ # | C | Each `::` name segment capitalized, quoted if alternative flag `#` is used.
621
+ # | c | Capitalized string, quoted if alternative flag `#` is used.
622
+ # | d | Downcased string, quoted if alternative flag `#` is used.
623
+ # | u | Upcased string, quoted if alternative flag `#` is used.
624
+ # | t | Trims leading and trailing whitespace from the string, quoted if alternative flag `#` is used.
625
+ #
626
+ # Defaults to `s` at top level and `p` inside array or hash.
627
+ #
628
+ # ### Boolean to String
629
+ #
630
+ # | Format | Boolean Formats
631
+ # | ---- | -------------------
632
+ # | t T | String 'true'/'false' or 'True'/'False', first char if alternate form is used (i.e. 't'/'f' or 'T'/'F').
633
+ # | y Y | String 'yes'/'no', 'Yes'/'No', 'y'/'n' or 'Y'/'N' if alternative flag `#` is used.
634
+ # | dxXobB | Numeric value 0/1 in accordance with the given format which must be valid integer format.
635
+ # | eEfgGaA | Numeric value 0.0/1.0 in accordance with the given float format and flags.
636
+ # | s | String 'true' / 'false'.
637
+ # | p | String 'true' / 'false'.
638
+ #
639
+ # ### Regexp to String
640
+ #
641
+ # | Format | Regexp Formats
642
+ # | ---- | --------------
643
+ # | s | No delimiters, quoted if alternative flag `#` is used.
644
+ # | p | Delimiters `/ /`.
645
+ #
646
+ # ### Undef to String
647
+ #
648
+ # | Format | Undef formats
649
+ # | ------ | -------------
650
+ # | s | Empty string, or quoted empty string if alternative flag `#` is used.
651
+ # | p | String 'undef', or quoted '"undef"' if alternative flag `#` is used.
652
+ # | n | String 'nil', or 'null' if alternative flag `#` is used.
653
+ # | dxXobB | String 'NaN'.
654
+ # | eEfgGaA | String 'NaN'.
655
+ # | v | String 'n/a'.
656
+ # | V | String 'N/A'.
657
+ # | u | String 'undef', or 'undefined' if alternative `#` flag is used.
658
+ #
659
+ # ### Default value to String
660
+ #
661
+ # | Format | Default formats
662
+ # | ------ | ---------------
663
+ # | d D | String 'default' or 'Default', alternative form `#` causes value to be quoted.
664
+ # | s | Same as d.
665
+ # | p | Same as d.
666
+ #
667
+ # ### Binary value to String
668
+ #
669
+ # | Format | Default formats
670
+ # | ------ | ---------------
671
+ # | s | binary as unquoted UTF-8 characters (errors if byte sequence is invalid UTF-8). Alternate form escapes non ascii bytes.
672
+ # | p | 'Binary("<base64strict>")'
673
+ # | b | '<base64>' - base64 string with newlines inserted
674
+ # | B | '<base64strict>' - base64 strict string (without newlines inserted)
675
+ # | u | '<base64urlsafe>' - base64 urlsafe string
676
+ # | t | 'Binary' - outputs the name of the type only
677
+ # | T | 'BINARY' - output the name of the type in all caps only
678
+ #
679
+ # * The alternate form flag `#` will quote the binary or base64 text output.
680
+ # * The format `%#s` allows invalid UTF-8 characters and outputs all non ascii bytes
681
+ # as hex escaped characters on the form `\\xHH` where `H` is a hex digit.
682
+ # * The width and precision values are applied to the text part only in `%p` format.
683
+ #
684
+ # ### Array & Tuple to String
685
+ #
686
+ # | Format | Array/Tuple Formats
687
+ # | ------ | -------------
688
+ # | a | Formats with `[ ]` delimiters and `,`, alternate form `#` indents nested arrays/hashes.
689
+ # | s | Same as a.
690
+ # | p | Same as a.
691
+ #
692
+ # See "Flags" `<[({\|` for formatting of delimiters, and "Additional parameters for containers; Array and Hash" for
693
+ # more information about options.
694
+ #
695
+ # The alternate form flag `#` will cause indentation of nested array or hash containers. If width is also set
696
+ # it is taken as the maximum allowed length of a sequence of elements (not including delimiters). If this max length
697
+ # is exceeded, each element will be indented.
698
+ #
699
+ # ### Hash & Struct to String
700
+ #
701
+ # | Format | Hash/Struct Formats
702
+ # | ------ | -------------
703
+ # | h | Formats with `{ }` delimiters, `,` element separator and ` => ` inner element separator unless overridden by flags.
704
+ # | s | Same as h.
705
+ # | p | Same as h.
706
+ # | a | Converts the hash to an array of [k,v] tuples and formats it using array rule(s).
707
+ #
708
+ # See "Flags" `<[({\|` for formatting of delimiters, and "Additional parameters for containers; Array and Hash" for
709
+ # more information about options.
710
+ #
711
+ # The alternate form flag `#` will format each hash key/value entry indented on a separate line.
712
+ #
713
+ # ### Type to String
714
+ #
715
+ # | Format | Array/Tuple Formats
716
+ # | ------ | -------------
717
+ # | s | The same as `p`, quoted if alternative flag `#` is used.
718
+ # | p | Outputs the type in string form as specified by the Puppet Language.
719
+ #
720
+ # ### Flags
721
+ #
722
+ # | Flag | Effect
723
+ # | ------ | ------
724
+ # | (space) | A space instead of `+` for numeric output (`-` is shown), for containers skips delimiters.
725
+ # | # | Alternate format; prefix 0x/0x, 0 (octal) and 0b/0B for binary, Floats force decimal '.'. For g/G keep trailing 0.
726
+ # | + | Show sign +/- depending on value's sign, changes x, X, o, b, B format to not use 2's complement form.
727
+ # | - | Left justify the value in the given width.
728
+ # | 0 | Pad with 0 instead of space for widths larger than value.
729
+ # | <[({\| | Defines an enclosing pair <> [] () {} or \| \| when used with a container type.
730
+ #
731
+ # Conversion to Boolean
732
+ # ---
733
+ #
734
+ # Accepts a single value as argument:
735
+ #
736
+ # * Float 0.0 is `false`, all other float values are `true`
737
+ # * Integer 0 is `false`, all other integer values are `true`
738
+ # * Strings
739
+ # * `true` if 'true', 'yes', 'y' (case independent compare)
740
+ # * `false` if 'false', 'no', 'n' (case independent compare)
741
+ # * Boolean is already boolean and is simply returned
742
+ #
743
+ # Conversion to Array and Tuple
744
+ # ---
745
+ #
746
+ # When given a single value as argument:
747
+ #
748
+ # * A non empty `Hash` is converted to an array matching `Array[Tuple[Any,Any], 1]`.
749
+ # * An empty `Hash` becomes an empty array.
750
+ # * An `Array` is simply returned.
751
+ # * An `Iterable[T]` is turned into an array of `T` instances.
752
+ # * A `Binary` is converted to an `Array[Integer[0,255]]` of byte values
753
+ #
754
+ #
755
+ # When given a second Boolean argument:
756
+ #
757
+ # * if `true`, a value that is not already an array is returned as a one element array.
758
+ # * if `false`, (the default), converts the first argument as shown above.
759
+ #
760
+ # @example Ensuring value is an array
761
+ #
762
+ # ```puppet
763
+ # $arr = Array($value, true)
764
+ # ```
765
+ #
766
+ # Conversion to a `Tuple` works exactly as conversion to an `Array`, only that the constructed array is
767
+ # asserted against the given tuple type.
768
+ #
769
+ # Conversion to Hash and Struct
770
+ # ---
771
+ #
772
+ # Accepts a single value as argument:
773
+ #
774
+ # * An empty `Array` becomes an empty `Hash`
775
+ # * An `Array` matching `Array[Tuple[Any,Any], 1]` is converted to a hash where each tuple describes a key/value entry
776
+ # * An `Array` with an even number of entries is interpreted as `[key1, val1, key2, val2, ...]`
777
+ # * An `Iterable` is turned into an `Array` and then converted to hash as per the array rules
778
+ # * A `Hash` is simply returned
779
+ #
780
+ # Alternatively, a tree can be constructed by giving two values; an array of tuples on the form `[path, value]`
781
+ # (where the `path` is the path from the root of a tree, and `value` the value at that position in the tree), and
782
+ # either the option `'tree'` (do not convert arrays to hashes except the top level), or
783
+ # `'hash_tree'` (convert all arrays to hashes).
784
+ #
785
+ # The tree/hash_tree forms of Hash creation are suited for transforming the result of an iteration
786
+ # using `tree_each` and subsequent filtering or mapping.
787
+ #
788
+ # @example Mapping a hash tree
789
+ #
790
+ # Mapping an arbitrary structure in a way that keeps the structure, but where some values are replaced
791
+ # can be done by using the `tree_each` function, mapping, and then constructing a new Hash from the result:
792
+ #
793
+ # ```puppet
794
+ # # A hash tree with 'water' at different locations
795
+ # $h = { a => { b => { x => 'water'}}, b => { y => 'water'} }
796
+ # # a helper function that turns water into wine
797
+ # function make_wine($x) { if $x == 'water' { 'wine' } else { $x } }
798
+ # # create a flattened tree with water turned into wine
799
+ # $flat_tree = $h.tree_each.map |$entry| { [$entry[0], make_wine($entry[1])] }
800
+ # # create a new Hash and log it
801
+ # notice Hash($flat_tree, 'hash_tree')
802
+ # ```
803
+ #
804
+ # Would notice the hash `{a => {b => {x => wine}}, b => {y => wine}}`
805
+ #
806
+ # Conversion to a `Struct` works exactly as conversion to a `Hash`, only that the constructed hash is
807
+ # asserted against the given struct type.
808
+ #
809
+ # Conversion to a Regexp
810
+ # ---
811
+ # A `String` can be converted into a `Regexp`
812
+ #
813
+ # **Example**: Converting a String into a Regexp
814
+ # ```puppet
815
+ # $s = '[a-z]+\.com'
816
+ # $r = Regexp($s)
817
+ # if('foo.com' =~ $r) {
818
+ # ...
819
+ # }
820
+ # ```
821
+ #
822
+ # Creating a SemVer
823
+ # ---
824
+ #
825
+ # A SemVer object represents a single [Semantic Version](http://semver.org/).
826
+ # It can be created from a String, individual values for its parts, or a hash specifying the value per part.
827
+ # See the specification at [semver.org](http://semver.org/) for the meaning of the SemVer's parts.
828
+ #
829
+ # The signatures are:
830
+ #
831
+ # ```puppet
832
+ # type PositiveInteger = Integer[0,default]
833
+ # type SemVerQualifier = Pattern[/\A(?<part>[0-9A-Za-z-]+)(?:\.\g<part>)*\Z/]
834
+ # type SemVerString = String[1]
835
+ # type SemVerHash =Struct[{
836
+ # major => PositiveInteger,
837
+ # minor => PositiveInteger,
838
+ # patch => PositiveInteger,
839
+ # Optional[prerelease] => SemVerQualifier,
840
+ # Optional[build] => SemVerQualifier
841
+ # }]
842
+ #
843
+ # function SemVer.new(SemVerString $str)
844
+ #
845
+ # function SemVer.new(
846
+ # PositiveInteger $major
847
+ # PositiveInteger $minor
848
+ # PositiveInteger $patch
849
+ # Optional[SemVerQualifier] $prerelease = undef
850
+ # Optional[SemVerQualifier] $build = undef
851
+ # )
852
+ #
853
+ # function SemVer.new(SemVerHash $hash_args)
854
+ # ```
855
+ #
856
+ # @example SemVer and SemVerRange usage
857
+ #
858
+ # ```puppet
859
+ # # As a type, SemVer can describe disjunct ranges which versions can be
860
+ # # matched against - here the type is constructed with two
861
+ # # SemVerRange objects.
862
+ # #
863
+ # $t = SemVer[
864
+ # SemVerRange('>=1.0.0 <2.0.0'),
865
+ # SemVerRange('>=3.0.0 <4.0.0')
866
+ # ]
867
+ # notice(SemVer('1.2.3') =~ $t) # true
868
+ # notice(SemVer('2.3.4') =~ $t) # false
869
+ # notice(SemVer('3.4.5') =~ $t) # true
870
+ # ```
871
+ #
872
+ # Creating a SemVerRange
873
+ # ---
874
+ #
875
+ # A `SemVerRange` object represents a range of `SemVer`. It can be created from
876
+ # a `String`, or from two `SemVer` instances, where either end can be given as
877
+ # a literal `default` to indicate infinity. The string format of a `SemVerRange` is specified by
878
+ # the [Semantic Version Range Grammar](https://github.com/npm/node-semver#ranges).
879
+ #
880
+ # > Use of the comparator sets described in the grammar (joining with `||`) is not supported.
881
+ #
882
+ # The signatures are:
883
+ #
884
+ # ```puppet
885
+ # type SemVerRangeString = String[1]
886
+ # type SemVerRangeHash = Struct[{
887
+ # min => Variant[Default, SemVer],
888
+ # Optional[max] => Variant[Default, SemVer],
889
+ # Optional[exclude_max] => Boolean
890
+ # }]
891
+ #
892
+ # function SemVerRange.new(
893
+ # SemVerRangeString $semver_range_string
894
+ # )
895
+ #
896
+ # function SemVerRange.new(
897
+ # Variant[Default,SemVer] $min
898
+ # Variant[Default,SemVer] $max
899
+ # Optional[Boolean] $exclude_max = undef
900
+ # )
901
+ #
902
+ # function SemVerRange.new(
903
+ # SemVerRangeHash $semver_range_hash
904
+ # )
905
+ # ```
906
+ #
907
+ # For examples of `SemVerRange` use see "Creating a SemVer"
908
+ #
909
+ # Creating a Binary
910
+ # ---
911
+ #
912
+ # A `Binary` object represents a sequence of bytes and it can be created from a String in Base64 format,
913
+ # an Array containing byte values. A Binary can also be created from a Hash containing the value to convert to
914
+ # a `Binary`.
915
+ #
916
+ # The signatures are:
917
+ #
918
+ # ```puppet
919
+ # type ByteInteger = Integer[0,255]
920
+ # type Base64Format = Enum["%b", "%u", "%B", "%s"]
921
+ # type StringHash = Struct[{value => String, "format" => Optional[Base64Format]}]
922
+ # type ArrayHash = Struct[{value => Array[ByteInteger]}]
923
+ # type BinaryArgsHash = Variant[StringHash, ArrayHash]
924
+ #
925
+ # function Binary.new(
926
+ # String $base64_str,
927
+ # Optional[Base64Format] $format
928
+ # )
929
+ #
930
+ #
931
+ # function Binary.new(
932
+ # Array[ByteInteger] $byte_array
933
+ # }
934
+ #
935
+ # # Same as for String, or for Array, but where arguments are given in a Hash.
936
+ # function Binary.new(BinaryArgsHash $hash_args)
937
+ # ```
938
+ #
939
+ # The formats have the following meaning:
940
+ #
941
+ # | format | explanation |
942
+ # | ---- | ---- |
943
+ # | B | The data is in base64 strict encoding
944
+ # | u | The data is in URL safe base64 encoding
945
+ # | b | The data is in base64 encoding, padding as required by base64 strict, is added by default
946
+ # | s | The data is a puppet string. The string must be valid UTF-8, or convertible to UTF-8 or an error is raised.
947
+ # | r | (Ruby Raw) the byte sequence in the given string is used verbatim irrespective of possible encoding errors
948
+ #
949
+ # * The default format is `%B`.
950
+ # * Note that the format `%r` should be used sparingly, or not at all. It exists for backwards compatibility reasons when someone receiving
951
+ # a string from some function and that string should be treated as Binary. Such code should be changed to return a Binary instead of a String.
952
+ #
953
+ # @example Creating a Binary
954
+ #
955
+ # ```puppet
956
+ # # create the binary content "abc"
957
+ # $a = Binary('YWJj')
958
+ #
959
+ # # create the binary content from content in a module's file
960
+ # $b = binary_file('mymodule/mypicture.jpg')
961
+ # ```
962
+ #
963
+ # * Since 4.5.0
964
+ # * Binary type since 4.8.0
965
+ #
966
+ # Creating an instance of a `Type` using the `Init` type.
967
+ # -------
968
+ #
969
+ # The type `Init[T]` describes a value that can be used when instantiating a type. When used as the first argument in a call to `new`, it
970
+ # will dispatch the call to its contained type and optionally augment the parameter list with additional arguments.
971
+ #
972
+ # @example Creating an instance of Integer using Init[Integer]
973
+ #
974
+ # ```puppet
975
+ # # The following declaration
976
+ # $x = Init[Integer].new('128')
977
+ # # is exactly the same as
978
+ # $x = Integer.new('128')
979
+ # ```
980
+ #
981
+ # or, with base 16 and using implicit new
982
+ #
983
+ # ```puppet
984
+ # # The following declaration
985
+ # $x = Init[Integer,16]('80')
986
+ # # is exactly the same as
987
+ # $x = Integer('80', 16)
988
+ # ```
989
+ #
990
+ # @example Creating an instance of String using a predefined format
991
+ #
992
+ # ```puppet
993
+ # $fmt = Init[String,'%#x']
994
+ # notice($fmt(256)) # will notice '0x100'
995
+ # ```
3
996
  #
4
997
  # @since 4.5.0
5
998
  #