openvox 7.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1120) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +15 -0
  3. data/CODEOWNERS +11 -0
  4. data/CODE_OF_CONDUCT.md +70 -0
  5. data/CONTRIBUTING.md +161 -0
  6. data/Gemfile +82 -0
  7. data/Guardfile.example +76 -0
  8. data/LICENSE +202 -0
  9. data/README.md +68 -0
  10. data/Rakefile +160 -0
  11. data/bin/puppet +9 -0
  12. data/conf/environment.conf +18 -0
  13. data/conf/fileserver.conf +32 -0
  14. data/conf/hiera.yaml +11 -0
  15. data/conf/puppet.conf +6 -0
  16. data/examples/enc/regexp_nodes/classes/databases +2 -0
  17. data/examples/enc/regexp_nodes/classes/webservers +2 -0
  18. data/examples/enc/regexp_nodes/environment/development +2 -0
  19. data/examples/enc/regexp_nodes/parameters/service/prod +1 -0
  20. data/examples/enc/regexp_nodes/parameters/service/qa +3 -0
  21. data/examples/enc/regexp_nodes/parameters/service/sandbox +1 -0
  22. data/examples/enc/regexp_nodes/regexp_nodes.rb +270 -0
  23. data/examples/hiera/README.md +91 -0
  24. data/examples/hiera/etc/hiera.yaml +15 -0
  25. data/examples/hiera/etc/hieradb/common.yaml +3 -0
  26. data/examples/hiera/etc/hieradb/dc1.yaml +6 -0
  27. data/examples/hiera/etc/hieradb/development.yaml +2 -0
  28. data/examples/hiera/etc/puppet.conf +3 -0
  29. data/examples/hiera/modules/data/manifests/common.pp +4 -0
  30. data/examples/hiera/modules/ntp/manifests/config.pp +6 -0
  31. data/examples/hiera/modules/ntp/manifests/data.pp +4 -0
  32. data/examples/hiera/modules/ntp/templates/ntp.conf.erb +3 -0
  33. data/examples/hiera/modules/users/manifests/common.pp +4 -0
  34. data/examples/hiera/modules/users/manifests/dc1.pp +4 -0
  35. data/examples/hiera/modules/users/manifests/development.pp +4 -0
  36. data/examples/hiera/site.pp +3 -0
  37. data/examples/nagios/check_puppet.rb +123 -0
  38. data/ext/README.md +13 -0
  39. data/ext/build_defaults.yaml +18 -0
  40. data/ext/debian/puppet.default +4 -0
  41. data/ext/debian/puppet.init +113 -0
  42. data/ext/hiera/hiera.yaml +15 -0
  43. data/ext/osx/puppet.plist +32 -0
  44. data/ext/project_data.yaml +20 -0
  45. data/ext/redhat/client.init +169 -0
  46. data/ext/redhat/client.sysconfig +2 -0
  47. data/ext/solaris/smf/puppet +44 -0
  48. data/ext/solaris/smf/puppet.xml +46 -0
  49. data/ext/suse/client.init +141 -0
  50. data/ext/systemd/puppet.service +26 -0
  51. data/ext/windows/puppet_interactive.bat +6 -0
  52. data/ext/windows/puppet_shell.bat +9 -0
  53. data/ext/windows/run_puppet_interactive.bat +9 -0
  54. data/ext/windows/service/daemon.bat +6 -0
  55. data/ext/windows/service/daemon.rb +225 -0
  56. data/install.rb +499 -0
  57. data/lib/hiera/puppet_function.rb +84 -0
  58. data/lib/hiera/scope.rb +90 -0
  59. data/lib/hiera_puppet.rb +80 -0
  60. data/lib/puppet/agent/disabler.rb +53 -0
  61. data/lib/puppet/agent/locker.rb +46 -0
  62. data/lib/puppet/agent.rb +176 -0
  63. data/lib/puppet/application/agent.rb +523 -0
  64. data/lib/puppet/application/apply.rb +428 -0
  65. data/lib/puppet/application/catalog.rb +4 -0
  66. data/lib/puppet/application/config.rb +5 -0
  67. data/lib/puppet/application/describe.rb +253 -0
  68. data/lib/puppet/application/device.rb +439 -0
  69. data/lib/puppet/application/doc.rb +233 -0
  70. data/lib/puppet/application/epp.rb +5 -0
  71. data/lib/puppet/application/face_base.rb +276 -0
  72. data/lib/puppet/application/facts.rb +9 -0
  73. data/lib/puppet/application/filebucket.rb +318 -0
  74. data/lib/puppet/application/generate.rb +5 -0
  75. data/lib/puppet/application/help.rb +5 -0
  76. data/lib/puppet/application/indirection_base.rb +4 -0
  77. data/lib/puppet/application/lookup.rb +433 -0
  78. data/lib/puppet/application/module.rb +4 -0
  79. data/lib/puppet/application/node.rb +4 -0
  80. data/lib/puppet/application/parser.rb +5 -0
  81. data/lib/puppet/application/plugin.rb +4 -0
  82. data/lib/puppet/application/report.rb +4 -0
  83. data/lib/puppet/application/resource.rb +254 -0
  84. data/lib/puppet/application/script.rb +264 -0
  85. data/lib/puppet/application/ssl.rb +323 -0
  86. data/lib/puppet/application.rb +596 -0
  87. data/lib/puppet/application_support.rb +68 -0
  88. data/lib/puppet/coercion.rb +40 -0
  89. data/lib/puppet/compilable_resource_type.rb +15 -0
  90. data/lib/puppet/concurrent/lock.rb +16 -0
  91. data/lib/puppet/concurrent/synchronized.rb +15 -0
  92. data/lib/puppet/concurrent/thread_local_singleton.rb +17 -0
  93. data/lib/puppet/concurrent.rb +2 -0
  94. data/lib/puppet/configurer/downloader.rb +85 -0
  95. data/lib/puppet/configurer/fact_handler.rb +50 -0
  96. data/lib/puppet/configurer/plugin_handler.rb +59 -0
  97. data/lib/puppet/configurer.rb +755 -0
  98. data/lib/puppet/confine/any.rb +26 -0
  99. data/lib/puppet/confine/boolean.rb +45 -0
  100. data/lib/puppet/confine/exists.rb +19 -0
  101. data/lib/puppet/confine/false.rb +25 -0
  102. data/lib/puppet/confine/feature.rb +17 -0
  103. data/lib/puppet/confine/true.rb +26 -0
  104. data/lib/puppet/confine/variable.rb +59 -0
  105. data/lib/puppet/confine.rb +83 -0
  106. data/lib/puppet/confine_collection.rb +51 -0
  107. data/lib/puppet/confiner.rb +46 -0
  108. data/lib/puppet/context/trusted_information.rb +120 -0
  109. data/lib/puppet/context.rb +188 -0
  110. data/lib/puppet/daemon.rb +182 -0
  111. data/lib/puppet/data_binding.rb +14 -0
  112. data/lib/puppet/datatypes/error.rb +21 -0
  113. data/lib/puppet/datatypes/impl/error.rb +40 -0
  114. data/lib/puppet/datatypes.rb +213 -0
  115. data/lib/puppet/defaults.rb +2277 -0
  116. data/lib/puppet/environments.rb +601 -0
  117. data/lib/puppet/error.rb +138 -0
  118. data/lib/puppet/etc.rb +180 -0
  119. data/lib/puppet/external/dot.rb +325 -0
  120. data/lib/puppet/external/pson/common.rb +374 -0
  121. data/lib/puppet/external/pson/pure/generator.rb +395 -0
  122. data/lib/puppet/external/pson/pure/parser.rb +308 -0
  123. data/lib/puppet/external/pson/pure.rb +15 -0
  124. data/lib/puppet/external/pson/version.rb +8 -0
  125. data/lib/puppet/face/catalog/select.rb +49 -0
  126. data/lib/puppet/face/catalog.rb +165 -0
  127. data/lib/puppet/face/config.rb +267 -0
  128. data/lib/puppet/face/epp.rb +566 -0
  129. data/lib/puppet/face/facts.rb +174 -0
  130. data/lib/puppet/face/generate.rb +66 -0
  131. data/lib/puppet/face/help/action.erb +90 -0
  132. data/lib/puppet/face/help/face.erb +115 -0
  133. data/lib/puppet/face/help/global.erb +16 -0
  134. data/lib/puppet/face/help/man.erb +152 -0
  135. data/lib/puppet/face/help.rb +242 -0
  136. data/lib/puppet/face/module/changes.rb +43 -0
  137. data/lib/puppet/face/module/install.rb +146 -0
  138. data/lib/puppet/face/module/list.rb +272 -0
  139. data/lib/puppet/face/module/uninstall.rb +89 -0
  140. data/lib/puppet/face/module/upgrade.rb +87 -0
  141. data/lib/puppet/face/module.rb +19 -0
  142. data/lib/puppet/face/node/clean.rb +107 -0
  143. data/lib/puppet/face/node.rb +43 -0
  144. data/lib/puppet/face/parser.rb +227 -0
  145. data/lib/puppet/face/plugin.rb +60 -0
  146. data/lib/puppet/face/report.rb +54 -0
  147. data/lib/puppet/face/resource.rb +53 -0
  148. data/lib/puppet/face.rb +12 -0
  149. data/lib/puppet/facter_impl.rb +96 -0
  150. data/lib/puppet/feature/base.rb +76 -0
  151. data/lib/puppet/feature/bolt.rb +3 -0
  152. data/lib/puppet/feature/cfpropertylist.rb +3 -0
  153. data/lib/puppet/feature/eventlog.rb +5 -0
  154. data/lib/puppet/feature/hiera_eyaml.rb +3 -0
  155. data/lib/puppet/feature/hocon.rb +3 -0
  156. data/lib/puppet/feature/libuser.rb +8 -0
  157. data/lib/puppet/feature/msgpack.rb +3 -0
  158. data/lib/puppet/feature/pe_license.rb +4 -0
  159. data/lib/puppet/feature/selinux.rb +3 -0
  160. data/lib/puppet/feature/ssh.rb +3 -0
  161. data/lib/puppet/feature/telnet.rb +9 -0
  162. data/lib/puppet/feature/zlib.rb +5 -0
  163. data/lib/puppet/ffi/posix/constants.rb +14 -0
  164. data/lib/puppet/ffi/posix/functions.rb +24 -0
  165. data/lib/puppet/ffi/posix.rb +10 -0
  166. data/lib/puppet/ffi/windows/api_types.rb +311 -0
  167. data/lib/puppet/ffi/windows/constants.rb +404 -0
  168. data/lib/puppet/ffi/windows/functions.rb +628 -0
  169. data/lib/puppet/ffi/windows/structs.rb +338 -0
  170. data/lib/puppet/ffi/windows.rb +12 -0
  171. data/lib/puppet/file_bucket/dipper.rb +174 -0
  172. data/lib/puppet/file_bucket/file.rb +129 -0
  173. data/lib/puppet/file_bucket.rb +4 -0
  174. data/lib/puppet/file_serving/base.rb +86 -0
  175. data/lib/puppet/file_serving/configuration/parser.rb +113 -0
  176. data/lib/puppet/file_serving/configuration.rb +113 -0
  177. data/lib/puppet/file_serving/content.rb +43 -0
  178. data/lib/puppet/file_serving/fileset.rb +186 -0
  179. data/lib/puppet/file_serving/http_metadata.rb +62 -0
  180. data/lib/puppet/file_serving/metadata.rb +171 -0
  181. data/lib/puppet/file_serving/mount/file.rb +122 -0
  182. data/lib/puppet/file_serving/mount/locales.rb +35 -0
  183. data/lib/puppet/file_serving/mount/modules.rb +26 -0
  184. data/lib/puppet/file_serving/mount/pluginfacts.rb +35 -0
  185. data/lib/puppet/file_serving/mount/plugins.rb +35 -0
  186. data/lib/puppet/file_serving/mount/scripts.rb +24 -0
  187. data/lib/puppet/file_serving/mount/tasks.rb +23 -0
  188. data/lib/puppet/file_serving/mount.rb +38 -0
  189. data/lib/puppet/file_serving/terminus_helper.rb +31 -0
  190. data/lib/puppet/file_serving/terminus_selector.rb +31 -0
  191. data/lib/puppet/file_serving.rb +3 -0
  192. data/lib/puppet/file_system/file_impl.rb +188 -0
  193. data/lib/puppet/file_system/jruby.rb +23 -0
  194. data/lib/puppet/file_system/memory_file.rb +79 -0
  195. data/lib/puppet/file_system/memory_impl.rb +99 -0
  196. data/lib/puppet/file_system/path_pattern.rb +93 -0
  197. data/lib/puppet/file_system/posix.rb +47 -0
  198. data/lib/puppet/file_system/uniquefile.rb +188 -0
  199. data/lib/puppet/file_system/windows.rb +213 -0
  200. data/lib/puppet/file_system.rb +419 -0
  201. data/lib/puppet/forge/cache.rb +60 -0
  202. data/lib/puppet/forge/errors.rb +114 -0
  203. data/lib/puppet/forge/repository.rb +95 -0
  204. data/lib/puppet/forge.rb +259 -0
  205. data/lib/puppet/functions/abs.rb +61 -0
  206. data/lib/puppet/functions/alert.rb +14 -0
  207. data/lib/puppet/functions/all.rb +104 -0
  208. data/lib/puppet/functions/annotate.rb +108 -0
  209. data/lib/puppet/functions/any.rb +109 -0
  210. data/lib/puppet/functions/assert_type.rb +93 -0
  211. data/lib/puppet/functions/binary_file.rb +32 -0
  212. data/lib/puppet/functions/break.rb +47 -0
  213. data/lib/puppet/functions/call.rb +80 -0
  214. data/lib/puppet/functions/camelcase.rb +62 -0
  215. data/lib/puppet/functions/capitalize.rb +61 -0
  216. data/lib/puppet/functions/ceiling.rb +37 -0
  217. data/lib/puppet/functions/chomp.rb +57 -0
  218. data/lib/puppet/functions/chop.rb +67 -0
  219. data/lib/puppet/functions/compare.rb +125 -0
  220. data/lib/puppet/functions/contain.rb +55 -0
  221. data/lib/puppet/functions/convert_to.rb +34 -0
  222. data/lib/puppet/functions/crit.rb +14 -0
  223. data/lib/puppet/functions/debug.rb +14 -0
  224. data/lib/puppet/functions/defined.rb +159 -0
  225. data/lib/puppet/functions/dig.rb +67 -0
  226. data/lib/puppet/functions/downcase.rb +89 -0
  227. data/lib/puppet/functions/each.rb +167 -0
  228. data/lib/puppet/functions/emerg.rb +14 -0
  229. data/lib/puppet/functions/empty.rb +85 -0
  230. data/lib/puppet/functions/epp.rb +49 -0
  231. data/lib/puppet/functions/err.rb +14 -0
  232. data/lib/puppet/functions/eyaml_lookup_key.rb +102 -0
  233. data/lib/puppet/functions/filter.rb +137 -0
  234. data/lib/puppet/functions/find_file.rb +44 -0
  235. data/lib/puppet/functions/find_template.rb +63 -0
  236. data/lib/puppet/functions/flatten.rb +64 -0
  237. data/lib/puppet/functions/floor.rb +37 -0
  238. data/lib/puppet/functions/get.rb +150 -0
  239. data/lib/puppet/functions/getvar.rb +87 -0
  240. data/lib/puppet/functions/group_by.rb +62 -0
  241. data/lib/puppet/functions/hiera.rb +89 -0
  242. data/lib/puppet/functions/hiera_array.rb +81 -0
  243. data/lib/puppet/functions/hiera_hash.rb +92 -0
  244. data/lib/puppet/functions/hiera_include.rb +104 -0
  245. data/lib/puppet/functions/hocon_data.rb +41 -0
  246. data/lib/puppet/functions/import.rb +7 -0
  247. data/lib/puppet/functions/include.rb +53 -0
  248. data/lib/puppet/functions/index.rb +167 -0
  249. data/lib/puppet/functions/info.rb +14 -0
  250. data/lib/puppet/functions/inline_epp.rb +60 -0
  251. data/lib/puppet/functions/join.rb +56 -0
  252. data/lib/puppet/functions/json_data.rb +33 -0
  253. data/lib/puppet/functions/keys.rb +25 -0
  254. data/lib/puppet/functions/length.rb +44 -0
  255. data/lib/puppet/functions/lest.rb +55 -0
  256. data/lib/puppet/functions/lookup.rb +224 -0
  257. data/lib/puppet/functions/lstrip.rb +58 -0
  258. data/lib/puppet/functions/map.rb +135 -0
  259. data/lib/puppet/functions/match.rb +130 -0
  260. data/lib/puppet/functions/max.rb +183 -0
  261. data/lib/puppet/functions/min.rb +182 -0
  262. data/lib/puppet/functions/module_directory.rb +41 -0
  263. data/lib/puppet/functions/new.rb +1011 -0
  264. data/lib/puppet/functions/next.rb +33 -0
  265. data/lib/puppet/functions/notice.rb +14 -0
  266. data/lib/puppet/functions/partition.rb +62 -0
  267. data/lib/puppet/functions/reduce.rb +162 -0
  268. data/lib/puppet/functions/regsubst.rb +101 -0
  269. data/lib/puppet/functions/require.rb +77 -0
  270. data/lib/puppet/functions/return.rb +15 -0
  271. data/lib/puppet/functions/reverse_each.rb +94 -0
  272. data/lib/puppet/functions/round.rb +24 -0
  273. data/lib/puppet/functions/rstrip.rb +58 -0
  274. data/lib/puppet/functions/scanf.rb +44 -0
  275. data/lib/puppet/functions/size.rb +15 -0
  276. data/lib/puppet/functions/slice.rb +124 -0
  277. data/lib/puppet/functions/sort.rb +74 -0
  278. data/lib/puppet/functions/split.rb +76 -0
  279. data/lib/puppet/functions/step.rb +98 -0
  280. data/lib/puppet/functions/strftime.rb +212 -0
  281. data/lib/puppet/functions/strip.rb +58 -0
  282. data/lib/puppet/functions/then.rb +77 -0
  283. data/lib/puppet/functions/tree_each.rb +197 -0
  284. data/lib/puppet/functions/type.rb +72 -0
  285. data/lib/puppet/functions/unique.rb +132 -0
  286. data/lib/puppet/functions/unwrap.rb +59 -0
  287. data/lib/puppet/functions/upcase.rb +89 -0
  288. data/lib/puppet/functions/values.rb +25 -0
  289. data/lib/puppet/functions/versioncmp.rb +40 -0
  290. data/lib/puppet/functions/warning.rb +14 -0
  291. data/lib/puppet/functions/with.rb +32 -0
  292. data/lib/puppet/functions/yaml_data.rb +45 -0
  293. data/lib/puppet/functions.rb +862 -0
  294. data/lib/puppet/generate/models/type/property.rb +70 -0
  295. data/lib/puppet/generate/models/type/type.rb +65 -0
  296. data/lib/puppet/generate/templates/type/pcore.erb +42 -0
  297. data/lib/puppet/generate/type.rb +249 -0
  298. data/lib/puppet/gettext/config.rb +275 -0
  299. data/lib/puppet/gettext/module_translations.rb +42 -0
  300. data/lib/puppet/gettext/stubs.rb +11 -0
  301. data/lib/puppet/graph/key.rb +26 -0
  302. data/lib/puppet/graph/prioritizer.rb +29 -0
  303. data/lib/puppet/graph/rb_tree_map.rb +388 -0
  304. data/lib/puppet/graph/relationship_graph.rb +284 -0
  305. data/lib/puppet/graph/sequential_prioritizer.rb +31 -0
  306. data/lib/puppet/graph/simple_graph.rb +546 -0
  307. data/lib/puppet/graph.rb +9 -0
  308. data/lib/puppet/http/client.rb +525 -0
  309. data/lib/puppet/http/dns.rb +159 -0
  310. data/lib/puppet/http/errors.rb +48 -0
  311. data/lib/puppet/http/external_client.rb +88 -0
  312. data/lib/puppet/http/factory.rb +51 -0
  313. data/lib/puppet/http/pool.rb +172 -0
  314. data/lib/puppet/http/pool_entry.rb +17 -0
  315. data/lib/puppet/http/proxy.rb +137 -0
  316. data/lib/puppet/http/redirector.rb +85 -0
  317. data/lib/puppet/http/resolver/server_list.rb +87 -0
  318. data/lib/puppet/http/resolver/settings.rb +23 -0
  319. data/lib/puppet/http/resolver/srv.rb +41 -0
  320. data/lib/puppet/http/resolver.rb +48 -0
  321. data/lib/puppet/http/response.rb +102 -0
  322. data/lib/puppet/http/response_converter.rb +24 -0
  323. data/lib/puppet/http/response_net_http.rb +42 -0
  324. data/lib/puppet/http/retry_after_handler.rb +77 -0
  325. data/lib/puppet/http/service/ca.rb +101 -0
  326. data/lib/puppet/http/service/compiler.rb +353 -0
  327. data/lib/puppet/http/service/file_server.rb +198 -0
  328. data/lib/puppet/http/service/puppetserver.rb +53 -0
  329. data/lib/puppet/http/service/report.rb +64 -0
  330. data/lib/puppet/http/service.rb +182 -0
  331. data/lib/puppet/http/session.rb +122 -0
  332. data/lib/puppet/http/site.rb +42 -0
  333. data/lib/puppet/http.rb +46 -0
  334. data/lib/puppet/indirector/catalog/compiler.rb +431 -0
  335. data/lib/puppet/indirector/catalog/json.rb +40 -0
  336. data/lib/puppet/indirector/catalog/msgpack.rb +6 -0
  337. data/lib/puppet/indirector/catalog/rest.rb +49 -0
  338. data/lib/puppet/indirector/catalog/store_configs.rb +8 -0
  339. data/lib/puppet/indirector/catalog/yaml.rb +6 -0
  340. data/lib/puppet/indirector/code.rb +6 -0
  341. data/lib/puppet/indirector/data_binding/hiera.rb +7 -0
  342. data/lib/puppet/indirector/data_binding/none.rb +8 -0
  343. data/lib/puppet/indirector/direct_file_server.rb +17 -0
  344. data/lib/puppet/indirector/envelope.rb +11 -0
  345. data/lib/puppet/indirector/errors.rb +5 -0
  346. data/lib/puppet/indirector/exec.rb +38 -0
  347. data/lib/puppet/indirector/face.rb +153 -0
  348. data/lib/puppet/indirector/fact_search.rb +60 -0
  349. data/lib/puppet/indirector/facts/facter.rb +117 -0
  350. data/lib/puppet/indirector/facts/json.rb +27 -0
  351. data/lib/puppet/indirector/facts/memory.rb +9 -0
  352. data/lib/puppet/indirector/facts/network_device.rb +27 -0
  353. data/lib/puppet/indirector/facts/rest.rb +44 -0
  354. data/lib/puppet/indirector/facts/store_configs.rb +11 -0
  355. data/lib/puppet/indirector/facts/yaml.rb +29 -0
  356. data/lib/puppet/indirector/file_bucket_file/file.rb +262 -0
  357. data/lib/puppet/indirector/file_bucket_file/rest.rb +50 -0
  358. data/lib/puppet/indirector/file_bucket_file/selector.rb +53 -0
  359. data/lib/puppet/indirector/file_content/file.rb +7 -0
  360. data/lib/puppet/indirector/file_content/file_server.rb +7 -0
  361. data/lib/puppet/indirector/file_content/rest.rb +35 -0
  362. data/lib/puppet/indirector/file_content/selector.rb +30 -0
  363. data/lib/puppet/indirector/file_content.rb +5 -0
  364. data/lib/puppet/indirector/file_metadata/file.rb +7 -0
  365. data/lib/puppet/indirector/file_metadata/file_server.rb +7 -0
  366. data/lib/puppet/indirector/file_metadata/http.rb +47 -0
  367. data/lib/puppet/indirector/file_metadata/rest.rb +56 -0
  368. data/lib/puppet/indirector/file_metadata/selector.rb +30 -0
  369. data/lib/puppet/indirector/file_metadata.rb +5 -0
  370. data/lib/puppet/indirector/file_server.rb +54 -0
  371. data/lib/puppet/indirector/generic_http.rb +5 -0
  372. data/lib/puppet/indirector/hiera.rb +100 -0
  373. data/lib/puppet/indirector/indirection.rb +372 -0
  374. data/lib/puppet/indirector/json.rb +79 -0
  375. data/lib/puppet/indirector/memory.rb +34 -0
  376. data/lib/puppet/indirector/msgpack.rb +83 -0
  377. data/lib/puppet/indirector/node/exec.rb +70 -0
  378. data/lib/puppet/indirector/node/json.rb +8 -0
  379. data/lib/puppet/indirector/node/memory.rb +10 -0
  380. data/lib/puppet/indirector/node/msgpack.rb +7 -0
  381. data/lib/puppet/indirector/node/plain.rb +21 -0
  382. data/lib/puppet/indirector/node/rest.rb +29 -0
  383. data/lib/puppet/indirector/node/store_configs.rb +8 -0
  384. data/lib/puppet/indirector/node/yaml.rb +7 -0
  385. data/lib/puppet/indirector/none.rb +9 -0
  386. data/lib/puppet/indirector/plain.rb +9 -0
  387. data/lib/puppet/indirector/report/json.rb +34 -0
  388. data/lib/puppet/indirector/report/msgpack.rb +11 -0
  389. data/lib/puppet/indirector/report/processor.rb +60 -0
  390. data/lib/puppet/indirector/report/rest.rb +42 -0
  391. data/lib/puppet/indirector/report/yaml.rb +34 -0
  392. data/lib/puppet/indirector/request.rb +194 -0
  393. data/lib/puppet/indirector/resource/ral.rb +66 -0
  394. data/lib/puppet/indirector/resource/store_configs.rb +12 -0
  395. data/lib/puppet/indirector/resource/validator.rb +8 -0
  396. data/lib/puppet/indirector/rest.rb +64 -0
  397. data/lib/puppet/indirector/store_configs.rb +30 -0
  398. data/lib/puppet/indirector/terminus.rb +176 -0
  399. data/lib/puppet/indirector/yaml.rb +63 -0
  400. data/lib/puppet/indirector.rb +61 -0
  401. data/lib/puppet/info_service/class_information_service.rb +109 -0
  402. data/lib/puppet/info_service/plan_information_service.rb +36 -0
  403. data/lib/puppet/info_service/task_information_service.rb +44 -0
  404. data/lib/puppet/info_service.rb +26 -0
  405. data/lib/puppet/interface/action.rb +406 -0
  406. data/lib/puppet/interface/action_builder.rb +161 -0
  407. data/lib/puppet/interface/action_manager.rb +98 -0
  408. data/lib/puppet/interface/documentation.rb +357 -0
  409. data/lib/puppet/interface/face_collection.rb +137 -0
  410. data/lib/puppet/interface/option.rb +172 -0
  411. data/lib/puppet/interface/option_builder.rb +105 -0
  412. data/lib/puppet/interface/option_manager.rb +106 -0
  413. data/lib/puppet/interface.rb +239 -0
  414. data/lib/puppet/loaders.rb +30 -0
  415. data/lib/puppet/metatype/manager.rb +197 -0
  416. data/lib/puppet/module/plan.rb +159 -0
  417. data/lib/puppet/module/task.rb +283 -0
  418. data/lib/puppet/module.rb +475 -0
  419. data/lib/puppet/module_tool/applications/application.rb +91 -0
  420. data/lib/puppet/module_tool/applications/checksummer.rb +62 -0
  421. data/lib/puppet/module_tool/applications/installer.rb +411 -0
  422. data/lib/puppet/module_tool/applications/uninstaller.rb +119 -0
  423. data/lib/puppet/module_tool/applications/unpacker.rb +100 -0
  424. data/lib/puppet/module_tool/applications/upgrader.rb +282 -0
  425. data/lib/puppet/module_tool/applications.rb +12 -0
  426. data/lib/puppet/module_tool/checksums.rb +49 -0
  427. data/lib/puppet/module_tool/contents_description.rb +89 -0
  428. data/lib/puppet/module_tool/dependency.rb +41 -0
  429. data/lib/puppet/module_tool/errors/base.rb +15 -0
  430. data/lib/puppet/module_tool/errors/installer.rb +93 -0
  431. data/lib/puppet/module_tool/errors/shared.rb +227 -0
  432. data/lib/puppet/module_tool/errors/uninstaller.rb +50 -0
  433. data/lib/puppet/module_tool/errors/upgrader.rb +63 -0
  434. data/lib/puppet/module_tool/errors.rb +11 -0
  435. data/lib/puppet/module_tool/install_directory.rb +45 -0
  436. data/lib/puppet/module_tool/installed_modules.rb +96 -0
  437. data/lib/puppet/module_tool/local_tarball.rb +90 -0
  438. data/lib/puppet/module_tool/metadata.rb +221 -0
  439. data/lib/puppet/module_tool/shared_behaviors.rb +181 -0
  440. data/lib/puppet/module_tool/tar/gnu.rb +19 -0
  441. data/lib/puppet/module_tool/tar/mini.rb +116 -0
  442. data/lib/puppet/module_tool/tar.rb +18 -0
  443. data/lib/puppet/module_tool.rb +194 -0
  444. data/lib/puppet/network/authconfig.rb +7 -0
  445. data/lib/puppet/network/authorization.rb +19 -0
  446. data/lib/puppet/network/client_request.rb +29 -0
  447. data/lib/puppet/network/format.rb +110 -0
  448. data/lib/puppet/network/format_handler.rb +108 -0
  449. data/lib/puppet/network/format_support.rb +139 -0
  450. data/lib/puppet/network/formats.rb +329 -0
  451. data/lib/puppet/network/http/api/indirected_routes.rb +277 -0
  452. data/lib/puppet/network/http/api/indirection_type.rb +32 -0
  453. data/lib/puppet/network/http/api/master/v3/environments.rb +3 -0
  454. data/lib/puppet/network/http/api/master/v3.rb +3 -0
  455. data/lib/puppet/network/http/api/master.rb +3 -0
  456. data/lib/puppet/network/http/api/server/v3/environments.rb +48 -0
  457. data/lib/puppet/network/http/api/server/v3.rb +39 -0
  458. data/lib/puppet/network/http/api/server.rb +10 -0
  459. data/lib/puppet/network/http/api.rb +39 -0
  460. data/lib/puppet/network/http/connection.rb +286 -0
  461. data/lib/puppet/network/http/error.rb +73 -0
  462. data/lib/puppet/network/http/handler.rb +215 -0
  463. data/lib/puppet/network/http/issues.rb +12 -0
  464. data/lib/puppet/network/http/memory_response.rb +13 -0
  465. data/lib/puppet/network/http/request.rb +71 -0
  466. data/lib/puppet/network/http/response.rb +23 -0
  467. data/lib/puppet/network/http/route.rb +101 -0
  468. data/lib/puppet/network/http.rb +28 -0
  469. data/lib/puppet/network/http_pool.rb +77 -0
  470. data/lib/puppet/network/uri.rb +18 -0
  471. data/lib/puppet/network.rb +3 -0
  472. data/lib/puppet/node/environment.rb +635 -0
  473. data/lib/puppet/node/facts.rb +165 -0
  474. data/lib/puppet/node/server_facts.rb +46 -0
  475. data/lib/puppet/node.rb +256 -0
  476. data/lib/puppet/pal/catalog_compiler.rb +108 -0
  477. data/lib/puppet/pal/compiler.rb +222 -0
  478. data/lib/puppet/pal/function_signature.rb +52 -0
  479. data/lib/puppet/pal/json_catalog_encoder.rb +71 -0
  480. data/lib/puppet/pal/pal_api.rb +15 -0
  481. data/lib/puppet/pal/pal_impl.rb +590 -0
  482. data/lib/puppet/pal/plan_signature.rb +71 -0
  483. data/lib/puppet/pal/script_compiler.rb +73 -0
  484. data/lib/puppet/pal/task_signature.rb +58 -0
  485. data/lib/puppet/parameter/boolean.rb +15 -0
  486. data/lib/puppet/parameter/package_options.rb +31 -0
  487. data/lib/puppet/parameter/path.rb +57 -0
  488. data/lib/puppet/parameter/value.rb +91 -0
  489. data/lib/puppet/parameter/value_collection.rb +212 -0
  490. data/lib/puppet/parameter.rb +589 -0
  491. data/lib/puppet/parser/abstract_compiler.rb +36 -0
  492. data/lib/puppet/parser/ast/block_expression.rb +15 -0
  493. data/lib/puppet/parser/ast/branch.rb +19 -0
  494. data/lib/puppet/parser/ast/hostclass.rb +27 -0
  495. data/lib/puppet/parser/ast/leaf.rb +81 -0
  496. data/lib/puppet/parser/ast/node.rb +17 -0
  497. data/lib/puppet/parser/ast/pops_bridge.rb +245 -0
  498. data/lib/puppet/parser/ast/resource.rb +66 -0
  499. data/lib/puppet/parser/ast/resource_instance.rb +10 -0
  500. data/lib/puppet/parser/ast/resourceparam.rb +31 -0
  501. data/lib/puppet/parser/ast/top_level_construct.rb +4 -0
  502. data/lib/puppet/parser/ast.rb +61 -0
  503. data/lib/puppet/parser/catalog_compiler.rb +56 -0
  504. data/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +39 -0
  505. data/lib/puppet/parser/compiler/catalog_validator.rb +33 -0
  506. data/lib/puppet/parser/compiler.rb +615 -0
  507. data/lib/puppet/parser/e4_parser_adapter.rb +60 -0
  508. data/lib/puppet/parser/files.rb +93 -0
  509. data/lib/puppet/parser/functions/assert_type.rb +60 -0
  510. data/lib/puppet/parser/functions/binary_file.rb +24 -0
  511. data/lib/puppet/parser/functions/break.rb +39 -0
  512. data/lib/puppet/parser/functions/contain.rb +30 -0
  513. data/lib/puppet/parser/functions/create_resources.rb +110 -0
  514. data/lib/puppet/parser/functions/defined.rb +107 -0
  515. data/lib/puppet/parser/functions/dig.rb +38 -0
  516. data/lib/puppet/parser/functions/digest.rb +5 -0
  517. data/lib/puppet/parser/functions/each.rb +104 -0
  518. data/lib/puppet/parser/functions/epp.rb +39 -0
  519. data/lib/puppet/parser/functions/fail.rb +11 -0
  520. data/lib/puppet/parser/functions/file.rb +33 -0
  521. data/lib/puppet/parser/functions/filter.rb +79 -0
  522. data/lib/puppet/parser/functions/find_file.rb +28 -0
  523. data/lib/puppet/parser/functions/fqdn_rand.rb +44 -0
  524. data/lib/puppet/parser/functions/generate.rb +37 -0
  525. data/lib/puppet/parser/functions/hiera.rb +103 -0
  526. data/lib/puppet/parser/functions/hiera_array.rb +92 -0
  527. data/lib/puppet/parser/functions/hiera_hash.rb +102 -0
  528. data/lib/puppet/parser/functions/hiera_include.rb +101 -0
  529. data/lib/puppet/parser/functions/include.rb +34 -0
  530. data/lib/puppet/parser/functions/inline_epp.rb +51 -0
  531. data/lib/puppet/parser/functions/inline_template.rb +26 -0
  532. data/lib/puppet/parser/functions/lest.rb +49 -0
  533. data/lib/puppet/parser/functions/lookup.rb +132 -0
  534. data/lib/puppet/parser/functions/map.rb +76 -0
  535. data/lib/puppet/parser/functions/match.rb +43 -0
  536. data/lib/puppet/parser/functions/md5.rb +5 -0
  537. data/lib/puppet/parser/functions/new.rb +991 -0
  538. data/lib/puppet/parser/functions/next.rb +38 -0
  539. data/lib/puppet/parser/functions/realize.rb +20 -0
  540. data/lib/puppet/parser/functions/reduce.rb +137 -0
  541. data/lib/puppet/parser/functions/regsubst.rb +62 -0
  542. data/lib/puppet/parser/functions/require.rb +40 -0
  543. data/lib/puppet/parser/functions/return.rb +92 -0
  544. data/lib/puppet/parser/functions/reverse_each.rb +83 -0
  545. data/lib/puppet/parser/functions/scanf.rb +38 -0
  546. data/lib/puppet/parser/functions/sha1.rb +5 -0
  547. data/lib/puppet/parser/functions/sha256.rb +5 -0
  548. data/lib/puppet/parser/functions/shellquote.rb +61 -0
  549. data/lib/puppet/parser/functions/slice.rb +39 -0
  550. data/lib/puppet/parser/functions/split.rb +28 -0
  551. data/lib/puppet/parser/functions/sprintf.rb +61 -0
  552. data/lib/puppet/parser/functions/step.rb +84 -0
  553. data/lib/puppet/parser/functions/strftime.rb +185 -0
  554. data/lib/puppet/parser/functions/tag.rb +12 -0
  555. data/lib/puppet/parser/functions/tagged.rb +21 -0
  556. data/lib/puppet/parser/functions/template.rb +39 -0
  557. data/lib/puppet/parser/functions/then.rb +73 -0
  558. data/lib/puppet/parser/functions/type.rb +53 -0
  559. data/lib/puppet/parser/functions/versioncmp.rb +30 -0
  560. data/lib/puppet/parser/functions/with.rb +28 -0
  561. data/lib/puppet/parser/functions.rb +321 -0
  562. data/lib/puppet/parser/parser_factory.rb +30 -0
  563. data/lib/puppet/parser/relationship.rb +84 -0
  564. data/lib/puppet/parser/resource/param.rb +35 -0
  565. data/lib/puppet/parser/resource.rb +351 -0
  566. data/lib/puppet/parser/scope.rb +1127 -0
  567. data/lib/puppet/parser/script_compiler.rb +123 -0
  568. data/lib/puppet/parser/templatewrapper.rb +104 -0
  569. data/lib/puppet/parser/type_loader.rb +150 -0
  570. data/lib/puppet/parser.rb +20 -0
  571. data/lib/puppet/plugins/configuration.rb +29 -0
  572. data/lib/puppet/plugins/syntax_checkers.rb +98 -0
  573. data/lib/puppet/plugins.rb +9 -0
  574. data/lib/puppet/pops/adaptable.rb +197 -0
  575. data/lib/puppet/pops/adapters.rb +156 -0
  576. data/lib/puppet/pops/evaluator/access_operator.rb +719 -0
  577. data/lib/puppet/pops/evaluator/callable_signature.rb +107 -0
  578. data/lib/puppet/pops/evaluator/closure.rb +375 -0
  579. data/lib/puppet/pops/evaluator/collector_transformer.rb +234 -0
  580. data/lib/puppet/pops/evaluator/collectors/abstract_collector.rb +86 -0
  581. data/lib/puppet/pops/evaluator/collectors/catalog_collector.rb +29 -0
  582. data/lib/puppet/pops/evaluator/collectors/exported_collector.rb +70 -0
  583. data/lib/puppet/pops/evaluator/collectors/fixed_set_collector.rb +38 -0
  584. data/lib/puppet/pops/evaluator/compare_operator.rb +254 -0
  585. data/lib/puppet/pops/evaluator/deferred_resolver.rb +225 -0
  586. data/lib/puppet/pops/evaluator/epp_evaluator.rb +120 -0
  587. data/lib/puppet/pops/evaluator/evaluator_impl.rb +1317 -0
  588. data/lib/puppet/pops/evaluator/external_syntax_support.rb +46 -0
  589. data/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +82 -0
  590. data/lib/puppet/pops/evaluator/literal_evaluator.rb +100 -0
  591. data/lib/puppet/pops/evaluator/puppet_proc.rb +69 -0
  592. data/lib/puppet/pops/evaluator/relationship_operator.rb +185 -0
  593. data/lib/puppet/pops/evaluator/runtime3_converter.rb +221 -0
  594. data/lib/puppet/pops/evaluator/runtime3_resource_support.rb +119 -0
  595. data/lib/puppet/pops/evaluator/runtime3_support.rb +535 -0
  596. data/lib/puppet/pops/functions/dispatch.rb +107 -0
  597. data/lib/puppet/pops/functions/dispatcher.rb +75 -0
  598. data/lib/puppet/pops/functions/function.rb +139 -0
  599. data/lib/puppet/pops/issue_reporter.rb +137 -0
  600. data/lib/puppet/pops/issues.rb +928 -0
  601. data/lib/puppet/pops/label_provider.rb +90 -0
  602. data/lib/puppet/pops/loader/base_loader.rb +178 -0
  603. data/lib/puppet/pops/loader/dependency_loader.rb +91 -0
  604. data/lib/puppet/pops/loader/gem_support.rb +51 -0
  605. data/lib/puppet/pops/loader/generic_plan_instantiator.rb +28 -0
  606. data/lib/puppet/pops/loader/loader.rb +221 -0
  607. data/lib/puppet/pops/loader/loader_paths.rb +412 -0
  608. data/lib/puppet/pops/loader/module_loaders.rb +556 -0
  609. data/lib/puppet/pops/loader/predefined_loader.rb +28 -0
  610. data/lib/puppet/pops/loader/puppet_function_instantiator.rb +84 -0
  611. data/lib/puppet/pops/loader/puppet_plan_instantiator.rb +93 -0
  612. data/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb +79 -0
  613. data/lib/puppet/pops/loader/ruby_data_type_instantiator.rb +39 -0
  614. data/lib/puppet/pops/loader/ruby_function_instantiator.rb +45 -0
  615. data/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +120 -0
  616. data/lib/puppet/pops/loader/runtime3_type_loader.rb +103 -0
  617. data/lib/puppet/pops/loader/simple_environment_loader.rb +20 -0
  618. data/lib/puppet/pops/loader/static_loader.rb +131 -0
  619. data/lib/puppet/pops/loader/task_instantiator.rb +44 -0
  620. data/lib/puppet/pops/loader/type_definition_instantiator.rb +100 -0
  621. data/lib/puppet/pops/loader/typed_name.rb +54 -0
  622. data/lib/puppet/pops/loader/uri_helper.rb +22 -0
  623. data/lib/puppet/pops/loaders.rb +546 -0
  624. data/lib/puppet/pops/lookup/configured_data_provider.rb +93 -0
  625. data/lib/puppet/pops/lookup/context.rb +199 -0
  626. data/lib/puppet/pops/lookup/data_adapter.rb +27 -0
  627. data/lib/puppet/pops/lookup/data_dig_function_provider.rb +145 -0
  628. data/lib/puppet/pops/lookup/data_hash_function_provider.rb +126 -0
  629. data/lib/puppet/pops/lookup/data_provider.rb +92 -0
  630. data/lib/puppet/pops/lookup/environment_data_provider.rb +35 -0
  631. data/lib/puppet/pops/lookup/explainer.rb +595 -0
  632. data/lib/puppet/pops/lookup/function_provider.rb +110 -0
  633. data/lib/puppet/pops/lookup/global_data_provider.rb +75 -0
  634. data/lib/puppet/pops/lookup/hiera_config.rb +775 -0
  635. data/lib/puppet/pops/lookup/interpolation.rb +155 -0
  636. data/lib/puppet/pops/lookup/invocation.rb +268 -0
  637. data/lib/puppet/pops/lookup/key_recorder.rb +18 -0
  638. data/lib/puppet/pops/lookup/location_resolver.rb +99 -0
  639. data/lib/puppet/pops/lookup/lookup_adapter.rb +528 -0
  640. data/lib/puppet/pops/lookup/lookup_key.rb +99 -0
  641. data/lib/puppet/pops/lookup/lookup_key_function_provider.rb +92 -0
  642. data/lib/puppet/pops/lookup/module_data_provider.rb +89 -0
  643. data/lib/puppet/pops/lookup/sub_lookup.rb +92 -0
  644. data/lib/puppet/pops/lookup.rb +97 -0
  645. data/lib/puppet/pops/merge_strategy.rb +441 -0
  646. data/lib/puppet/pops/migration/migration_checker.rb +58 -0
  647. data/lib/puppet/pops/model/ast.pp +669 -0
  648. data/lib/puppet/pops/model/ast.rb +4675 -0
  649. data/lib/puppet/pops/model/ast_transformer.rb +131 -0
  650. data/lib/puppet/pops/model/factory.rb +1155 -0
  651. data/lib/puppet/pops/model/model_label_provider.rb +134 -0
  652. data/lib/puppet/pops/model/model_tree_dumper.rb +445 -0
  653. data/lib/puppet/pops/model/pn_transformer.rb +385 -0
  654. data/lib/puppet/pops/model/tree_dumper.rb +59 -0
  655. data/lib/puppet/pops/parser/code_merger.rb +29 -0
  656. data/lib/puppet/pops/parser/egrammar.ra +889 -0
  657. data/lib/puppet/pops/parser/eparser.rb +3184 -0
  658. data/lib/puppet/pops/parser/epp_parser.rb +51 -0
  659. data/lib/puppet/pops/parser/epp_support.rb +265 -0
  660. data/lib/puppet/pops/parser/evaluating_parser.rb +162 -0
  661. data/lib/puppet/pops/parser/heredoc_support.rb +153 -0
  662. data/lib/puppet/pops/parser/interpolation_support.rb +249 -0
  663. data/lib/puppet/pops/parser/lexer2.rb +777 -0
  664. data/lib/puppet/pops/parser/lexer_support.rb +221 -0
  665. data/lib/puppet/pops/parser/locatable.rb +23 -0
  666. data/lib/puppet/pops/parser/locator.rb +357 -0
  667. data/lib/puppet/pops/parser/parser_support.rb +251 -0
  668. data/lib/puppet/pops/parser/pn_parser.rb +317 -0
  669. data/lib/puppet/pops/parser/slurp_support.rb +118 -0
  670. data/lib/puppet/pops/patterns.rb +60 -0
  671. data/lib/puppet/pops/pcore.rb +135 -0
  672. data/lib/puppet/pops/pn.rb +236 -0
  673. data/lib/puppet/pops/puppet_stack.rb +61 -0
  674. data/lib/puppet/pops/resource/param.rb +55 -0
  675. data/lib/puppet/pops/resource/resource_type_impl.rb +294 -0
  676. data/lib/puppet/pops/resource/resource_type_set.pcore +22 -0
  677. data/lib/puppet/pops/semantic_error.rb +29 -0
  678. data/lib/puppet/pops/serialization/abstract_reader.rb +180 -0
  679. data/lib/puppet/pops/serialization/abstract_writer.rb +222 -0
  680. data/lib/puppet/pops/serialization/deserializer.rb +80 -0
  681. data/lib/puppet/pops/serialization/extension.rb +158 -0
  682. data/lib/puppet/pops/serialization/from_data_converter.rb +224 -0
  683. data/lib/puppet/pops/serialization/instance_reader.rb +19 -0
  684. data/lib/puppet/pops/serialization/instance_writer.rb +14 -0
  685. data/lib/puppet/pops/serialization/json.rb +297 -0
  686. data/lib/puppet/pops/serialization/json_path.rb +127 -0
  687. data/lib/puppet/pops/serialization/object.rb +70 -0
  688. data/lib/puppet/pops/serialization/serializer.rb +140 -0
  689. data/lib/puppet/pops/serialization/time_factory.rb +67 -0
  690. data/lib/puppet/pops/serialization/to_data_converter.rb +313 -0
  691. data/lib/puppet/pops/serialization/to_stringified_converter.rb +226 -0
  692. data/lib/puppet/pops/serialization.rb +43 -0
  693. data/lib/puppet/pops/time/timespan.rb +716 -0
  694. data/lib/puppet/pops/time/timestamp.rb +160 -0
  695. data/lib/puppet/pops/types/annotatable.rb +36 -0
  696. data/lib/puppet/pops/types/annotation.rb +71 -0
  697. data/lib/puppet/pops/types/class_loader.rb +132 -0
  698. data/lib/puppet/pops/types/implementation_registry.rb +134 -0
  699. data/lib/puppet/pops/types/iterable.rb +365 -0
  700. data/lib/puppet/pops/types/p_binary_type.rb +232 -0
  701. data/lib/puppet/pops/types/p_init_type.rb +238 -0
  702. data/lib/puppet/pops/types/p_meta_type.rb +94 -0
  703. data/lib/puppet/pops/types/p_object_type.rb +1117 -0
  704. data/lib/puppet/pops/types/p_object_type_extension.rb +228 -0
  705. data/lib/puppet/pops/types/p_runtime_type.rb +115 -0
  706. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +190 -0
  707. data/lib/puppet/pops/types/p_sem_ver_type.rb +155 -0
  708. data/lib/puppet/pops/types/p_sensitive_type.rb +83 -0
  709. data/lib/puppet/pops/types/p_timespan_type.rb +192 -0
  710. data/lib/puppet/pops/types/p_timestamp_type.rb +73 -0
  711. data/lib/puppet/pops/types/p_type_set_type.rb +387 -0
  712. data/lib/puppet/pops/types/p_uri_type.rb +190 -0
  713. data/lib/puppet/pops/types/puppet_object.rb +40 -0
  714. data/lib/puppet/pops/types/recursion_guard.rb +136 -0
  715. data/lib/puppet/pops/types/ruby_generator.rb +472 -0
  716. data/lib/puppet/pops/types/ruby_method.rb +31 -0
  717. data/lib/puppet/pops/types/string_converter.rb +1134 -0
  718. data/lib/puppet/pops/types/tree_iterators.rb +254 -0
  719. data/lib/puppet/pops/types/type_acceptor.rb +25 -0
  720. data/lib/puppet/pops/types/type_asserter.rb +47 -0
  721. data/lib/puppet/pops/types/type_assertion_error.rb +27 -0
  722. data/lib/puppet/pops/types/type_calculator.rb +822 -0
  723. data/lib/puppet/pops/types/type_conversion_error.rb +15 -0
  724. data/lib/puppet/pops/types/type_factory.rb +631 -0
  725. data/lib/puppet/pops/types/type_formatter.rb +801 -0
  726. data/lib/puppet/pops/types/type_mismatch_describer.rb +1096 -0
  727. data/lib/puppet/pops/types/type_parser.rb +683 -0
  728. data/lib/puppet/pops/types/type_set_reference.rb +59 -0
  729. data/lib/puppet/pops/types/type_with_members.rb +43 -0
  730. data/lib/puppet/pops/types/types.rb +3633 -0
  731. data/lib/puppet/pops/utils.rb +119 -0
  732. data/lib/puppet/pops/validation/checker4_0.rb +1148 -0
  733. data/lib/puppet/pops/validation/tasks_checker.rb +93 -0
  734. data/lib/puppet/pops/validation/validator_factory_4_0.rb +45 -0
  735. data/lib/puppet/pops/validation.rb +459 -0
  736. data/lib/puppet/pops/visitable.rb +6 -0
  737. data/lib/puppet/pops/visitor.rb +122 -0
  738. data/lib/puppet/pops.rb +121 -0
  739. data/lib/puppet/property/boolean.rb +7 -0
  740. data/lib/puppet/property/ensure.rb +106 -0
  741. data/lib/puppet/property/keyvalue.rb +158 -0
  742. data/lib/puppet/property/list.rb +70 -0
  743. data/lib/puppet/property/ordered_list.rb +29 -0
  744. data/lib/puppet/property.rb +611 -0
  745. data/lib/puppet/provider/aix_object.rb +485 -0
  746. data/lib/puppet/provider/command.rb +25 -0
  747. data/lib/puppet/provider/confine.rb +6 -0
  748. data/lib/puppet/provider/exec/posix.rb +60 -0
  749. data/lib/puppet/provider/exec/shell.rb +25 -0
  750. data/lib/puppet/provider/exec/windows.rb +55 -0
  751. data/lib/puppet/provider/exec.rb +105 -0
  752. data/lib/puppet/provider/file/posix.rb +144 -0
  753. data/lib/puppet/provider/file/windows.rb +152 -0
  754. data/lib/puppet/provider/group/aix.rb +99 -0
  755. data/lib/puppet/provider/group/directoryservice.rb +22 -0
  756. data/lib/puppet/provider/group/groupadd.rb +174 -0
  757. data/lib/puppet/provider/group/ldap.rb +48 -0
  758. data/lib/puppet/provider/group/pw.rb +51 -0
  759. data/lib/puppet/provider/group/windows_adsi.rb +113 -0
  760. data/lib/puppet/provider/ldap.rb +141 -0
  761. data/lib/puppet/provider/nameservice/directoryservice.rb +512 -0
  762. data/lib/puppet/provider/nameservice/objectadd.rb +22 -0
  763. data/lib/puppet/provider/nameservice/pw.rb +21 -0
  764. data/lib/puppet/provider/nameservice.rb +293 -0
  765. data/lib/puppet/provider/network_device.rb +74 -0
  766. data/lib/puppet/provider/package/aix.rb +169 -0
  767. data/lib/puppet/provider/package/appdmg.rb +111 -0
  768. data/lib/puppet/provider/package/apple.rb +47 -0
  769. data/lib/puppet/provider/package/apt.rb +262 -0
  770. data/lib/puppet/provider/package/aptitude.rb +35 -0
  771. data/lib/puppet/provider/package/aptrpm.rb +83 -0
  772. data/lib/puppet/provider/package/blastwave.rb +112 -0
  773. data/lib/puppet/provider/package/dnf.rb +50 -0
  774. data/lib/puppet/provider/package/dnfmodule.rb +141 -0
  775. data/lib/puppet/provider/package/dpkg.rb +192 -0
  776. data/lib/puppet/provider/package/fink.rb +97 -0
  777. data/lib/puppet/provider/package/freebsd.rb +47 -0
  778. data/lib/puppet/provider/package/gem.rb +293 -0
  779. data/lib/puppet/provider/package/hpux.rb +44 -0
  780. data/lib/puppet/provider/package/macports.rb +110 -0
  781. data/lib/puppet/provider/package/nim.rb +291 -0
  782. data/lib/puppet/provider/package/openbsd.rb +260 -0
  783. data/lib/puppet/provider/package/opkg.rb +82 -0
  784. data/lib/puppet/provider/package/pacman.rb +273 -0
  785. data/lib/puppet/provider/package/pip.rb +346 -0
  786. data/lib/puppet/provider/package/pip2.rb +17 -0
  787. data/lib/puppet/provider/package/pip3.rb +17 -0
  788. data/lib/puppet/provider/package/pkg.rb +295 -0
  789. data/lib/puppet/provider/package/pkgdmg.rb +153 -0
  790. data/lib/puppet/provider/package/pkgin.rb +87 -0
  791. data/lib/puppet/provider/package/pkgng.rb +173 -0
  792. data/lib/puppet/provider/package/pkgutil.rb +187 -0
  793. data/lib/puppet/provider/package/portage.rb +310 -0
  794. data/lib/puppet/provider/package/ports.rb +91 -0
  795. data/lib/puppet/provider/package/portupgrade.rb +240 -0
  796. data/lib/puppet/provider/package/puppet_gem.rb +34 -0
  797. data/lib/puppet/provider/package/puppetserver_gem.rb +171 -0
  798. data/lib/puppet/provider/package/rpm.rb +250 -0
  799. data/lib/puppet/provider/package/rug.rb +51 -0
  800. data/lib/puppet/provider/package/sun.rb +133 -0
  801. data/lib/puppet/provider/package/sunfreeware.rb +9 -0
  802. data/lib/puppet/provider/package/tdnf.rb +28 -0
  803. data/lib/puppet/provider/package/up2date.rb +40 -0
  804. data/lib/puppet/provider/package/urpmi.rb +55 -0
  805. data/lib/puppet/provider/package/windows/exe_package.rb +106 -0
  806. data/lib/puppet/provider/package/windows/msi_package.rb +70 -0
  807. data/lib/puppet/provider/package/windows/package.rb +110 -0
  808. data/lib/puppet/provider/package/windows.rb +130 -0
  809. data/lib/puppet/provider/package/yum.rb +387 -0
  810. data/lib/puppet/provider/package/zypper.rb +206 -0
  811. data/lib/puppet/provider/package.rb +59 -0
  812. data/lib/puppet/provider/package_targetable.rb +69 -0
  813. data/lib/puppet/provider/parsedfile.rb +490 -0
  814. data/lib/puppet/provider/service/base.rb +139 -0
  815. data/lib/puppet/provider/service/bsd.rb +51 -0
  816. data/lib/puppet/provider/service/daemontools.rb +193 -0
  817. data/lib/puppet/provider/service/debian.rb +75 -0
  818. data/lib/puppet/provider/service/freebsd.rb +143 -0
  819. data/lib/puppet/provider/service/gentoo.rb +45 -0
  820. data/lib/puppet/provider/service/init.rb +192 -0
  821. data/lib/puppet/provider/service/launchd.rb +384 -0
  822. data/lib/puppet/provider/service/openbsd.rb +100 -0
  823. data/lib/puppet/provider/service/openrc.rb +71 -0
  824. data/lib/puppet/provider/service/openwrt.rb +36 -0
  825. data/lib/puppet/provider/service/rcng.rb +51 -0
  826. data/lib/puppet/provider/service/redhat.rb +72 -0
  827. data/lib/puppet/provider/service/runit.rb +106 -0
  828. data/lib/puppet/provider/service/service.rb +68 -0
  829. data/lib/puppet/provider/service/smf.rb +317 -0
  830. data/lib/puppet/provider/service/src.rb +147 -0
  831. data/lib/puppet/provider/service/systemd.rb +232 -0
  832. data/lib/puppet/provider/service/upstart.rb +385 -0
  833. data/lib/puppet/provider/service/windows.rb +182 -0
  834. data/lib/puppet/provider/user/aix.rb +361 -0
  835. data/lib/puppet/provider/user/directoryservice.rb +680 -0
  836. data/lib/puppet/provider/user/hpux.rb +95 -0
  837. data/lib/puppet/provider/user/ldap.rb +132 -0
  838. data/lib/puppet/provider/user/openbsd.rb +77 -0
  839. data/lib/puppet/provider/user/pw.rb +108 -0
  840. data/lib/puppet/provider/user/user_role_add.rb +239 -0
  841. data/lib/puppet/provider/user/useradd.rb +406 -0
  842. data/lib/puppet/provider/user/windows_adsi.rb +172 -0
  843. data/lib/puppet/provider.rb +612 -0
  844. data/lib/puppet/reference/configuration.rb +97 -0
  845. data/lib/puppet/reference/function.rb +17 -0
  846. data/lib/puppet/reference/indirection.rb +71 -0
  847. data/lib/puppet/reference/metaparameter.rb +33 -0
  848. data/lib/puppet/reference/providers.rb +117 -0
  849. data/lib/puppet/reference/report.rb +20 -0
  850. data/lib/puppet/reference/type.rb +109 -0
  851. data/lib/puppet/relationship.rb +84 -0
  852. data/lib/puppet/reports/http.rb +44 -0
  853. data/lib/puppet/reports/log.rb +14 -0
  854. data/lib/puppet/reports/store.rb +68 -0
  855. data/lib/puppet/reports.rb +93 -0
  856. data/lib/puppet/resource/catalog.rb +654 -0
  857. data/lib/puppet/resource/status.rb +229 -0
  858. data/lib/puppet/resource/type.rb +425 -0
  859. data/lib/puppet/resource/type_collection.rb +231 -0
  860. data/lib/puppet/resource.rb +663 -0
  861. data/lib/puppet/runtime.rb +65 -0
  862. data/lib/puppet/scheduler/job.rb +53 -0
  863. data/lib/puppet/scheduler/scheduler.rb +44 -0
  864. data/lib/puppet/scheduler/splay_job.rb +32 -0
  865. data/lib/puppet/scheduler/timer.rb +13 -0
  866. data/lib/puppet/scheduler.rb +16 -0
  867. data/lib/puppet/settings/alias_setting.rb +37 -0
  868. data/lib/puppet/settings/array_setting.rb +17 -0
  869. data/lib/puppet/settings/autosign_setting.rb +22 -0
  870. data/lib/puppet/settings/base_setting.rb +223 -0
  871. data/lib/puppet/settings/boolean_setting.rb +32 -0
  872. data/lib/puppet/settings/certificate_revocation_setting.rb +21 -0
  873. data/lib/puppet/settings/config_file.rb +146 -0
  874. data/lib/puppet/settings/directory_setting.rb +18 -0
  875. data/lib/puppet/settings/duration_setting.rb +32 -0
  876. data/lib/puppet/settings/enum_setting.rb +16 -0
  877. data/lib/puppet/settings/environment_conf.rb +224 -0
  878. data/lib/puppet/settings/errors.rb +11 -0
  879. data/lib/puppet/settings/file_or_directory_setting.rb +40 -0
  880. data/lib/puppet/settings/file_setting.rb +241 -0
  881. data/lib/puppet/settings/http_extra_headers_setting.rb +25 -0
  882. data/lib/puppet/settings/ini_file.rb +226 -0
  883. data/lib/puppet/settings/integer_setting.rb +17 -0
  884. data/lib/puppet/settings/path_setting.rb +8 -0
  885. data/lib/puppet/settings/port_setting.rb +15 -0
  886. data/lib/puppet/settings/priority_setting.rb +43 -0
  887. data/lib/puppet/settings/server_list_setting.rb +29 -0
  888. data/lib/puppet/settings/string_setting.rb +9 -0
  889. data/lib/puppet/settings/symbolic_enum_setting.rb +17 -0
  890. data/lib/puppet/settings/terminus_setting.rb +14 -0
  891. data/lib/puppet/settings/ttl_setting.rb +51 -0
  892. data/lib/puppet/settings/value_translator.rb +14 -0
  893. data/lib/puppet/settings.rb +1642 -0
  894. data/lib/puppet/ssl/base.rb +149 -0
  895. data/lib/puppet/ssl/certificate.rb +96 -0
  896. data/lib/puppet/ssl/certificate_request.rb +324 -0
  897. data/lib/puppet/ssl/certificate_request_attributes.rb +37 -0
  898. data/lib/puppet/ssl/certificate_signer.rb +39 -0
  899. data/lib/puppet/ssl/digest.rb +20 -0
  900. data/lib/puppet/ssl/error.rb +26 -0
  901. data/lib/puppet/ssl/oids.rb +197 -0
  902. data/lib/puppet/ssl/openssl_loader.rb +24 -0
  903. data/lib/puppet/ssl/ssl_context.rb +25 -0
  904. data/lib/puppet/ssl/ssl_provider.rb +350 -0
  905. data/lib/puppet/ssl/state_machine.rb +474 -0
  906. data/lib/puppet/ssl/verifier.rb +142 -0
  907. data/lib/puppet/ssl.rb +23 -0
  908. data/lib/puppet/syntax_checkers/base64.rb +40 -0
  909. data/lib/puppet/syntax_checkers/epp.rb +34 -0
  910. data/lib/puppet/syntax_checkers/json.rb +35 -0
  911. data/lib/puppet/syntax_checkers/pp.rb +34 -0
  912. data/lib/puppet/syntax_checkers.rb +3 -0
  913. data/lib/puppet/test/test_helper.rb +265 -0
  914. data/lib/puppet/thread_local.rb +4 -0
  915. data/lib/puppet/transaction/additional_resource_generator.rb +220 -0
  916. data/lib/puppet/transaction/event.rb +168 -0
  917. data/lib/puppet/transaction/event_manager.rb +179 -0
  918. data/lib/puppet/transaction/persistence.rb +119 -0
  919. data/lib/puppet/transaction/report.rb +504 -0
  920. data/lib/puppet/transaction/resource_harness.rb +323 -0
  921. data/lib/puppet/transaction.rb +491 -0
  922. data/lib/puppet/trusted_external.rb +41 -0
  923. data/lib/puppet/type/component.rb +89 -0
  924. data/lib/puppet/type/exec.rb +720 -0
  925. data/lib/puppet/type/file/checksum.rb +50 -0
  926. data/lib/puppet/type/file/checksum_value.rb +54 -0
  927. data/lib/puppet/type/file/content.rb +176 -0
  928. data/lib/puppet/type/file/ctime.rb +21 -0
  929. data/lib/puppet/type/file/data_sync.rb +98 -0
  930. data/lib/puppet/type/file/ensure.rb +195 -0
  931. data/lib/puppet/type/file/group.rb +48 -0
  932. data/lib/puppet/type/file/mode.rb +189 -0
  933. data/lib/puppet/type/file/mtime.rb +19 -0
  934. data/lib/puppet/type/file/owner.rb +51 -0
  935. data/lib/puppet/type/file/selcontext.rb +142 -0
  936. data/lib/puppet/type/file/source.rb +379 -0
  937. data/lib/puppet/type/file/target.rb +88 -0
  938. data/lib/puppet/type/file/type.rb +20 -0
  939. data/lib/puppet/type/file.rb +1133 -0
  940. data/lib/puppet/type/filebucket.rb +121 -0
  941. data/lib/puppet/type/group.rb +237 -0
  942. data/lib/puppet/type/notify.rb +47 -0
  943. data/lib/puppet/type/package.rb +713 -0
  944. data/lib/puppet/type/resources.rb +187 -0
  945. data/lib/puppet/type/schedule.rb +441 -0
  946. data/lib/puppet/type/service.rb +309 -0
  947. data/lib/puppet/type/stage.rb +27 -0
  948. data/lib/puppet/type/tidy.rb +376 -0
  949. data/lib/puppet/type/user.rb +859 -0
  950. data/lib/puppet/type/whit.rb +34 -0
  951. data/lib/puppet/type.rb +2676 -0
  952. data/lib/puppet/util/at_fork/noop.rb +18 -0
  953. data/lib/puppet/util/at_fork/solaris.rb +160 -0
  954. data/lib/puppet/util/at_fork.rb +35 -0
  955. data/lib/puppet/util/autoload.rb +215 -0
  956. data/lib/puppet/util/backups.rb +86 -0
  957. data/lib/puppet/util/character_encoding.rb +80 -0
  958. data/lib/puppet/util/checksums.rb +376 -0
  959. data/lib/puppet/util/classgen.rb +228 -0
  960. data/lib/puppet/util/colors.rb +100 -0
  961. data/lib/puppet/util/command_line/puppet_option_parser.rb +87 -0
  962. data/lib/puppet/util/command_line/trollop.rb +825 -0
  963. data/lib/puppet/util/command_line.rb +196 -0
  964. data/lib/puppet/util/constant_inflector.rb +24 -0
  965. data/lib/puppet/util/diff.rb +81 -0
  966. data/lib/puppet/util/docs.rb +128 -0
  967. data/lib/puppet/util/errors.rb +159 -0
  968. data/lib/puppet/util/execution.rb +424 -0
  969. data/lib/puppet/util/execution_stub.rb +26 -0
  970. data/lib/puppet/util/feature.rb +129 -0
  971. data/lib/puppet/util/file_watcher.rb +28 -0
  972. data/lib/puppet/util/fileparsing.rb +408 -0
  973. data/lib/puppet/util/filetype.rb +358 -0
  974. data/lib/puppet/util/http_proxy.rb +4 -0
  975. data/lib/puppet/util/inifile.rb +340 -0
  976. data/lib/puppet/util/instance_loader.rb +66 -0
  977. data/lib/puppet/util/json.rb +92 -0
  978. data/lib/puppet/util/json_lockfile.rb +44 -0
  979. data/lib/puppet/util/ldap/connection.rb +73 -0
  980. data/lib/puppet/util/ldap/generator.rb +42 -0
  981. data/lib/puppet/util/ldap/manager.rb +284 -0
  982. data/lib/puppet/util/ldap.rb +2 -0
  983. data/lib/puppet/util/libuser.conf +15 -0
  984. data/lib/puppet/util/libuser.rb +12 -0
  985. data/lib/puppet/util/limits.rb +12 -0
  986. data/lib/puppet/util/lockfile.rb +66 -0
  987. data/lib/puppet/util/log/destination.rb +49 -0
  988. data/lib/puppet/util/log/destinations.rb +253 -0
  989. data/lib/puppet/util/log.rb +427 -0
  990. data/lib/puppet/util/logging.rb +300 -0
  991. data/lib/puppet/util/metaid.rb +21 -0
  992. data/lib/puppet/util/metric.rb +65 -0
  993. data/lib/puppet/util/monkey_patches.rb +122 -0
  994. data/lib/puppet/util/multi_match.rb +51 -0
  995. data/lib/puppet/util/network_device/base.rb +23 -0
  996. data/lib/puppet/util/network_device/config.rb +105 -0
  997. data/lib/puppet/util/network_device/transport/base.rb +26 -0
  998. data/lib/puppet/util/network_device/transport.rb +5 -0
  999. data/lib/puppet/util/network_device.rb +17 -0
  1000. data/lib/puppet/util/package/version/debian.rb +175 -0
  1001. data/lib/puppet/util/package/version/gem.rb +15 -0
  1002. data/lib/puppet/util/package/version/pip.rb +167 -0
  1003. data/lib/puppet/util/package/version/range/eq.rb +14 -0
  1004. data/lib/puppet/util/package/version/range/gt.rb +14 -0
  1005. data/lib/puppet/util/package/version/range/gt_eq.rb +14 -0
  1006. data/lib/puppet/util/package/version/range/lt.rb +14 -0
  1007. data/lib/puppet/util/package/version/range/lt_eq.rb +14 -0
  1008. data/lib/puppet/util/package/version/range/min_max.rb +21 -0
  1009. data/lib/puppet/util/package/version/range/simple.rb +11 -0
  1010. data/lib/puppet/util/package/version/range.rb +53 -0
  1011. data/lib/puppet/util/package/version/rpm.rb +73 -0
  1012. data/lib/puppet/util/package.rb +40 -0
  1013. data/lib/puppet/util/pidlock.rb +102 -0
  1014. data/lib/puppet/util/platform.rb +70 -0
  1015. data/lib/puppet/util/plist.rb +161 -0
  1016. data/lib/puppet/util/posix.rb +203 -0
  1017. data/lib/puppet/util/profiler/aggregate.rb +85 -0
  1018. data/lib/puppet/util/profiler/around_profiler.rb +67 -0
  1019. data/lib/puppet/util/profiler/logging.rb +48 -0
  1020. data/lib/puppet/util/profiler/object_counts.rb +17 -0
  1021. data/lib/puppet/util/profiler/wall_clock.rb +35 -0
  1022. data/lib/puppet/util/profiler.rb +53 -0
  1023. data/lib/puppet/util/provider_features.rb +179 -0
  1024. data/lib/puppet/util/psych_support.rb +30 -0
  1025. data/lib/puppet/util/rdoc/code_objects.rb +295 -0
  1026. data/lib/puppet/util/rdoc/generators/puppet_generator.rb +912 -0
  1027. data/lib/puppet/util/rdoc/generators/template/puppet/puppet.rb +1085 -0
  1028. data/lib/puppet/util/rdoc/parser/puppet_parser_core.rb +259 -0
  1029. data/lib/puppet/util/rdoc/parser/puppet_parser_rdoc2.rb +14 -0
  1030. data/lib/puppet/util/rdoc/parser.rb +12 -0
  1031. data/lib/puppet/util/rdoc.rb +53 -0
  1032. data/lib/puppet/util/reference.rb +119 -0
  1033. data/lib/puppet/util/resource_template.rb +61 -0
  1034. data/lib/puppet/util/retry_action.rb +46 -0
  1035. data/lib/puppet/util/rpm_compare.rb +193 -0
  1036. data/lib/puppet/util/rubygems.rb +67 -0
  1037. data/lib/puppet/util/run_mode.rb +122 -0
  1038. data/lib/puppet/util/selinux.rb +297 -0
  1039. data/lib/puppet/util/skip_tags.rb +13 -0
  1040. data/lib/puppet/util/splayer.rb +18 -0
  1041. data/lib/puppet/util/storage.rb +100 -0
  1042. data/lib/puppet/util/suidmanager.rb +166 -0
  1043. data/lib/puppet/util/symbolic_file_mode.rb +156 -0
  1044. data/lib/puppet/util/tag_set.rb +27 -0
  1045. data/lib/puppet/util/tagging.rb +132 -0
  1046. data/lib/puppet/util/terminal.rb +16 -0
  1047. data/lib/puppet/util/user_attr.rb +21 -0
  1048. data/lib/puppet/util/warnings.rb +31 -0
  1049. data/lib/puppet/util/watched_file.rb +37 -0
  1050. data/lib/puppet/util/watcher/change_watcher.rb +33 -0
  1051. data/lib/puppet/util/watcher/periodic_watcher.rb +37 -0
  1052. data/lib/puppet/util/watcher/timer.rb +19 -0
  1053. data/lib/puppet/util/watcher.rb +17 -0
  1054. data/lib/puppet/util/windows/access_control_entry.rb +84 -0
  1055. data/lib/puppet/util/windows/access_control_list.rb +113 -0
  1056. data/lib/puppet/util/windows/adsi.rb +654 -0
  1057. data/lib/puppet/util/windows/com.rb +225 -0
  1058. data/lib/puppet/util/windows/daemon.rb +343 -0
  1059. data/lib/puppet/util/windows/error.rb +84 -0
  1060. data/lib/puppet/util/windows/eventlog.rb +187 -0
  1061. data/lib/puppet/util/windows/file.rb +355 -0
  1062. data/lib/puppet/util/windows/monkey_patches/process.rb +414 -0
  1063. data/lib/puppet/util/windows/principal.rb +201 -0
  1064. data/lib/puppet/util/windows/process.rb +364 -0
  1065. data/lib/puppet/util/windows/registry.rb +441 -0
  1066. data/lib/puppet/util/windows/root_certs.rb +108 -0
  1067. data/lib/puppet/util/windows/security.rb +907 -0
  1068. data/lib/puppet/util/windows/security_descriptor.rb +62 -0
  1069. data/lib/puppet/util/windows/service.rb +696 -0
  1070. data/lib/puppet/util/windows/sid.rb +289 -0
  1071. data/lib/puppet/util/windows/string.rb +15 -0
  1072. data/lib/puppet/util/windows/user.rb +550 -0
  1073. data/lib/puppet/util/windows.rb +51 -0
  1074. data/lib/puppet/util/yaml.rb +65 -0
  1075. data/lib/puppet/util.rb +808 -0
  1076. data/lib/puppet/vendor/require_vendored.rb +4 -0
  1077. data/lib/puppet/vendor.rb +57 -0
  1078. data/lib/puppet/version.rb +95 -0
  1079. data/lib/puppet/x509/cert_provider.rb +369 -0
  1080. data/lib/puppet/x509/pem_store.rb +55 -0
  1081. data/lib/puppet/x509.rb +11 -0
  1082. data/lib/puppet.rb +345 -0
  1083. data/lib/puppet_pal.rb +8 -0
  1084. data/lib/puppet_x.rb +14 -0
  1085. data/locales/config.yaml +29 -0
  1086. data/locales/en/puppet.po +19 -0
  1087. data/locales/puppet.pot +20 -0
  1088. data/man/man5/puppet.conf.5 +2198 -0
  1089. data/man/man8/puppet-agent.8 +203 -0
  1090. data/man/man8/puppet-apply.8 +100 -0
  1091. data/man/man8/puppet-catalog.8 +291 -0
  1092. data/man/man8/puppet-config.8 +151 -0
  1093. data/man/man8/puppet-describe.8 +51 -0
  1094. data/man/man8/puppet-device.8 +119 -0
  1095. data/man/man8/puppet-doc.8 +46 -0
  1096. data/man/man8/puppet-epp.8 +377 -0
  1097. data/man/man8/puppet-facts.8 +234 -0
  1098. data/man/man8/puppet-filebucket.8 +166 -0
  1099. data/man/man8/puppet-generate.8 +84 -0
  1100. data/man/man8/puppet-help.8 +67 -0
  1101. data/man/man8/puppet-lookup.8 +107 -0
  1102. data/man/man8/puppet-module.8 +325 -0
  1103. data/man/man8/puppet-node.8 +163 -0
  1104. data/man/man8/puppet-parser.8 +130 -0
  1105. data/man/man8/puppet-plugin.8 +73 -0
  1106. data/man/man8/puppet-report.8 +127 -0
  1107. data/man/man8/puppet-resource.8 +88 -0
  1108. data/man/man8/puppet-script.8 +70 -0
  1109. data/man/man8/puppet-ssl.8 +63 -0
  1110. data/man/man8/puppet.8 +28 -0
  1111. data/tasks/benchmark.rake +180 -0
  1112. data/tasks/ci.rake +24 -0
  1113. data/tasks/generate_ast_model.rake +90 -0
  1114. data/tasks/generate_cert_fixtures.rake +194 -0
  1115. data/tasks/manpages.rake +67 -0
  1116. data/tasks/memwalk.rake +195 -0
  1117. data/tasks/parallel.rake +410 -0
  1118. data/tasks/parser.rake +22 -0
  1119. data/tasks/yard.rake +59 -0
  1120. metadata +1324 -0
@@ -0,0 +1,3633 @@
1
+ require_relative 'iterable'
2
+ require_relative 'recursion_guard'
3
+ require_relative 'type_acceptor'
4
+ require_relative 'type_asserter'
5
+ require_relative 'type_assertion_error'
6
+ require_relative 'type_conversion_error'
7
+ require_relative 'type_formatter'
8
+ require_relative 'type_calculator'
9
+ require_relative 'type_factory'
10
+ require_relative 'type_parser'
11
+ require_relative 'class_loader'
12
+ require_relative 'type_mismatch_describer'
13
+ require_relative 'puppet_object'
14
+
15
+ module Puppet::Pops
16
+ module Types
17
+
18
+ # The EMPTY_xxx declarations is for backward compatibility. They should not be explicitly referenced
19
+
20
+ # @api private
21
+ # @deprecated
22
+ EMPTY_HASH = Puppet::Pops::EMPTY_HASH
23
+
24
+ # @api private
25
+ # @deprecated
26
+ EMPTY_ARRAY = Puppet::Pops::EMPTY_ARRAY
27
+
28
+ # @api private
29
+ # @deprecated
30
+ EMPTY_STRING = Puppet::Pops::EMPTY_STRING
31
+
32
+ # The Types model is a model of Puppet Language types.
33
+ #
34
+ # The {TypeCalculator} should be used to answer questions about types. The {TypeFactory} or {TypeParser} should be used
35
+ # to create an instance of a type whenever one is needed.
36
+ #
37
+ # The implementation of the Types model contains methods that are required for the type objects to behave as
38
+ # expected when comparing them and using them as keys in hashes. (No other logic is, or should be included directly in
39
+ # the model's classes).
40
+ #
41
+ # @api public
42
+ #
43
+ class TypedModelObject < Object
44
+ include PuppetObject
45
+ include Visitable
46
+ include Adaptable
47
+
48
+ def self._pcore_type
49
+ @type
50
+ end
51
+
52
+ def self.create_ptype(loader, ir, parent_name, attributes_hash = EMPTY_HASH)
53
+ @type = Pcore::create_object_type(loader, ir, self, "Pcore::#{simple_name}Type", "Pcore::#{parent_name}", attributes_hash)
54
+ end
55
+
56
+ def self.register_ptypes(loader, ir)
57
+ types = [
58
+ Annotation.register_ptype(loader, ir),
59
+ RubyMethod.register_ptype(loader, ir),
60
+ ]
61
+ Types.constants.each do |c|
62
+ next if c == :PType || c == :PHostClassType
63
+ cls = Types.const_get(c)
64
+ next unless cls.is_a?(Class) && cls < self
65
+ type = cls.register_ptype(loader, ir)
66
+ types << type unless type.nil?
67
+ end
68
+ types.each { |type| type.resolve(loader) }
69
+ end
70
+ end
71
+
72
+ # Base type for all types
73
+ # @api public
74
+ #
75
+ class PAnyType < TypedModelObject
76
+
77
+ def self.register_ptype(loader, ir)
78
+ @type = Pcore::create_object_type(loader, ir, self, 'Pcore::AnyType', 'Any', EMPTY_HASH)
79
+ end
80
+
81
+ def self.create(*args)
82
+ # NOTE! Important to use self::DEFAULT and not just DEFAULT since the latter yields PAnyType::DEFAULT
83
+ args.empty? ? self::DEFAULT : new(*args)
84
+ end
85
+
86
+ # Accept a visitor that will be sent the message `visit`, once with `self` as the
87
+ # argument. The visitor will then visit all types that this type contains.
88
+ #
89
+ def accept(visitor, guard)
90
+ visitor.visit(self, guard)
91
+ end
92
+
93
+ # Checks if _o_ is a type that is assignable to this type.
94
+ # If _o_ is a `Class` then it is first converted to a type.
95
+ # If _o_ is a Variant, then it is considered assignable when all its types are assignable
96
+ #
97
+ # The check for assignable must be guarded against self recursion since `self`, the given type _o_,
98
+ # or both, might be a `TypeAlias`. The initial caller of this method will typically never care
99
+ # about this and hence pass only the first argument, but as soon as a check of a contained type
100
+ # encounters a `TypeAlias`, then a `RecursionGuard` instance is created and passed on in all
101
+ # subsequent calls. The recursion is allowed to continue until self recursion has been detected in
102
+ # both `self` and in the given type. At that point the given type is considered to be assignable
103
+ # to `self` since all checks up to that point were positive.
104
+ #
105
+ # @param o [Class,PAnyType] the class or type to test
106
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
107
+ # @return [Boolean] `true` when _o_ is assignable to this type
108
+ # @api public
109
+ def assignable?(o, guard = nil)
110
+ case o
111
+ when Class
112
+ # Safe to call _assignable directly since a Class never is a Unit or Variant
113
+ _assignable?(TypeCalculator.singleton.type(o), guard)
114
+ when PUnitType
115
+ true
116
+ when PTypeAliasType
117
+ # An alias may contain self recursive constructs.
118
+ if o.self_recursion?
119
+ guard ||= RecursionGuard.new
120
+ if guard.add_that(o) == RecursionGuard::SELF_RECURSION_IN_BOTH
121
+ # Recursion detected both in self and other. This means that other is assignable
122
+ # to self. This point would not have been reached otherwise
123
+ true
124
+ else
125
+ assignable?(o.resolved_type, guard)
126
+ end
127
+ else
128
+ assignable?(o.resolved_type, guard)
129
+ end
130
+ when PVariantType
131
+ # Assignable if all contained types are assignable, or if this is exactly Any
132
+ return true if self.class == PAnyType
133
+ # An empty variant may be assignable to NotUndef[T] if T is assignable to empty variant
134
+ return _assignable?(o, guard) if is_a?(PNotUndefType) && o.types.empty?
135
+ !o.types.empty? && o.types.all? { |vt| assignable?(vt, guard) }
136
+ when POptionalType
137
+ # Assignable if undef and contained type is assignable
138
+ assignable?(PUndefType::DEFAULT) && (o.type.nil? || assignable?(o.type))
139
+ when PNotUndefType
140
+ if !(o.type.nil? || o.type.assignable?(PUndefType::DEFAULT))
141
+ assignable?(o.type, guard)
142
+ else
143
+ _assignable?(o, guard)
144
+ end
145
+ else
146
+ _assignable?(o, guard)
147
+ end
148
+ end
149
+
150
+ # Returns `true` if this instance is a callable that accepts the given _args_type_ type
151
+ #
152
+ # @param args_type [PAnyType] the arguments to test
153
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
154
+ # @return [Boolean] `true` if this instance is a callable that accepts the given _args_
155
+ def callable?(args_type, guard = nil)
156
+ args_type.is_a?(PAnyType) && kind_of_callable? && args_type.callable_args?(self, guard)
157
+ end
158
+
159
+ # Returns `true` if this instance is a callable that accepts the given _args_
160
+ #
161
+ # @param args [Array] the arguments to test
162
+ # @param block [Proc] block, or nil if not called with a block
163
+ # @return [Boolean] `true` if this instance is a callable that accepts the given _args_
164
+ def callable_with?(args, block = nil)
165
+ false
166
+ end
167
+
168
+ # Returns `true` if this instance is considered valid as arguments to the given `callable`
169
+ # @param callable [PAnyType] the callable
170
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
171
+ # @return [Boolean] `true` if this instance is considered valid as arguments to the given `callable`
172
+ # @api private
173
+ def callable_args?(callable, guard)
174
+ false
175
+ end
176
+
177
+ # Called from the `PTypeAliasType` when it detects self recursion. The default is to do nothing
178
+ # but some self recursive constructs are illegal such as when a `PObjectType` somehow inherits itself
179
+ # @param originator [PTypeAliasType] the starting point for the check
180
+ # @raise Puppet::Error if an illegal self recursion is detected
181
+ # @api private
182
+ def check_self_recursion(originator)
183
+ end
184
+
185
+ # Generalizes value specific types. Types that are not value specific will return `self` otherwise
186
+ # the generalized type is returned.
187
+ #
188
+ # @return [PAnyType] The generalized type
189
+ # @api public
190
+ def generalize
191
+ # Applicable to all types that have no variables
192
+ self
193
+ end
194
+
195
+ # Returns the loader that loaded this type.
196
+ # @return [Loaders::Loader] the loader
197
+ def loader
198
+ Loaders.static_loader
199
+ end
200
+
201
+ # Normalizes the type. This does not change the characteristics of the type but it will remove duplicates
202
+ # and constructs like NotUndef[T] where T is not assignable from Undef and change Variant[*T] where all
203
+ # T are enums into an Enum.
204
+ #
205
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
206
+ # @return [PAnyType] The iterable type that this type is assignable to or `nil`
207
+ # @api public
208
+ def normalize(guard = nil)
209
+ self
210
+ end
211
+
212
+ # Called from the TypeParser once it has found a type using the Loader to enable that this type can
213
+ # resolve internal type expressions using a loader. Presently, this method is a no-op for all types
214
+ # except the {{PTypeAliasType}}.
215
+ #
216
+ # @param loader [Loader::Loader] loader to use
217
+ # @return [PTypeAliasType] the receiver of the call, i.e. `self`
218
+ # @api private
219
+ def resolve(loader)
220
+ self
221
+ end
222
+
223
+ # Responds `true` for all callables, variants of callables and unless _optional_ is
224
+ # false, all optional callables.
225
+ # @param optional [Boolean]
226
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
227
+ # @return [Boolean] `true`if this type is considered callable
228
+ # @api private
229
+ def kind_of_callable?(optional = true, guard = nil)
230
+ false
231
+ end
232
+
233
+ # Returns `true` if an instance of this type is iterable, `false` otherwise
234
+ # The method #iterable_type must produce a `PIterableType` instance when this
235
+ # method returns `true`
236
+ #
237
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
238
+ # @return [Boolean] flag to indicate if instances of this type is iterable.
239
+ def iterable?(guard = nil)
240
+ false
241
+ end
242
+
243
+ # Returns the `PIterableType` that this type should be assignable to, or `nil` if no such type exists.
244
+ # A type that returns a `PIterableType` must respond `true` to `#iterable?`.
245
+ #
246
+ # @example
247
+ # Any Collection[T] is assignable to an Iterable[T]
248
+ # A String is assignable to an Iterable[String] iterating over the strings characters
249
+ # An Integer is assignable to an Iterable[Integer] iterating over the 'times' enumerator
250
+ # A Type[T] is assignable to an Iterable[Type[T]] if T is an Integer or Enum
251
+ #
252
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
253
+ # @return [PIterableType,nil] The iterable type that this type is assignable to or `nil`
254
+ # @api private
255
+ def iterable_type(guard = nil)
256
+ nil
257
+ end
258
+
259
+ def hash
260
+ self.class.hash
261
+ end
262
+
263
+ # Returns true if the given argument _o_ is an instance of this type
264
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
265
+ # @return [Boolean]
266
+ # @api public
267
+ def instance?(o, guard = nil)
268
+ true
269
+ end
270
+
271
+ # An object is considered to really be an instance of a type when something other than a
272
+ # TypeAlias or a Variant responds true to a call to {#instance?}.
273
+ #
274
+ # @return [Integer] -1 = is not instance, 0 = recursion detected, 1 = is instance
275
+ # @api private
276
+ def really_instance?(o, guard = nil)
277
+ instance?(o, guard) ? 1 : -1
278
+ end
279
+
280
+ def eql?(o)
281
+ self.class == o.class
282
+ end
283
+
284
+ def ==(o)
285
+ eql?(o)
286
+ end
287
+
288
+ def simple_name
289
+ self.class.simple_name
290
+ end
291
+
292
+ # Strips the class name from all module prefixes, the leading 'P' and the ending 'Type'. I.e.
293
+ # an instance of PVariantType will return 'Variant'
294
+ # @return [String] the simple name of this type
295
+ def self.simple_name
296
+ @simple_name ||= (
297
+ n = name
298
+ n[n.rindex(DOUBLE_COLON)+3..n.size-5].freeze
299
+ )
300
+ end
301
+
302
+ def to_alias_expanded_s
303
+ TypeFormatter.new.alias_expanded_string(self)
304
+ end
305
+
306
+ def to_s
307
+ TypeFormatter.string(self)
308
+ end
309
+
310
+ # Returns the name of the type, without parameters
311
+ # @return [String] the name of the type
312
+ # @api public
313
+ def name
314
+ simple_name
315
+ end
316
+
317
+ def create(*args)
318
+ Loaders.find_loader(nil).load(:function, 'new').call({}, self, *args)
319
+ end
320
+
321
+ # Create an instance of this type.
322
+ # The default implementation will just dispatch the call to the class method with the
323
+ # same name and pass `self` as the first argument.
324
+ #
325
+ # @return [Function] the created function
326
+ # @raises ArgumentError
327
+ #
328
+ def new_function
329
+ self.class.new_function(self)
330
+ end
331
+
332
+ # This default implementation of of a new_function raises an Argument Error.
333
+ # Types for which creating a new instance is supported, should create and return
334
+ # a Puppet Function class by using Puppet:Loaders.create_loaded_function(:new, loader)
335
+ # and return that result.
336
+ #
337
+ # @param type [PAnyType] the type to create a new function for
338
+ # @return [Function] the created function
339
+ # @raises ArgumentError
340
+ #
341
+ def self.new_function(type)
342
+ raise ArgumentError.new("Creation of new instance of type '#{type}' is not supported")
343
+ end
344
+
345
+ # Answers the question if instances of this type can represent themselves as a string that
346
+ # can then be passed to the create method
347
+ #
348
+ # @return [Boolean] whether or not the instance has a canonical string representation
349
+ def roundtrip_with_string?
350
+ false
351
+ end
352
+
353
+ # The default instance of this type. Each type in the type system has this constant
354
+ # declared.
355
+ #
356
+ DEFAULT = PAnyType.new
357
+
358
+ protected
359
+
360
+ # @api private
361
+ def _assignable?(o, guard)
362
+ o.is_a?(PAnyType)
363
+ end
364
+
365
+ # Produces the tuple entry at the given index given a tuple type, its from/to constraints on the last
366
+ # type, and an index.
367
+ # Produces nil if the index is out of bounds
368
+ # from must be less than to, and from may not be less than 0
369
+ #
370
+ # @api private
371
+ #
372
+ def tuple_entry_at(tuple_t, to, index)
373
+ regular = (tuple_t.types.size - 1)
374
+ if index < regular
375
+ tuple_t.types[index]
376
+ elsif index < regular + to
377
+ # in the varargs part
378
+ tuple_t.types[-1]
379
+ else
380
+ nil
381
+ end
382
+ end
383
+
384
+ # Applies a transformation by sending the given _method_ and _method_args_ to each of the types of the given array
385
+ # and collecting the results in a new array. If all transformation calls returned the type instance itself (i.e. no
386
+ # transformation took place), then this method will return `self`. If a transformation did occur, then this method
387
+ # will either return the transformed array or in case a block was given, the result of calling a given block with
388
+ # the transformed array.
389
+ #
390
+ # @param types [Array<PAnyType>] the array of types to transform
391
+ # @param method [Symbol] The method to call on each type
392
+ # @param method_args [Object] The arguments to pass to the method, if any
393
+ # @return [Object] self, the transformed array, or the result of calling a given block with the transformed array
394
+ # @yieldparam altered_types [Array<PAnyType>] the altered type array
395
+ # @api private
396
+ def alter_type_array(types, method, *method_args)
397
+ modified = false
398
+ modified_types = types.map do |t|
399
+ t_mod = t.send(method, *method_args)
400
+ modified = !t.equal?(t_mod) unless modified
401
+ t_mod
402
+ end
403
+ if modified
404
+ block_given? ? yield(modified_types) : modified_types
405
+ else
406
+ self
407
+ end
408
+ end
409
+ end
410
+
411
+ # @abstract Encapsulates common behavior for a type that contains one type
412
+ # @api public
413
+ class PTypeWithContainedType < PAnyType
414
+ def self.register_ptype(loader, ir)
415
+ # Abstract type. It doesn't register anything
416
+ end
417
+
418
+ attr_reader :type
419
+
420
+ def initialize(type)
421
+ @type = type
422
+ end
423
+
424
+ def accept(visitor, guard)
425
+ super
426
+ @type.accept(visitor, guard) unless @type.nil?
427
+ end
428
+
429
+ def generalize
430
+ if @type.nil?
431
+ self.class::DEFAULT
432
+ else
433
+ ge_type = @type.generalize
434
+ @type.equal?(ge_type) ? self : self.class.new(ge_type)
435
+ end
436
+ end
437
+
438
+ def normalize(guard = nil)
439
+ if @type.nil?
440
+ self.class::DEFAULT
441
+ else
442
+ ne_type = @type.normalize(guard)
443
+ @type.equal?(ne_type) ? self : self.class.new(ne_type)
444
+ end
445
+ end
446
+
447
+ def hash
448
+ self.class.hash ^ @type.hash
449
+ end
450
+
451
+ def eql?(o)
452
+ self.class == o.class && @type == o.type
453
+ end
454
+
455
+ def resolve(loader)
456
+ rtype = @type
457
+ rtype = rtype.resolve(loader) unless rtype.nil?
458
+ rtype.equal?(@type) ? self : self.class.new(rtype)
459
+ end
460
+ end
461
+
462
+ # The type of types.
463
+ # @api public
464
+ #
465
+ class PTypeType < PTypeWithContainedType
466
+
467
+ def self.register_ptype(loader, ir)
468
+ create_ptype(loader, ir, 'AnyType',
469
+ 'type' => {
470
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
471
+ KEY_VALUE => nil
472
+ }
473
+ )
474
+ end
475
+
476
+ # Returns a new function that produces a Type instance
477
+ #
478
+ def self.new_function(type)
479
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_type, type.loader) do
480
+ dispatch :from_string do
481
+ param 'String[1]', :type_string
482
+ end
483
+
484
+ def from_string(type_string)
485
+ TypeParser.singleton.parse(type_string, loader)
486
+ end
487
+ end
488
+ end
489
+
490
+ def instance?(o, guard = nil)
491
+ if o.is_a?(PAnyType)
492
+ type.nil? || type.assignable?(o, guard)
493
+ elsif o.is_a?(Module) || o.is_a?(Puppet::Resource) || o.is_a?(Puppet::Parser::Resource)
494
+ @type.nil? ? true : assignable?(TypeCalculator.infer(o))
495
+ else
496
+ false
497
+ end
498
+ end
499
+
500
+ def iterable?(guard = nil)
501
+ case @type
502
+ when PEnumType
503
+ true
504
+ when PIntegerType
505
+ @type.finite_range?
506
+ else
507
+ false
508
+ end
509
+ end
510
+
511
+ def iterable_type(guard = nil)
512
+ # The types PIntegerType and PEnumType are Iterable
513
+ case @type
514
+ when PEnumType
515
+ # @type describes the element type perfectly since the iteration is made over the
516
+ # contained choices.
517
+ PIterableType.new(@type)
518
+ when PIntegerType
519
+ # @type describes the element type perfectly since the iteration is made over the
520
+ # specified range.
521
+ @type.finite_range? ? PIterableType.new(@type) : nil
522
+ else
523
+ nil
524
+ end
525
+ end
526
+
527
+ def eql?(o)
528
+ self.class == o.class && @type == o.type
529
+ end
530
+
531
+ DEFAULT = PTypeType.new(nil)
532
+
533
+ protected
534
+
535
+ # @api private
536
+ def _assignable?(o, guard)
537
+ return false unless o.is_a?(PTypeType)
538
+ return true if @type.nil? # wide enough to handle all types
539
+ return false if o.type.nil? # wider than t
540
+ @type.assignable?(o.type, guard)
541
+ end
542
+ end
543
+
544
+ # For backward compatibility
545
+ PType = PTypeType
546
+
547
+ class PNotUndefType < PTypeWithContainedType
548
+ def self.register_ptype(loader, ir)
549
+ create_ptype(loader, ir, 'AnyType',
550
+ 'type' => {
551
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
552
+ KEY_VALUE => nil
553
+ }
554
+ )
555
+ end
556
+
557
+ def initialize(type = nil)
558
+ super(type.class == PAnyType ? nil : type)
559
+ end
560
+
561
+ def instance?(o, guard = nil)
562
+ !(o.nil? || o == :undef) && (@type.nil? || @type.instance?(o, guard))
563
+ end
564
+
565
+ def normalize(guard = nil)
566
+ n = super
567
+ if n.type.nil?
568
+ n
569
+ else
570
+ if n.type.is_a?(POptionalType)
571
+ # No point in having an optional in a NotUndef
572
+ PNotUndefType.new(n.type.type).normalize
573
+ elsif !n.type.assignable?(PUndefType::DEFAULT)
574
+ # THe type is NotUndef anyway, so it can be stripped of
575
+ n.type
576
+ else
577
+ n
578
+ end
579
+ end
580
+ end
581
+
582
+ def new_function
583
+ # If only NotUndef, then use Unit's null converter
584
+ if type.nil?
585
+ PUnitType.new_function(self)
586
+ else
587
+ type.new_function
588
+ end
589
+ end
590
+
591
+ DEFAULT = PNotUndefType.new
592
+
593
+ protected
594
+
595
+ # @api private
596
+ def _assignable?(o, guard)
597
+ o.is_a?(PAnyType) && !o.assignable?(PUndefType::DEFAULT, guard) && (@type.nil? || @type.assignable?(o, guard))
598
+ end
599
+ end
600
+
601
+ # @api public
602
+ #
603
+ class PUndefType < PAnyType
604
+ def self.register_ptype(loader, ir)
605
+ create_ptype(loader, ir, 'AnyType')
606
+ end
607
+
608
+ def instance?(o, guard = nil)
609
+ o.nil? || :undef == o
610
+ end
611
+
612
+ # @api private
613
+ def callable_args?(callable_t, guard)
614
+ # if callable_t is Optional (or indeed PUndefType), this means that 'missing callable' is accepted
615
+ callable_t.assignable?(DEFAULT, guard)
616
+ end
617
+
618
+ DEFAULT = PUndefType.new
619
+
620
+ protected
621
+ # @api private
622
+ def _assignable?(o, guard)
623
+ o.is_a?(PUndefType)
624
+ end
625
+ end
626
+
627
+ # A type private to the type system that describes "ignored type" - i.e. "I am what you are"
628
+ # @api private
629
+ #
630
+ class PUnitType < PAnyType
631
+ def self.register_ptype(loader, ir)
632
+ create_ptype(loader, ir, 'AnyType')
633
+ end
634
+
635
+ def instance?(o, guard = nil)
636
+ true
637
+ end
638
+
639
+ # A "null" implementation - that simply returns the given argument
640
+ def self.new_function(type)
641
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_unit, type.loader) do
642
+ dispatch :from_args do
643
+ param 'Any', :from
644
+ end
645
+
646
+ def from_args(from)
647
+ from
648
+ end
649
+ end
650
+ end
651
+
652
+ DEFAULT = PUnitType.new
653
+
654
+ def assignable?(o, guard=nil)
655
+ true
656
+ end
657
+
658
+ protected
659
+
660
+ # @api private
661
+ def _assignable?(o, guard)
662
+ true
663
+ end
664
+ end
665
+
666
+ # @api public
667
+ #
668
+ class PDefaultType < PAnyType
669
+ def self.register_ptype(loader, ir)
670
+ create_ptype(loader, ir, 'AnyType')
671
+ end
672
+
673
+ def instance?(o, guard = nil)
674
+ # Ensure that Symbol.== is called here instead of something unknown
675
+ # that is implemented on o
676
+ :default == o
677
+ end
678
+
679
+ DEFAULT = PDefaultType.new
680
+
681
+ protected
682
+ # @api private
683
+ def _assignable?(o, guard)
684
+ o.is_a?(PDefaultType)
685
+ end
686
+ end
687
+
688
+ # Type that is a Scalar
689
+ # @api public
690
+ #
691
+ class PScalarType < PAnyType
692
+ def self.register_ptype(loader, ir)
693
+ create_ptype(loader, ir, 'AnyType')
694
+ end
695
+
696
+ def instance?(o, guard = nil)
697
+ if o.is_a?(String) || o.is_a?(Numeric) || o.is_a?(TrueClass) || o.is_a?(FalseClass) || o.is_a?(Regexp)
698
+ true
699
+ elsif o.instance_of?(Array) || o.instance_of?(Hash) || o.is_a?(PAnyType) || o.is_a?(NilClass)
700
+ false
701
+ else
702
+ assignable?(TypeCalculator.infer(o))
703
+ end
704
+ end
705
+
706
+ def roundtrip_with_string?
707
+ true
708
+ end
709
+
710
+ DEFAULT = PScalarType.new
711
+
712
+ protected
713
+
714
+ # @api private
715
+ def _assignable?(o, guard)
716
+ o.is_a?(PScalarType) ||
717
+ PStringType::DEFAULT.assignable?(o, guard) ||
718
+ PIntegerType::DEFAULT.assignable?(o, guard) ||
719
+ PFloatType::DEFAULT.assignable?(o, guard) ||
720
+ PBooleanType::DEFAULT.assignable?(o, guard) ||
721
+ PRegexpType::DEFAULT.assignable?(o, guard) ||
722
+ PSemVerType::DEFAULT.assignable?(o, guard) ||
723
+ PSemVerRangeType::DEFAULT.assignable?(o, guard) ||
724
+ PTimespanType::DEFAULT.assignable?(o, guard) ||
725
+ PTimestampType::DEFAULT.assignable?(o, guard)
726
+ end
727
+ end
728
+
729
+ # Like Scalar but limited to Json Data.
730
+ # @api public
731
+ #
732
+ class PScalarDataType < PScalarType
733
+ def self.register_ptype(loader, ir)
734
+ create_ptype(loader, ir, 'ScalarType')
735
+ end
736
+
737
+ def instance?(o, guard = nil)
738
+ return o.instance_of?(String) || o.is_a?(Integer) || o.is_a?(Float) || o.is_a?(TrueClass) || o.is_a?(FalseClass)
739
+ end
740
+
741
+ DEFAULT = PScalarDataType.new
742
+
743
+ protected
744
+
745
+ # @api private
746
+ def _assignable?(o, guard)
747
+ o.is_a?(PScalarDataType) ||
748
+ PStringType::DEFAULT.assignable?(o, guard) ||
749
+ PIntegerType::DEFAULT.assignable?(o, guard) ||
750
+ PFloatType::DEFAULT.assignable?(o, guard) ||
751
+ PBooleanType::DEFAULT.assignable?(o, guard)
752
+ end
753
+ end
754
+
755
+ # A string type describing the set of strings having one of the given values
756
+ # @api public
757
+ #
758
+ class PEnumType < PScalarDataType
759
+ def self.register_ptype(loader, ir)
760
+ create_ptype(loader, ir, 'ScalarDataType',
761
+ 'values' => PArrayType.new(PStringType::NON_EMPTY),
762
+ 'case_insensitive' => { 'type' => PBooleanType::DEFAULT, 'value' => false })
763
+ end
764
+
765
+ attr_reader :values, :case_insensitive
766
+
767
+ def initialize(values, case_insensitive = false)
768
+ @values = values.uniq.sort.freeze
769
+ @case_insensitive = case_insensitive
770
+ end
771
+
772
+ def case_insensitive?
773
+ @case_insensitive
774
+ end
775
+
776
+ # Returns Enumerator if no block is given, otherwise, calls the given
777
+ # block with each of the strings for this enum
778
+ def each(&block)
779
+ r = Iterable.on(self)
780
+ block_given? ? r.each(&block) : r
781
+ end
782
+
783
+ def generalize
784
+ # General form of an Enum is a String
785
+ if @values.empty?
786
+ PStringType::DEFAULT
787
+ else
788
+ range = @values.map(&:size).minmax
789
+ PStringType.new(PIntegerType.new(range.min, range.max))
790
+ end
791
+ end
792
+
793
+ def iterable?(guard = nil)
794
+ true
795
+ end
796
+
797
+ def iterable_type(guard = nil)
798
+ # An instance of an Enum is a String
799
+ PStringType::ITERABLE_TYPE
800
+ end
801
+
802
+ def hash
803
+ @values.hash ^ @case_insensitive.hash
804
+ end
805
+
806
+ def eql?(o)
807
+ self.class == o.class && @values == o.values && @case_insensitive == o.case_insensitive?
808
+ end
809
+
810
+ def instance?(o, guard = nil)
811
+ if o.is_a?(String)
812
+ @case_insensitive ? @values.any? { |p| p.casecmp(o) == 0 } : @values.any? { |p| p == o }
813
+ else
814
+ false
815
+ end
816
+ end
817
+
818
+ DEFAULT = PEnumType.new(EMPTY_ARRAY)
819
+
820
+ protected
821
+
822
+ # @api private
823
+ def _assignable?(o, guard)
824
+ return true if self == o
825
+ svalues = values
826
+ if svalues.empty?
827
+ return true if o.is_a?(PStringType) || o.is_a?(PEnumType) || o.is_a?(PPatternType)
828
+ end
829
+ case o
830
+ when PStringType
831
+ # if the contained string is found in the set of enums
832
+ instance?(o.value, guard)
833
+ when PEnumType
834
+ !o.values.empty? && (case_insensitive? || !o.case_insensitive?) && o.values.all? { |s| instance?(s, guard) }
835
+ else
836
+ false
837
+ end
838
+ end
839
+ end
840
+
841
+ INTEGER_HEX = '(?:0[xX][0-9A-Fa-f]+)'
842
+ INTEGER_OCT = '(?:0[0-7]+)'
843
+ INTEGER_BIN = '(?:0[bB][01]+)'
844
+ INTEGER_DEC = '(?:0|[1-9]\d*)'
845
+ INTEGER_DEC_OR_OCT = '(?:\d+)'
846
+ SIGN_PREFIX = '[+-]?\s*'
847
+
848
+ OPTIONAL_FRACTION = '(?:\.\d+)?'
849
+ OPTIONAL_EXPONENT = '(?:[eE]-?\d+)?'
850
+ FLOAT_DEC = '(?:' + INTEGER_DEC + OPTIONAL_FRACTION + OPTIONAL_EXPONENT + ')'
851
+
852
+ INTEGER_PATTERN = '\A' + SIGN_PREFIX + '(?:' + INTEGER_DEC + '|' + INTEGER_HEX + '|' + INTEGER_OCT + '|' + INTEGER_BIN + ')\z'
853
+ INTEGER_PATTERN_LENIENT = '\A' + SIGN_PREFIX + '(?:' + INTEGER_DEC_OR_OCT + '|' + INTEGER_HEX + '|' + INTEGER_BIN + ')\z'
854
+ FLOAT_PATTERN = '\A' + SIGN_PREFIX + '(?:' + FLOAT_DEC + '|' + INTEGER_HEX + '|' + INTEGER_OCT + '|' + INTEGER_BIN + ')\z'
855
+
856
+ # @api public
857
+ #
858
+ class PNumericType < PScalarDataType
859
+ def self.register_ptype(loader, ir)
860
+ create_ptype(loader, ir, 'ScalarDataType',
861
+ 'from' => { KEY_TYPE => POptionalType.new(PNumericType::DEFAULT), KEY_VALUE => nil },
862
+ 'to' => { KEY_TYPE => POptionalType.new(PNumericType::DEFAULT), KEY_VALUE => nil }
863
+ )
864
+ end
865
+
866
+ def self.new_function(type)
867
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_numeric, type.loader) do
868
+ local_types do
869
+ type "Convertible = Variant[Integer, Float, Boolean, Pattern[/#{FLOAT_PATTERN}/], Timespan, Timestamp]"
870
+ type 'NamedArgs = Struct[{from => Convertible, Optional[abs] => Boolean}]'
871
+ end
872
+
873
+ dispatch :from_args do
874
+ param 'Convertible', :from
875
+ optional_param 'Boolean', :abs
876
+ end
877
+
878
+ dispatch :from_hash do
879
+ param 'NamedArgs', :hash_args
880
+ end
881
+
882
+ argument_mismatch :on_error do
883
+ param 'Any', :from
884
+ optional_param 'Boolean', :abs
885
+ end
886
+
887
+ def from_args(from, abs = false)
888
+ result = from_convertible(from)
889
+ abs ? result.abs : result
890
+ end
891
+
892
+ def from_hash(args_hash)
893
+ from_args(args_hash['from'], args_hash['abs'] || false)
894
+ end
895
+
896
+ def from_convertible(from)
897
+ case from
898
+ when Float
899
+ from
900
+ when Integer
901
+ from
902
+ when Time::TimeData
903
+ from.to_f
904
+ when TrueClass
905
+ 1
906
+ when FalseClass
907
+ 0
908
+ else
909
+ begin
910
+ if from[0] == '0'
911
+ second_char = (from[1] || '').downcase
912
+ if second_char == 'b' || second_char == 'x'
913
+ # use built in conversion
914
+ return Integer(from)
915
+ end
916
+ end
917
+
918
+ Puppet::Pops::Utils.to_n(from)
919
+ rescue TypeError => e
920
+ raise TypeConversionError.new(e.message)
921
+ rescue ArgumentError => e
922
+ raise TypeConversionError.new(e.message)
923
+ end
924
+ end
925
+ end
926
+
927
+ def on_error(from, abs = false)
928
+ if from.is_a?(String)
929
+ _("The string '%{str}' cannot be converted to Numeric") % { str: from }
930
+ else
931
+ t = TypeCalculator.singleton.infer(from).generalize
932
+ _("Value of type %{type} cannot be converted to Numeric") % { type: t }
933
+ end
934
+ end
935
+ end
936
+ end
937
+
938
+ def initialize(from, to = Float::INFINITY)
939
+ from = -Float::INFINITY if from.nil? || from == :default
940
+ to = Float::INFINITY if to.nil? || to == :default
941
+ raise ArgumentError, "'from' must be less or equal to 'to'. Got (#{from}, #{to}" if from > to
942
+ @from = from
943
+ @to = to
944
+ end
945
+
946
+ # Checks if this numeric range intersects with another
947
+ #
948
+ # @param o [PNumericType] the range to compare with
949
+ # @return [Boolean] `true` if this range intersects with the other range
950
+ # @api public
951
+ def intersect?(o)
952
+ self.class == o.class && !(@to < o.numeric_from || o.numeric_to < @from)
953
+ end
954
+
955
+ # Returns the lower bound of the numeric range or `nil` if no lower bound is set.
956
+ # @return [Float,Integer]
957
+ def from
958
+ @from == -Float::INFINITY ? nil : @from
959
+ end
960
+
961
+ # Returns the upper bound of the numeric range or `nil` if no upper bound is set.
962
+ # @return [Float,Integer]
963
+ def to
964
+ @to == Float::INFINITY ? nil : @to
965
+ end
966
+
967
+ # Same as #from but will return `-Float::Infinity` instead of `nil` if no lower bound is set.
968
+ # @return [Float,Integer]
969
+ def numeric_from
970
+ @from
971
+ end
972
+
973
+ # Same as #to but will return `Float::Infinity` instead of `nil` if no lower bound is set.
974
+ # @return [Float,Integer]
975
+ def numeric_to
976
+ @to
977
+ end
978
+
979
+ def hash
980
+ @from.hash ^ @to.hash
981
+ end
982
+
983
+ def eql?(o)
984
+ self.class == o.class && @from == o.numeric_from && @to == o.numeric_to
985
+ end
986
+
987
+ def instance?(o, guard = nil)
988
+ (o.is_a?(Float) || o.is_a?(Integer)) && o >= @from && o <= @to
989
+ end
990
+
991
+ def unbounded?
992
+ @from == -Float::INFINITY && @to == Float::INFINITY
993
+ end
994
+
995
+ protected
996
+
997
+ # @api_private
998
+ def _assignable?(o, guard)
999
+ return false unless o.is_a?(self.class)
1000
+ # If o min and max are within the range of t
1001
+ @from <= o.numeric_from && @to >= o.numeric_to
1002
+ end
1003
+
1004
+ DEFAULT = PNumericType.new(-Float::INFINITY)
1005
+ end
1006
+
1007
+ # @api public
1008
+ #
1009
+ class PIntegerType < PNumericType
1010
+ def self.register_ptype(loader, ir)
1011
+ create_ptype(loader, ir, 'NumericType')
1012
+ end
1013
+
1014
+ # Will respond `true` for any range that is bounded at both ends.
1015
+ #
1016
+ # @return [Boolean] `true` if the type describes a finite range.
1017
+ def finite_range?
1018
+ @from != -Float::INFINITY && @to != Float::INFINITY
1019
+ end
1020
+
1021
+ def generalize
1022
+ DEFAULT
1023
+ end
1024
+
1025
+ def instance?(o, guard = nil)
1026
+ o.is_a?(Integer) && o >= numeric_from && o <= numeric_to
1027
+ end
1028
+
1029
+ # Checks if this range is adjacent to the given range
1030
+ #
1031
+ # @param o [PIntegerType] the range to compare with
1032
+ # @return [Boolean] `true` if this range is adjacent to the other range
1033
+ # @api public
1034
+ def adjacent?(o)
1035
+ o.is_a?(PIntegerType) && (@to + 1 == o.from || o.to + 1 == @from)
1036
+ end
1037
+
1038
+ # Concatenates this range with another range provided that the ranges intersect or
1039
+ # are adjacent. When that's not the case, this method will return `nil`
1040
+ #
1041
+ # @param o [PIntegerType] the range to concatenate with this range
1042
+ # @return [PIntegerType,nil] the concatenated range or `nil` when the ranges were apart
1043
+ # @api public
1044
+ def merge(o)
1045
+ if intersect?(o) || adjacent?(o)
1046
+ min = @from <= o.numeric_from ? @from : o.numeric_from
1047
+ max = @to >= o.numeric_to ? @to : o.numeric_to
1048
+ PIntegerType.new(min, max)
1049
+ else
1050
+ nil
1051
+ end
1052
+ end
1053
+
1054
+ def iterable?(guard = nil)
1055
+ true
1056
+ end
1057
+
1058
+ def iterable_type(guard = nil)
1059
+ # It's unknown if the iterable will be a range (min, max) or a "times" (0, max)
1060
+ PIterableType.new(PIntegerType::DEFAULT)
1061
+ end
1062
+
1063
+ # Returns Float.Infinity if one end of the range is unbound
1064
+ def size
1065
+ return Float::INFINITY if @from == -Float::INFINITY || @to == Float::INFINITY
1066
+ 1+(to-from).abs
1067
+ end
1068
+
1069
+ # Returns the range as an array ordered so the smaller number is always first.
1070
+ # The number may be Infinity or -Infinity.
1071
+ def range
1072
+ [@from, @to]
1073
+ end
1074
+
1075
+ # Returns Enumerator if no block is given
1076
+ # Returns nil if size is infinity (does not yield)
1077
+ def each(&block)
1078
+ r = Iterable.on(self)
1079
+ block_given? ? r.each(&block) : r
1080
+ end
1081
+
1082
+ # Returns a range where both to and from are positive numbers. Negative
1083
+ # numbers are converted to zero
1084
+ # @return [PIntegerType] a positive range
1085
+ def to_size
1086
+ @from >= 0 ? self : PIntegerType.new(0, @to < 0 ? 0 : @to)
1087
+ end
1088
+
1089
+ def new_function
1090
+ @@new_function ||= Puppet::Functions.create_loaded_function(:new, loader) do
1091
+ local_types do
1092
+ type 'Radix = Variant[Default, Integer[2,2], Integer[8,8], Integer[10,10], Integer[16,16]]'
1093
+ type "Convertible = Variant[Numeric, Boolean, Pattern[/#{INTEGER_PATTERN_LENIENT}/], Timespan, Timestamp]"
1094
+ type 'NamedArgs = Struct[{from => Convertible, Optional[radix] => Radix, Optional[abs] => Boolean}]'
1095
+ end
1096
+
1097
+ dispatch :from_args do
1098
+ param 'Convertible', :from
1099
+ optional_param 'Radix', :radix
1100
+ optional_param 'Boolean', :abs
1101
+ end
1102
+
1103
+ dispatch :from_hash do
1104
+ param 'NamedArgs', :hash_args
1105
+ end
1106
+
1107
+ argument_mismatch :on_error_hash do
1108
+ param 'Hash', :hash_args
1109
+ end
1110
+
1111
+ argument_mismatch :on_error do
1112
+ param 'Any', :from
1113
+ optional_param 'Integer', :radix
1114
+ optional_param 'Boolean', :abs
1115
+ end
1116
+
1117
+ def from_args(from, radix = :default, abs = false)
1118
+ result = from_convertible(from, radix)
1119
+ abs ? result.abs : result
1120
+ end
1121
+
1122
+ def from_hash(args_hash)
1123
+ from_args(args_hash['from'], args_hash['radix'] || :default, args_hash['abs'] || false)
1124
+ end
1125
+
1126
+ def from_convertible(from, radix)
1127
+ case from
1128
+ when Float, Time::TimeData
1129
+ from.to_i
1130
+ when Integer
1131
+ from
1132
+ when TrueClass
1133
+ 1
1134
+ when FalseClass
1135
+ 0
1136
+ else
1137
+ begin
1138
+ radix == :default ? Integer(from) : Integer(from, radix)
1139
+ rescue TypeError => e
1140
+ raise TypeConversionError.new(e.message)
1141
+ rescue ArgumentError => e
1142
+ # Test for special case where there is whitespace between sign and number
1143
+ match = Patterns::WS_BETWEEN_SIGN_AND_NUMBER.match(from)
1144
+ if match
1145
+ begin
1146
+ # Try again, this time with whitespace removed
1147
+ return from_args(match[1] + match[2], radix)
1148
+ rescue TypeConversionError
1149
+ # Ignored to retain original error
1150
+ end
1151
+ end
1152
+ raise TypeConversionError.new(e.message)
1153
+ end
1154
+ end
1155
+ end
1156
+
1157
+ def on_error_hash(args_hash)
1158
+ if args_hash.include?('from')
1159
+ from = args_hash['from']
1160
+ return on_error(from) unless loader.load(:type, 'convertible').instance?(from)
1161
+ end
1162
+ radix = args_hash['radix']
1163
+ assert_radix(radix) unless radix.nil? || radix == :default
1164
+ TypeAsserter.assert_instance_of('Integer.new', loader.load(:type, 'namedargs'), args_hash)
1165
+ end
1166
+
1167
+ def on_error(from, radix = :default, abs = nil)
1168
+ assert_radix(radix) unless radix == :default
1169
+ if from.is_a?(String)
1170
+ _("The string '%{str}' cannot be converted to Integer") % { str: from }
1171
+ else
1172
+ t = TypeCalculator.singleton.infer(from).generalize
1173
+ _("Value of type %{type} cannot be converted to Integer") % { type: t }
1174
+ end
1175
+ end
1176
+
1177
+ def assert_radix(radix)
1178
+ case radix
1179
+ when 2, 8, 10, 16
1180
+ else
1181
+ raise ArgumentError.new(_("Illegal radix: %{radix}, expected 2, 8, 10, 16, or default") % { radix: radix })
1182
+ end
1183
+ radix
1184
+ end
1185
+
1186
+ end
1187
+ end
1188
+
1189
+ DEFAULT = PIntegerType.new(-Float::INFINITY)
1190
+ end
1191
+
1192
+ # @api public
1193
+ #
1194
+ class PFloatType < PNumericType
1195
+ def self.register_ptype(loader, ir)
1196
+ create_ptype(loader, ir, 'NumericType')
1197
+ end
1198
+
1199
+ def generalize
1200
+ DEFAULT
1201
+ end
1202
+
1203
+ def instance?(o, guard = nil)
1204
+ o.is_a?(Float) && o >= numeric_from && o <= numeric_to
1205
+ end
1206
+
1207
+ # Concatenates this range with another range provided that the ranges intersect. When that's not the case, this
1208
+ # method will return `nil`
1209
+ #
1210
+ # @param o [PFloatType] the range to concatenate with this range
1211
+ # @return [PFloatType,nil] the concatenated range or `nil` when the ranges were apart
1212
+ # @api public
1213
+ def merge(o)
1214
+ if intersect?(o)
1215
+ min = @from <= o.from ? @from : o.from
1216
+ max = @to >= o.to ? @to : o.to
1217
+ PFloatType.new(min, max)
1218
+ else
1219
+ nil
1220
+ end
1221
+ end
1222
+
1223
+ # Returns a new function that produces a Float value
1224
+ #
1225
+ def self.new_function(type)
1226
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_float, type.loader) do
1227
+ local_types do
1228
+ type "Convertible = Variant[Numeric, Boolean, Pattern[/#{FLOAT_PATTERN}/], Timespan, Timestamp]"
1229
+ type 'NamedArgs = Struct[{from => Convertible, Optional[abs] => Boolean}]'
1230
+ end
1231
+
1232
+ dispatch :from_args do
1233
+ param 'Convertible', :from
1234
+ optional_param 'Boolean', :abs
1235
+ end
1236
+
1237
+ dispatch :from_hash do
1238
+ param 'NamedArgs', :hash_args
1239
+ end
1240
+
1241
+ argument_mismatch :on_error do
1242
+ param 'Any', :from
1243
+ optional_param 'Boolean', :abs
1244
+ end
1245
+
1246
+ def from_args(from, abs = false)
1247
+ result = from_convertible(from)
1248
+ abs ? result.abs : result
1249
+ end
1250
+
1251
+ def from_hash(args_hash)
1252
+ from_args(args_hash['from'], args_hash['abs'] || false)
1253
+ end
1254
+
1255
+ def from_convertible(from)
1256
+ case from
1257
+ when Float
1258
+ from
1259
+ when Integer
1260
+ Float(from)
1261
+ when Time::TimeData
1262
+ from.to_f
1263
+ when TrueClass
1264
+ 1.0
1265
+ when FalseClass
1266
+ 0.0
1267
+ else
1268
+ begin
1269
+ # support a binary as float
1270
+ if from[0] == '0' && from[1].casecmp('b').zero?
1271
+ from = Integer(from)
1272
+ end
1273
+ Float(from)
1274
+ rescue TypeError => e
1275
+ raise TypeConversionError.new(e.message)
1276
+ rescue ArgumentError => e
1277
+ # Test for special case where there is whitespace between sign and number
1278
+ match = Patterns::WS_BETWEEN_SIGN_AND_NUMBER.match(from)
1279
+ if match
1280
+ begin
1281
+ # Try again, this time with whitespace removed
1282
+ return from_args(match[1] + match[2])
1283
+ rescue TypeConversionError
1284
+ # Ignored to retain original error
1285
+ end
1286
+ end
1287
+ raise TypeConversionError.new(e.message)
1288
+ end
1289
+ end
1290
+ end
1291
+
1292
+ def on_error(from, _ = false)
1293
+ if from.is_a?(String)
1294
+ _("The string '%{str}' cannot be converted to Float") % { str: from }
1295
+ else
1296
+ t = TypeCalculator.singleton.infer(from).generalize
1297
+ _("Value of type %{type} cannot be converted to Float") % { type: t }
1298
+ end
1299
+ end
1300
+ end
1301
+ end
1302
+
1303
+ DEFAULT = PFloatType.new(-Float::INFINITY)
1304
+ end
1305
+
1306
+ # @api public
1307
+ #
1308
+ class PCollectionType < PAnyType
1309
+ def self.register_ptype(loader, ir)
1310
+ create_ptype(loader, ir, 'AnyType',
1311
+ 'size_type' => {
1312
+ KEY_TYPE => POptionalType.new(PTypeType.new(PIntegerType::DEFAULT)),
1313
+ KEY_VALUE => nil
1314
+ }
1315
+ )
1316
+ end
1317
+
1318
+ attr_reader :size_type
1319
+
1320
+ def initialize(size_type)
1321
+ @size_type = size_type.nil? ? nil : size_type.to_size
1322
+ end
1323
+
1324
+ def accept(visitor, guard)
1325
+ super
1326
+ @size_type.accept(visitor, guard) unless @size_type.nil?
1327
+ end
1328
+
1329
+ def generalize
1330
+ DEFAULT
1331
+ end
1332
+
1333
+ def normalize(guard = nil)
1334
+ DEFAULT
1335
+ end
1336
+
1337
+ def instance?(o, guard = nil)
1338
+ # The inferred type of a class derived from Array or Hash is either Runtime or Object. It's not assignable to the Collection type.
1339
+ if o.instance_of?(Array) || o.instance_of?(Hash)
1340
+ @size_type.nil? || @size_type.instance?(o.size)
1341
+ else
1342
+ false
1343
+ end
1344
+ end
1345
+
1346
+ # Returns an array with from (min) size to (max) size
1347
+ def size_range
1348
+ (@size_type || DEFAULT_SIZE).range
1349
+ end
1350
+
1351
+ def has_empty_range?
1352
+ from, to = size_range
1353
+ from == 0 && to == 0
1354
+ end
1355
+
1356
+ def hash
1357
+ @size_type.hash
1358
+ end
1359
+
1360
+ def iterable?(guard = nil)
1361
+ true
1362
+ end
1363
+
1364
+ def eql?(o)
1365
+ self.class == o.class && @size_type == o.size_type
1366
+ end
1367
+
1368
+
1369
+ DEFAULT_SIZE = PIntegerType.new(0)
1370
+ ZERO_SIZE = PIntegerType.new(0, 0)
1371
+ NOT_EMPTY_SIZE = PIntegerType.new(1)
1372
+ DEFAULT = PCollectionType.new(nil)
1373
+
1374
+ protected
1375
+
1376
+ # @api private
1377
+ #
1378
+ def _assignable?(o, guard)
1379
+ case o
1380
+ when PCollectionType
1381
+ (@size_type || DEFAULT_SIZE).assignable?(o.size_type || DEFAULT_SIZE, guard)
1382
+ when PTupleType
1383
+ # compute the tuple's min/max size, and check if that size matches
1384
+ size_s = size_type || DEFAULT_SIZE
1385
+ size_o = o.size_type
1386
+ if size_o.nil?
1387
+ type_count = o.types.size
1388
+ size_o = PIntegerType.new(type_count, type_count)
1389
+ end
1390
+ size_s.assignable?(size_o)
1391
+ when PStructType
1392
+ from = to = o.elements.size
1393
+ (@size_type || DEFAULT_SIZE).assignable?(PIntegerType.new(from, to), guard)
1394
+ else
1395
+ false
1396
+ end
1397
+ end
1398
+ end
1399
+
1400
+ class PIterableType < PTypeWithContainedType
1401
+ def self.register_ptype(loader, ir)
1402
+ create_ptype(loader, ir, 'AnyType',
1403
+ 'type' => {
1404
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
1405
+ KEY_VALUE => nil
1406
+ }
1407
+ )
1408
+ end
1409
+
1410
+ def element_type
1411
+ @type
1412
+ end
1413
+
1414
+ def instance?(o, guard = nil)
1415
+ if @type.nil? || @type.assignable?(PAnyType::DEFAULT, guard)
1416
+ # Any element_type will do
1417
+ case o
1418
+ when Iterable, String, Hash, Array, Range, PEnumType
1419
+ true
1420
+ when Integer
1421
+ o >= 0
1422
+ when PIntegerType
1423
+ o.finite_range?
1424
+ when PTypeAliasType
1425
+ instance?(o.resolved_type, guard)
1426
+ else
1427
+ false
1428
+ end
1429
+ else
1430
+ assignable?(TypeCalculator.infer(o), guard)
1431
+ end
1432
+ end
1433
+
1434
+ def iterable?(guard = nil)
1435
+ true
1436
+ end
1437
+
1438
+ def iterable_type(guard = nil)
1439
+ self
1440
+ end
1441
+
1442
+ DEFAULT = PIterableType.new(nil)
1443
+
1444
+ protected
1445
+
1446
+ # @api private
1447
+ def _assignable?(o, guard)
1448
+ if @type.nil? || @type.assignable?(PAnyType::DEFAULT, guard)
1449
+ # Don't request the iterable_type. Since this Iterable accepts Any element, it is enough that o is iterable.
1450
+ o.iterable?
1451
+ else
1452
+ o = o.iterable_type
1453
+ o.nil? || o.element_type.nil? ? false : @type.assignable?(o.element_type, guard)
1454
+ end
1455
+ end
1456
+ end
1457
+
1458
+ # @api public
1459
+ #
1460
+ class PIteratorType < PTypeWithContainedType
1461
+ def self.register_ptype(loader, ir)
1462
+ create_ptype(loader, ir, 'AnyType',
1463
+ 'type' => {
1464
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
1465
+ KEY_VALUE => nil
1466
+ }
1467
+ )
1468
+ end
1469
+
1470
+ def element_type
1471
+ @type
1472
+ end
1473
+
1474
+ def instance?(o, guard = nil)
1475
+ o.is_a?(Iterable) && (@type.nil? || @type.assignable?(o.element_type, guard))
1476
+ end
1477
+
1478
+ def iterable?(guard = nil)
1479
+ true
1480
+ end
1481
+
1482
+ def iterable_type(guard = nil)
1483
+ @type.nil? ? PIterableType::DEFAULT : PIterableType.new(@type)
1484
+ end
1485
+
1486
+ DEFAULT = PIteratorType.new(nil)
1487
+
1488
+ protected
1489
+
1490
+ # @api private
1491
+ def _assignable?(o, guard)
1492
+ o.is_a?(PIteratorType) && (@type.nil? || @type.assignable?(o.element_type, guard))
1493
+ end
1494
+ end
1495
+
1496
+ # @api public
1497
+ #
1498
+ class PStringType < PScalarDataType
1499
+ def self.register_ptype(loader, ir)
1500
+ create_ptype(loader, ir, 'ScalarDataType',
1501
+ 'size_type_or_value' => {
1502
+ KEY_TYPE => POptionalType.new(PVariantType.new([PStringType::DEFAULT, PTypeType.new(PIntegerType::DEFAULT)])),
1503
+ KEY_VALUE => nil
1504
+ })
1505
+ end
1506
+
1507
+ attr_reader :size_type_or_value
1508
+
1509
+ def initialize(size_type_or_value, deprecated_multi_args = EMPTY_ARRAY)
1510
+ unless deprecated_multi_args.empty?
1511
+ if Puppet[:strict] != :off
1512
+ #TRANSLATORS 'PStringType#initialize' is a class and method name and should not be translated
1513
+ Puppet.warn_once('deprecations', "PStringType#initialize_multi_args",
1514
+ _("Passing more than one argument to PStringType#initialize is deprecated"))
1515
+ end
1516
+ size_type_or_value = deprecated_multi_args[0]
1517
+ end
1518
+ @size_type_or_value = size_type_or_value.is_a?(PIntegerType) ? size_type_or_value.to_size : size_type_or_value
1519
+ end
1520
+
1521
+ def accept(visitor, guard)
1522
+ super
1523
+ @size_type_or_value.accept(visitor, guard) if @size_type_or_value.is_a?(PIntegerType)
1524
+ end
1525
+
1526
+ def generalize
1527
+ DEFAULT
1528
+ end
1529
+
1530
+ def hash
1531
+ @size_type_or_value.hash
1532
+ end
1533
+
1534
+ def iterable?(guard = nil)
1535
+ true
1536
+ end
1537
+
1538
+ def iterable_type(guard = nil)
1539
+ ITERABLE_TYPE
1540
+ end
1541
+
1542
+ def eql?(o)
1543
+ self.class == o.class && @size_type_or_value == o.size_type_or_value
1544
+ end
1545
+
1546
+ def instance?(o, guard = nil)
1547
+ # true if size compliant
1548
+ if o.is_a?(String)
1549
+ if @size_type_or_value.is_a?(PIntegerType)
1550
+ @size_type_or_value.instance?(o.size, guard)
1551
+ else
1552
+ @size_type_or_value.nil? ? true : o == value
1553
+ end
1554
+ else
1555
+ false
1556
+ end
1557
+ end
1558
+
1559
+ def value
1560
+ @size_type_or_value.is_a?(PIntegerType) ? nil : @size_type_or_value
1561
+ end
1562
+
1563
+ # @deprecated
1564
+ # @api private
1565
+ def values
1566
+ if Puppet[:strict] != :off
1567
+ #TRANSLATORS 'PStringType#values' and '#value' are classes and method names and should not be translated
1568
+ Puppet.warn_once('deprecations', "PStringType#values", _("Method PStringType#values is deprecated. Use #value instead"))
1569
+ end
1570
+ @value.is_a?(String) ? [@value] : EMPTY_ARRAY
1571
+ end
1572
+
1573
+ def size_type
1574
+ @size_type_or_value.is_a?(PIntegerType) ? @size_type_or_value : nil
1575
+ end
1576
+
1577
+ def derived_size_type
1578
+ if @size_type_or_value.is_a?(PIntegerType)
1579
+ @size_type_or_value
1580
+ elsif @size_type_or_value.is_a?(String)
1581
+ sz = @size_type_or_value.size
1582
+ PIntegerType.new(sz, sz)
1583
+ else
1584
+ PCollectionType::DEFAULT_SIZE
1585
+ end
1586
+ end
1587
+
1588
+ def self.new_function(type)
1589
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_string, type.loader) do
1590
+ local_types do
1591
+ type "Format = Pattern[/#{StringConverter::Format::FMT_PATTERN_STR}/]"
1592
+ type 'ContainerFormat = Struct[{
1593
+ Optional[format] => Format,
1594
+ Optional[separator] => String,
1595
+ Optional[separator2] => String,
1596
+ Optional[string_formats] => Hash[Type, Format]
1597
+ }]'
1598
+ type 'TypeMap = Hash[Type, Variant[Format, ContainerFormat]]'
1599
+ type 'Convertible = Any'
1600
+ type 'Formats = Variant[Default, String[1], TypeMap]'
1601
+ end
1602
+
1603
+ dispatch :from_args do
1604
+ param 'Convertible', :from
1605
+ optional_param 'Formats', :string_formats
1606
+ end
1607
+
1608
+ def from_args(from, formats = :default)
1609
+ StringConverter.singleton.convert(from, formats)
1610
+ end
1611
+ end
1612
+ end
1613
+
1614
+ DEFAULT = PStringType.new(nil)
1615
+ NON_EMPTY = PStringType.new(PCollectionType::NOT_EMPTY_SIZE)
1616
+
1617
+ # Iterates over each character of the string
1618
+ ITERABLE_TYPE = PIterableType.new(PStringType.new(PIntegerType.new(1,1)))
1619
+
1620
+ protected
1621
+
1622
+ # @api private
1623
+ def _assignable?(o, guard)
1624
+ if @size_type_or_value.is_a?(PIntegerType)
1625
+ # A general string is assignable by any other string or pattern restricted string
1626
+ # if the string has a size constraint it does not match since there is no reasonable way
1627
+ # to compute the min/max length a pattern will match. For enum, it is possible to test that
1628
+ # each enumerator value is within range
1629
+ case o
1630
+ when PStringType
1631
+ @size_type_or_value.assignable?(o.derived_size_type, guard)
1632
+
1633
+ when PEnumType
1634
+ if o.values.empty?
1635
+ # enum represents all enums, and thus all strings, a sized constrained string can thus not
1636
+ # be assigned any enum (unless it is max size).
1637
+ @size_type_or_value.assignable?(PCollectionType::DEFAULT_SIZE, guard)
1638
+ else
1639
+ # true if all enum values are within range
1640
+ orange = o.values.map(&:size).minmax
1641
+ srange = @size_type_or_value.range
1642
+ # If o min and max are within the range of t
1643
+ srange[0] <= orange[0] && srange[1] >= orange[1]
1644
+ end
1645
+
1646
+ when PPatternType
1647
+ # true if size constraint is at least 0 to +Infinity (which is the same as the default)
1648
+ @size_type_or_value.assignable?(PCollectionType::DEFAULT_SIZE, guard)
1649
+ else
1650
+ # no other type matches string
1651
+ false
1652
+ end
1653
+ else
1654
+ case o
1655
+ when PStringType
1656
+ # Must match exactly when value is a string
1657
+ @size_type_or_value.nil? || @size_type_or_value == o.size_type_or_value
1658
+ when PEnumType
1659
+ @size_type_or_value.nil? ? true : o.values.size == 1 && !o.case_insensitive? && o.values[0]
1660
+ when PPatternType
1661
+ @size_type_or_value.nil?
1662
+ else
1663
+ # All others are false, since no other type describes the same set of specific strings
1664
+ false
1665
+ end
1666
+ end
1667
+ end
1668
+ end
1669
+
1670
+ # @api public
1671
+ #
1672
+ class PRegexpType < PScalarType
1673
+ def self.register_ptype(loader, ir)
1674
+ create_ptype(loader, ir, 'ScalarType',
1675
+ 'pattern' => {
1676
+ KEY_TYPE => PVariantType.new([PUndefType::DEFAULT, PStringType::DEFAULT, PRegexpType::DEFAULT]),
1677
+ KEY_VALUE => nil
1678
+ })
1679
+ end
1680
+
1681
+
1682
+ # Returns a new function that produces a Regexp instance
1683
+ #
1684
+ def self.new_function(type)
1685
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_float, type.loader) do
1686
+ dispatch :from_string do
1687
+ param 'String', :pattern
1688
+ optional_param 'Boolean', :escape
1689
+ end
1690
+
1691
+ def from_string(pattern, escape = false)
1692
+ Regexp.new(escape ? Regexp.escape(pattern) : pattern)
1693
+ end
1694
+ end
1695
+ end
1696
+
1697
+ attr_reader :pattern
1698
+
1699
+ # @param regexp [Regexp] the regular expression
1700
+ # @return [String] the Regexp as a slash delimited string with slashes escaped
1701
+ def self.regexp_to_s_with_delimiters(regexp)
1702
+ regexp.options == 0 ? regexp.inspect : "/#{regexp}/"
1703
+ end
1704
+
1705
+ # @param regexp [Regexp] the regular expression
1706
+ # @return [String] the Regexp as a string without escaped slash
1707
+ def self.regexp_to_s(regexp)
1708
+ append_flags_group(regexp.source, regexp.options)
1709
+ end
1710
+
1711
+ def self.append_flags_group(rx_string, options)
1712
+ if options == 0
1713
+ rx_string
1714
+ else
1715
+ bld = '(?'
1716
+ bld << 'i' if (options & Regexp::IGNORECASE) != 0
1717
+ bld << 'm' if (options & Regexp::MULTILINE) != 0
1718
+ bld << 'x' if (options & Regexp::EXTENDED) != 0
1719
+ unless options == (Regexp::IGNORECASE | Regexp::MULTILINE | Regexp::EXTENDED)
1720
+ bld << '-'
1721
+ bld << 'i' if (options & Regexp::IGNORECASE) == 0
1722
+ bld << 'm' if (options & Regexp::MULTILINE) == 0
1723
+ bld << 'x' if (options & Regexp::EXTENDED) == 0
1724
+ end
1725
+ bld << ':' << rx_string << ')'
1726
+ bld.freeze
1727
+ end
1728
+ end
1729
+
1730
+ def initialize(pattern)
1731
+ if pattern.is_a?(Regexp)
1732
+ @regexp = pattern
1733
+ @pattern = PRegexpType.regexp_to_s(pattern)
1734
+ else
1735
+ @pattern = pattern
1736
+ end
1737
+ end
1738
+
1739
+ def regexp
1740
+ @regexp ||= Regexp.new(@pattern || '')
1741
+ end
1742
+
1743
+ def hash
1744
+ @pattern.hash
1745
+ end
1746
+
1747
+ def eql?(o)
1748
+ self.class == o.class && @pattern == o.pattern
1749
+ end
1750
+
1751
+ def instance?(o, guard=nil)
1752
+ o.is_a?(Regexp) && @pattern.nil? || regexp == o
1753
+ end
1754
+
1755
+ DEFAULT = PRegexpType.new(nil)
1756
+
1757
+ protected
1758
+
1759
+ # @api private
1760
+ #
1761
+ def _assignable?(o, guard)
1762
+ o.is_a?(PRegexpType) && (@pattern.nil? || @pattern == o.pattern)
1763
+ end
1764
+ end
1765
+
1766
+ # Represents a subtype of String that narrows the string to those matching the patterns
1767
+ # If specified without a pattern it is basically the same as the String type.
1768
+ #
1769
+ # @api public
1770
+ #
1771
+ class PPatternType < PScalarDataType
1772
+ def self.register_ptype(loader, ir)
1773
+ create_ptype(loader, ir, 'ScalarDataType', 'patterns' => PArrayType.new(PRegexpType::DEFAULT))
1774
+ end
1775
+
1776
+ attr_reader :patterns
1777
+
1778
+ def initialize(patterns)
1779
+ @patterns = patterns.freeze
1780
+ end
1781
+
1782
+ def accept(visitor, guard)
1783
+ super
1784
+ @patterns.each { |p| p.accept(visitor, guard) }
1785
+ end
1786
+
1787
+ def hash
1788
+ @patterns.hash
1789
+ end
1790
+
1791
+ def eql?(o)
1792
+ self.class == o.class && @patterns.size == o.patterns.size && (@patterns - o.patterns).empty?
1793
+ end
1794
+
1795
+ def instance?(o, guard = nil)
1796
+ o.is_a?(String) && (@patterns.empty? || @patterns.any? { |p| p.regexp.match(o) })
1797
+ end
1798
+
1799
+ DEFAULT = PPatternType.new(EMPTY_ARRAY)
1800
+
1801
+ protected
1802
+
1803
+ # @api private
1804
+ #
1805
+ def _assignable?(o, guard)
1806
+ return true if self == o
1807
+ case o
1808
+ when PStringType
1809
+ v = o.value
1810
+ if v.nil?
1811
+ # Strings cannot all match a pattern, but if there is no pattern it is ok
1812
+ # (There should really always be a pattern, but better safe than sorry).
1813
+ @patterns.empty?
1814
+ else
1815
+ # the string in String type must match one of the patterns in Pattern type,
1816
+ # or Pattern represents all Patterns == all Strings
1817
+ regexps = @patterns.map { |p| p.regexp }
1818
+ regexps.empty? || regexps.any? { |re| re.match(v) }
1819
+ end
1820
+ when PEnumType
1821
+ if o.values.empty?
1822
+ # Enums (unknown which ones) cannot all match a pattern, but if there is no pattern it is ok
1823
+ # (There should really always be a pattern, but better safe than sorry).
1824
+ @patterns.empty?
1825
+ else
1826
+ # all strings in String/Enum type must match one of the patterns in Pattern type,
1827
+ # or Pattern represents all Patterns == all Strings
1828
+ regexps = @patterns.map { |p| p.regexp }
1829
+ regexps.empty? || o.values.all? { |s| regexps.any? {|re| re.match(s) } }
1830
+ end
1831
+ when PPatternType
1832
+ @patterns.empty?
1833
+ else
1834
+ false
1835
+ end
1836
+ end
1837
+ end
1838
+
1839
+ # @api public
1840
+ #
1841
+ class PBooleanType < PScalarDataType
1842
+ def self.register_ptype(loader, ir)
1843
+ create_ptype(loader, ir, 'ScalarDataType')
1844
+ end
1845
+
1846
+ attr_reader :value
1847
+
1848
+ def initialize(value = nil)
1849
+ @value = value
1850
+ end
1851
+
1852
+ def eql?(o)
1853
+ o.is_a?(PBooleanType) && @value == o.value
1854
+ end
1855
+
1856
+ def generalize
1857
+ PBooleanType::DEFAULT
1858
+ end
1859
+
1860
+ def hash
1861
+ 31 ^ @value.hash
1862
+ end
1863
+
1864
+ def instance?(o, guard = nil)
1865
+ (o == true || o == false) && (@value.nil? || value == o)
1866
+ end
1867
+
1868
+ def self.new_function(type)
1869
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_boolean, type.loader) do
1870
+ dispatch :from_args do
1871
+ param "Variant[Integer, Float, Boolean, Enum['false','true','yes','no','y','n',true]]", :from
1872
+ end
1873
+
1874
+ argument_mismatch :on_error do
1875
+ param 'Any', :from
1876
+ end
1877
+
1878
+ def from_args(from)
1879
+ from = from.downcase if from.is_a?(String)
1880
+ case from
1881
+ when Float
1882
+ from != 0.0
1883
+ when Integer
1884
+ from != 0
1885
+ when false, 'false', 'no', 'n'
1886
+ false
1887
+ else
1888
+ true
1889
+ end
1890
+ end
1891
+
1892
+ def on_error(from)
1893
+ if from.is_a?(String)
1894
+ _("The string '%{str}' cannot be converted to Boolean") % { str: from }
1895
+ else
1896
+ t = TypeCalculator.singleton.infer(from).generalize
1897
+ _("Value of type %{type} cannot be converted to Boolean") % { type: t }
1898
+ end
1899
+ end
1900
+ end
1901
+ end
1902
+
1903
+ DEFAULT = PBooleanType.new
1904
+ TRUE = PBooleanType.new(true)
1905
+ FALSE = PBooleanType.new(false)
1906
+
1907
+ protected
1908
+
1909
+ # @api private
1910
+ #
1911
+ def _assignable?(o, guard)
1912
+ o.is_a?(PBooleanType) && (@value.nil? || @value == o.value)
1913
+ end
1914
+ end
1915
+
1916
+ # @api public
1917
+ #
1918
+ # @api public
1919
+ #
1920
+ class PStructElement < TypedModelObject
1921
+ def self.register_ptype(loader, ir)
1922
+ @type = Pcore::create_object_type(loader, ir, self, 'Pcore::StructElement'.freeze, nil,
1923
+ 'key_type' => PTypeType::DEFAULT,
1924
+ 'value_type' => PTypeType::DEFAULT)
1925
+ end
1926
+
1927
+ attr_accessor :key_type, :value_type
1928
+
1929
+ def accept(visitor, guard)
1930
+ @key_type.accept(visitor, guard)
1931
+ @value_type.accept(visitor, guard)
1932
+ end
1933
+
1934
+ def hash
1935
+ value_type.hash ^ key_type.hash
1936
+ end
1937
+
1938
+ def name
1939
+ k = key_type
1940
+ k = k.optional_type if k.is_a?(POptionalType)
1941
+ k.value
1942
+ end
1943
+
1944
+ def initialize(key_type, value_type)
1945
+ @key_type = key_type
1946
+ @value_type = value_type
1947
+ end
1948
+
1949
+ def generalize
1950
+ gv_type = @value_type.generalize
1951
+ @value_type.equal?(gv_type) ? self : PStructElement.new(@key_type, gv_type)
1952
+ end
1953
+
1954
+ def normalize(guard = nil)
1955
+ nv_type = @value_type.normalize(guard)
1956
+ @value_type.equal?(nv_type) ? self : PStructElement.new(@key_type, nv_type)
1957
+ end
1958
+
1959
+ def resolve(loader)
1960
+ rkey_type = @key_type.resolve(loader)
1961
+ rvalue_type = @value_type.resolve(loader)
1962
+ rkey_type.equal?(@key_type) && rvalue_type.equal?(@value_type) ? self : self.class.new(rkey_type, rvalue_type)
1963
+ end
1964
+
1965
+ def <=>(o)
1966
+ self.name <=> o.name
1967
+ end
1968
+
1969
+ def eql?(o)
1970
+ self == o
1971
+ end
1972
+
1973
+ def ==(o)
1974
+ self.class == o.class && value_type == o.value_type && key_type == o.key_type
1975
+ end
1976
+
1977
+ # Special boostrap method to overcome the hen and egg problem with the Object initializer that contains
1978
+ # types that are derived from Object (such as Annotation)
1979
+ #
1980
+ # @api private
1981
+ def replace_value_type(new_type)
1982
+ @value_type = new_type
1983
+ end
1984
+ end
1985
+
1986
+ # @api public
1987
+ #
1988
+ class PStructType < PAnyType
1989
+ include Enumerable
1990
+
1991
+ def self.register_ptype(loader, ir)
1992
+ create_ptype(loader, ir, 'AnyType', 'elements' => PArrayType.new(PTypeReferenceType.new('Pcore::StructElement')))
1993
+ end
1994
+
1995
+ def initialize(elements)
1996
+ @elements = elements.freeze
1997
+ end
1998
+
1999
+ def accept(visitor, guard)
2000
+ super
2001
+ @elements.each { |elem| elem.accept(visitor, guard) }
2002
+ end
2003
+
2004
+ def each
2005
+ if block_given?
2006
+ elements.each { |elem| yield elem }
2007
+ else
2008
+ elements.to_enum
2009
+ end
2010
+ end
2011
+
2012
+ def generalize
2013
+ if @elements.empty?
2014
+ DEFAULT
2015
+ else
2016
+ alter_type_array(@elements, :generalize) { |altered| PStructType.new(altered) }
2017
+ end
2018
+ end
2019
+
2020
+ def normalize(guard = nil)
2021
+ if @elements.empty?
2022
+ DEFAULT
2023
+ else
2024
+ alter_type_array(@elements, :normalize, guard) { |altered| PStructType.new(altered) }
2025
+ end
2026
+ end
2027
+
2028
+ def hashed_elements
2029
+ @hashed ||= @elements.reduce({}) {|memo, e| memo[e.name] = e; memo }
2030
+ end
2031
+
2032
+ def hash
2033
+ @elements.hash
2034
+ end
2035
+
2036
+ def iterable?(guard = nil)
2037
+ true
2038
+ end
2039
+
2040
+ def iterable_type(guard = nil)
2041
+ if self == DEFAULT
2042
+ PIterableType.new(PHashType::DEFAULT_KEY_PAIR_TUPLE)
2043
+ else
2044
+ PIterableType.new(
2045
+ PTupleType.new([
2046
+ PVariantType.maybe_create(@elements.map {|se| se.key_type }),
2047
+ PVariantType.maybe_create(@elements.map {|se| se.value_type })],
2048
+ PHashType::KEY_PAIR_TUPLE_SIZE))
2049
+ end
2050
+ end
2051
+
2052
+ def resolve(loader)
2053
+ changed = false
2054
+ relements = @elements.map do |elem|
2055
+ relem = elem.resolve(loader)
2056
+ changed ||= !relem.equal?(elem)
2057
+ relem
2058
+ end
2059
+ changed ? self.class.new(relements) : self
2060
+ end
2061
+
2062
+ def eql?(o)
2063
+ self.class == o.class && @elements == o.elements
2064
+ end
2065
+
2066
+ def elements
2067
+ @elements
2068
+ end
2069
+
2070
+ def instance?(o, guard = nil)
2071
+ # The inferred type of a class derived from Hash is either Runtime or Object. It's not assignable to the Struct type.
2072
+ return false unless o.instance_of?(Hash)
2073
+ matched = 0
2074
+ @elements.all? do |e|
2075
+ key = e.name
2076
+ v = o[key]
2077
+ if v.nil? && !o.include?(key)
2078
+ # Entry is missing. Only OK when key is optional
2079
+ e.key_type.assignable?(PUndefType::DEFAULT, guard)
2080
+ else
2081
+ matched += 1
2082
+ e.value_type.instance?(v, guard)
2083
+ end
2084
+ end && matched == o.size
2085
+ end
2086
+
2087
+ def new_function
2088
+ # Simply delegate to Hash type and let the higher level assertion deal with
2089
+ # compliance with the Struct type regarding the produced result.
2090
+ PHashType.new_function(self)
2091
+ end
2092
+
2093
+ DEFAULT = PStructType.new(EMPTY_ARRAY)
2094
+
2095
+ protected
2096
+
2097
+ # @api private
2098
+ def _assignable?(o, guard)
2099
+ if o.is_a?(Types::PStructType)
2100
+ h2 = o.hashed_elements
2101
+ matched = 0
2102
+ elements.all? do |e1|
2103
+ e2 = h2[e1.name]
2104
+ if e2.nil?
2105
+ e1.key_type.assignable?(PUndefType::DEFAULT, guard)
2106
+ else
2107
+ matched += 1
2108
+ e1.key_type.assignable?(e2.key_type, guard) && e1.value_type.assignable?(e2.value_type, guard)
2109
+ end
2110
+ end && matched == h2.size
2111
+ elsif o.is_a?(Types::PHashType)
2112
+ required = 0
2113
+ required_elements_assignable = elements.all? do |e|
2114
+ key_type = e.key_type
2115
+ if key_type.assignable?(PUndefType::DEFAULT)
2116
+ # Element is optional so Hash does not need to provide it
2117
+ true
2118
+ else
2119
+ required += 1
2120
+ if e.value_type.assignable?(o.value_type, guard)
2121
+ # Hash must have something that is assignable. We don't care about the name or size of the key though
2122
+ # because we have no instance of a hash to compare against.
2123
+ key_type.generalize.assignable?(o.key_type)
2124
+ else
2125
+ false
2126
+ end
2127
+ end
2128
+ end
2129
+ if required_elements_assignable
2130
+ size_o = o.size_type || PCollectionType::DEFAULT_SIZE
2131
+ PIntegerType.new(required, elements.size).assignable?(size_o, guard)
2132
+ else
2133
+ false
2134
+ end
2135
+ else
2136
+ false
2137
+ end
2138
+ end
2139
+ end
2140
+
2141
+ # @api public
2142
+ #
2143
+ class PTupleType < PAnyType
2144
+ include Enumerable
2145
+
2146
+ def self.register_ptype(loader, ir)
2147
+ create_ptype(loader, ir, 'AnyType',
2148
+ 'types' => PArrayType.new(PTypeType::DEFAULT),
2149
+ 'size_type' => {
2150
+ KEY_TYPE => POptionalType.new(PTypeType.new(PIntegerType::DEFAULT)),
2151
+ KEY_VALUE => nil
2152
+ }
2153
+ )
2154
+ end
2155
+
2156
+ # If set, describes min and max required of the given types - if max > size of
2157
+ # types, the last type entry repeats
2158
+ #
2159
+ attr_reader :size_type
2160
+
2161
+ attr_reader :types
2162
+
2163
+ def accept(visitor, guard)
2164
+ super
2165
+ @size_type.accept(visitor, guard) unless @size_type.nil?
2166
+ @types.each { |elem| elem.accept(visitor, guard) }
2167
+ end
2168
+
2169
+ # @api private
2170
+ def callable_args?(callable_t, guard)
2171
+ unless size_type.nil?
2172
+ raise ArgumentError, 'Callable tuple may not have a size constraint when used as args'
2173
+ end
2174
+
2175
+ params_tuple = callable_t.param_types
2176
+ param_block_t = callable_t.block_type
2177
+ arg_types = @types
2178
+ arg_block_t = arg_types.last
2179
+ if arg_block_t.kind_of_callable?(true, guard)
2180
+ # Can't pass a block to a callable that doesn't accept one
2181
+ return false if param_block_t.nil?
2182
+
2183
+ # Check that the block is of the right tyṕe
2184
+ return false unless param_block_t.assignable?(arg_block_t, guard)
2185
+
2186
+ # Check other arguments
2187
+ arg_count = arg_types.size - 1
2188
+ params_size_t = params_tuple.size_type || PIntegerType.new(*params_tuple.size_range)
2189
+ return false unless params_size_t.assignable?(PIntegerType.new(arg_count, arg_count), guard)
2190
+
2191
+ ctypes = params_tuple.types
2192
+ arg_count.times do |index|
2193
+ return false unless (ctypes[index] || ctypes[-1]).assignable?(arg_types[index], guard)
2194
+ end
2195
+ return true
2196
+ end
2197
+
2198
+ # Check that tuple is assignable and that the block (if declared) is optional
2199
+ params_tuple.assignable?(self, guard) && (param_block_t.nil? || param_block_t.assignable?(PUndefType::DEFAULT, guard))
2200
+ end
2201
+
2202
+ def initialize(types, size_type = nil)
2203
+ @types = types
2204
+ @size_type = size_type.nil? ? nil : size_type.to_size
2205
+ end
2206
+
2207
+ # Returns Enumerator for the types if no block is given, otherwise, calls the given
2208
+ # block with each of the types in this tuple
2209
+ def each
2210
+ if block_given?
2211
+ types.each { |x| yield x }
2212
+ else
2213
+ types.to_enum
2214
+ end
2215
+ end
2216
+
2217
+ def generalize
2218
+ if self == DEFAULT
2219
+ DEFAULT
2220
+ else
2221
+ alter_type_array(@types, :generalize) { |altered_types| PTupleType.new(altered_types, @size_type) }
2222
+ end
2223
+ end
2224
+
2225
+ def normalize(guard = nil)
2226
+ if self == DEFAULT
2227
+ DEFAULT
2228
+ else
2229
+ alter_type_array(@types, :normalize, guard) { |altered_types| PTupleType.new(altered_types, @size_type) }
2230
+ end
2231
+ end
2232
+
2233
+ def resolve(loader)
2234
+ changed = false
2235
+ rtypes = @types.map do |type|
2236
+ rtype = type.resolve(loader)
2237
+ changed ||= !rtype.equal?(type)
2238
+ rtype
2239
+ end
2240
+ changed ? self.class.new(rtypes, @size_type) : self
2241
+ end
2242
+
2243
+ def instance?(o, guard = nil)
2244
+ # The inferred type of a class derived from Array is either Runtime or Object. It's not assignable to the Tuple type.
2245
+ return false unless o.instance_of?(Array)
2246
+ if @size_type
2247
+ return false unless @size_type.instance?(o.size, guard)
2248
+ else
2249
+ return false unless @types.empty? || @types.size == o.size
2250
+ end
2251
+ index = -1
2252
+ @types.empty? || o.all? do |element|
2253
+ @types.fetch(index += 1) { @types.last }.instance?(element, guard)
2254
+ end
2255
+ end
2256
+
2257
+ def iterable?(guard = nil)
2258
+ true
2259
+ end
2260
+
2261
+ def iterable_type(guard = nil)
2262
+ PIterableType.new(PVariantType.maybe_create(types))
2263
+ end
2264
+
2265
+ # Returns the number of elements accepted [min, max] in the tuple
2266
+ def size_range
2267
+ if @size_type.nil?
2268
+ types_size = @types.size
2269
+ types_size == 0 ? [0, Float::INFINITY] : [types_size, types_size]
2270
+ else
2271
+ @size_type.range
2272
+ end
2273
+ end
2274
+
2275
+ # Returns the number of accepted occurrences [min, max] of the last type in the tuple
2276
+ # The defaults is [1,1]
2277
+ #
2278
+ def repeat_last_range
2279
+ if @size_type.nil?
2280
+ return [1, 1]
2281
+ end
2282
+ types_size = @types.size
2283
+ from, to = @size_type.range
2284
+ min = from - (types_size-1)
2285
+ min = min <= 0 ? 0 : min
2286
+ max = to - (types_size-1)
2287
+ [min, max]
2288
+ end
2289
+
2290
+ def hash
2291
+ @size_type.hash ^ @types.hash
2292
+ end
2293
+
2294
+ def eql?(o)
2295
+ self.class == o.class && @types == o.types && @size_type == o.size_type
2296
+ end
2297
+
2298
+ def new_function
2299
+ # Simply delegate to Array type and let the higher level assertion deal with
2300
+ # compliance with the Tuple type regarding the produced result.
2301
+ PArrayType.new_function(self)
2302
+ end
2303
+
2304
+ DEFAULT = PTupleType.new(EMPTY_ARRAY)
2305
+
2306
+ protected
2307
+
2308
+ # @api private
2309
+ def _assignable?(o, guard)
2310
+ return true if self == o
2311
+ return false unless o.is_a?(PTupleType) || o.is_a?(PArrayType)
2312
+ s_types = types
2313
+ size_s = size_type || PIntegerType.new(*size_range)
2314
+
2315
+ if o.is_a?(PTupleType)
2316
+ size_o = o.size_type || PIntegerType.new(*o.size_range)
2317
+ return false unless size_s.assignable?(size_o, guard)
2318
+ unless s_types.empty?
2319
+ o_types = o.types
2320
+ return size_s.numeric_from == 0 if o_types.empty?
2321
+ o_types.size.times do |index|
2322
+ return false unless (s_types[index] || s_types[-1]).assignable?(o_types[index], guard)
2323
+ end
2324
+ end
2325
+ else
2326
+ size_o = o.size_type || PCollectionType::DEFAULT_SIZE
2327
+ return false unless size_s.assignable?(size_o, guard)
2328
+ unless s_types.empty?
2329
+ o_entry = o.element_type
2330
+ # Array of anything can not be assigned (unless tuple is tuple of anything) - this case
2331
+ # was handled at the top of this method.
2332
+ #
2333
+ return false if o_entry.nil?
2334
+ [s_types.size, size_o.range[1]].min.times { |index| return false unless (s_types[index] || s_types[-1]).assignable?(o_entry, guard) }
2335
+ end
2336
+ end
2337
+ true
2338
+ end
2339
+ end
2340
+
2341
+ # @api public
2342
+ #
2343
+ class PCallableType < PAnyType
2344
+ def self.register_ptype(loader, ir)
2345
+ create_ptype(loader, ir, 'AnyType',
2346
+ 'param_types' => {
2347
+ KEY_TYPE => POptionalType.new(PTypeType.new(PTupleType::DEFAULT)),
2348
+ KEY_VALUE => nil
2349
+ },
2350
+ 'block_type' => {
2351
+ KEY_TYPE => POptionalType.new(PTypeType.new(PCallableType::DEFAULT)),
2352
+ KEY_VALUE => nil
2353
+ },
2354
+ 'return_type' => {
2355
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
2356
+ KEY_VALUE => PAnyType::DEFAULT
2357
+ }
2358
+ )
2359
+ end
2360
+
2361
+ # @return [PAnyType] The type for the values returned by this callable. Returns `nil` if return value is unconstrained
2362
+ attr_reader :return_type
2363
+
2364
+ # Types of parameters as a Tuple with required/optional count, or an Integer with min (required), max count
2365
+ # @return [PTupleType] the tuple representing the parameter types
2366
+ attr_reader :param_types
2367
+
2368
+ # Although being an abstract type reference, only Callable, or all Callables wrapped in
2369
+ # Optional or Variant are supported
2370
+ # If not set, the meaning is that block is not supported.
2371
+ # @return [PAnyType|nil] the block type
2372
+ attr_reader :block_type
2373
+
2374
+ # @param param_types [PTupleType]
2375
+ # @param block_type [PAnyType]
2376
+ # @param return_type [PAnyType]
2377
+ def initialize(param_types, block_type = nil, return_type = nil)
2378
+ @param_types = param_types
2379
+ @block_type = block_type
2380
+ @return_type = return_type == PAnyType::DEFAULT ? nil : return_type
2381
+ end
2382
+
2383
+ def accept(visitor, guard)
2384
+ super
2385
+ @param_types.accept(visitor, guard) unless @param_types.nil?
2386
+ @block_type.accept(visitor, guard) unless @block_type.nil?
2387
+ @return_type.accept(visitor, guard) unless @return_type.nil?
2388
+ end
2389
+
2390
+ def generalize
2391
+ if self == DEFAULT
2392
+ DEFAULT
2393
+ else
2394
+ params_t = @param_types.nil? ? nil : @param_types.generalize
2395
+ block_t = @block_type.nil? ? nil : @block_type.generalize
2396
+ return_t = @return_type.nil? ? nil : @return_type.generalize
2397
+ @param_types.equal?(params_t) && @block_type.equal?(block_t) && @return_type.equal?(return_t) ? self : PCallableType.new(params_t, block_t, return_t)
2398
+ end
2399
+ end
2400
+
2401
+ def normalize(guard = nil)
2402
+ if self == DEFAULT
2403
+ DEFAULT
2404
+ else
2405
+ params_t = @param_types.nil? ? nil : @param_types.normalize(guard)
2406
+ block_t = @block_type.nil? ? nil : @block_type.normalize(guard)
2407
+ return_t = @return_type.nil? ? nil : @return_type.normalize(guard)
2408
+ @param_types.equal?(params_t) && @block_type.equal?(block_t) && @return_type.equal?(return_t) ? self : PCallableType.new(params_t, block_t, return_t)
2409
+ end
2410
+ end
2411
+
2412
+ def instance?(o, guard = nil)
2413
+ (o.is_a?(Proc) || o.is_a?(Evaluator::Closure) || o.is_a?(Functions::Function)) && assignable?(TypeCalculator.infer(o), guard)
2414
+ end
2415
+
2416
+ # Returns `true` if this instance is a callable that accepts the given _args_
2417
+ #
2418
+ # @param args [Array] the arguments to test
2419
+ # @return [Boolean] `true` if this instance is a callable that accepts the given _args_
2420
+ def callable_with?(args, block = nil)
2421
+ # nil param_types and compatible return type means other Callable is assignable
2422
+ return true if @param_types.nil?
2423
+ return false unless @param_types.instance?(args)
2424
+ if @block_type.nil?
2425
+ block == nil
2426
+ else
2427
+ @block_type.instance?(block)
2428
+ end
2429
+ end
2430
+
2431
+ # @api private
2432
+ def callable_args?(required_callable_t, guard)
2433
+ # If the required callable is equal or more specific than self, self is acceptable arguments
2434
+ required_callable_t.assignable?(self, guard)
2435
+ end
2436
+
2437
+ def kind_of_callable?(optional=true, guard = nil)
2438
+ true
2439
+ end
2440
+
2441
+ # Returns the number of accepted arguments [min, max]
2442
+ def size_range
2443
+ @param_types.nil? ? nil : @param_types.size_range
2444
+ end
2445
+
2446
+ # Returns the number of accepted arguments for the last parameter type [min, max]
2447
+ #
2448
+ def last_range
2449
+ @param_types.nil? ? nil : @param_types.repeat_last_range
2450
+ end
2451
+
2452
+ # Range [0,0], [0,1], or [1,1] for the block
2453
+ #
2454
+ def block_range
2455
+ case block_type
2456
+ when POptionalType
2457
+ [0,1]
2458
+ when PVariantType, PCallableType
2459
+ [1,1]
2460
+ else
2461
+ [0,0]
2462
+ end
2463
+ end
2464
+
2465
+ def hash
2466
+ [@param_types, @block_type, @return_type].hash
2467
+ end
2468
+
2469
+ def eql?(o)
2470
+ self.class == o.class && @param_types == o.param_types && @block_type == o.block_type && @return_type == o.return_type
2471
+ end
2472
+
2473
+ def resolve(loader)
2474
+ params_t = @param_types.nil? ? nil : @param_types.resolve(loader)
2475
+ block_t = @block_type.nil? ? nil : @block_type.resolve(loader)
2476
+ return_t = @return_type.nil? ? nil : @return_type.resolve(loader)
2477
+ @param_types.equal?(params_t) && @block_type.equal?(block_t) && @return_type.equal?(return_t) ? self : self.class.new(params_t, block_t, return_t)
2478
+ end
2479
+
2480
+ DEFAULT = PCallableType.new(nil, nil, nil)
2481
+
2482
+ protected
2483
+
2484
+ # @api private
2485
+ def _assignable?(o, guard)
2486
+ return false unless o.is_a?(PCallableType)
2487
+ return false unless @return_type.nil? || @return_type.assignable?(o.return_type || PAnyType::DEFAULT, guard)
2488
+
2489
+ # nil param_types and compatible return type means other Callable is assignable
2490
+ return true if @param_types.nil?
2491
+
2492
+ # NOTE: these tests are made in reverse as it is calling the callable that is constrained
2493
+ # (it's lower bound), not its upper bound
2494
+ other_param_types = o.param_types
2495
+
2496
+ return false if other_param_types.nil? || !other_param_types.assignable?(@param_types, guard)
2497
+ # names are ignored, they are just information
2498
+ # Blocks must be compatible
2499
+ this_block_t = @block_type || PUndefType::DEFAULT
2500
+ that_block_t = o.block_type || PUndefType::DEFAULT
2501
+ that_block_t.assignable?(this_block_t, guard)
2502
+ end
2503
+ end
2504
+
2505
+ # @api public
2506
+ #
2507
+ class PArrayType < PCollectionType
2508
+
2509
+ def self.register_ptype(loader, ir)
2510
+ create_ptype(loader, ir, 'CollectionType',
2511
+ 'element_type' => {
2512
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
2513
+ KEY_VALUE => PAnyType::DEFAULT
2514
+ }
2515
+ )
2516
+ end
2517
+
2518
+ attr_reader :element_type
2519
+
2520
+ def initialize(element_type, size_type = nil)
2521
+ super(size_type)
2522
+ if !size_type.nil? && size_type.from == 0 && size_type.to == 0
2523
+ @element_type = PUnitType::DEFAULT
2524
+ else
2525
+ @element_type = element_type.nil? ? PAnyType::DEFAULT : element_type
2526
+ end
2527
+ end
2528
+
2529
+ def accept(visitor, guard)
2530
+ super
2531
+ @element_type.accept(visitor, guard)
2532
+ end
2533
+
2534
+ # @api private
2535
+ def callable_args?(callable, guard = nil)
2536
+ param_t = callable.param_types
2537
+ block_t = callable.block_type
2538
+ # does not support calling with a block, but have to check that callable is ok with missing block
2539
+ (param_t.nil? || param_t.assignable?(self, guard)) && (block_t.nil? || block_t.assignable?(PUndefType::DEFAULT, guard))
2540
+ end
2541
+
2542
+ def generalize
2543
+ if PAnyType::DEFAULT.eql?(@element_type)
2544
+ DEFAULT
2545
+ else
2546
+ ge_type = @element_type.generalize
2547
+ @size_type.nil? && @element_type.equal?(ge_type) ? self : self.class.new(ge_type, nil)
2548
+ end
2549
+ end
2550
+
2551
+ def eql?(o)
2552
+ super && @element_type == o.element_type
2553
+ end
2554
+
2555
+ def hash
2556
+ super ^ @element_type.hash
2557
+ end
2558
+
2559
+ def normalize(guard = nil)
2560
+ if PAnyType::DEFAULT.eql?(@element_type)
2561
+ DEFAULT
2562
+ else
2563
+ ne_type = @element_type.normalize(guard)
2564
+ @element_type.equal?(ne_type) ? self : self.class.new(ne_type, @size_type)
2565
+ end
2566
+ end
2567
+
2568
+ def resolve(loader)
2569
+ relement_type = @element_type.resolve(loader)
2570
+ relement_type.equal?(@element_type) ? self : self.class.new(relement_type, @size_type)
2571
+ end
2572
+
2573
+ def instance?(o, guard = nil)
2574
+ # The inferred type of a class derived from Array is either Runtime or Object. It's not assignable to the Array type.
2575
+ return false unless o.instance_of?(Array)
2576
+ return false unless o.all? {|element| @element_type.instance?(element, guard) }
2577
+ size_t = size_type
2578
+ size_t.nil? || size_t.instance?(o.size, guard)
2579
+ end
2580
+
2581
+ def iterable_type(guard = nil)
2582
+ PAnyType::DEFAULT.eql?(@element_type) ? PIterableType::DEFAULT : PIterableType.new(@element_type)
2583
+ end
2584
+
2585
+ # Returns a new function that produces an Array
2586
+ #
2587
+ def self.new_function(type)
2588
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_array, type.loader) do
2589
+
2590
+ dispatch :to_array do
2591
+ param 'Variant[Array,Hash,Binary,Iterable]', :from
2592
+ optional_param 'Boolean[false]', :wrap
2593
+ end
2594
+
2595
+ dispatch :wrapped do
2596
+ param 'Any', :from
2597
+ param 'Boolean[true]', :wrap
2598
+ end
2599
+
2600
+ argument_mismatch :on_error do
2601
+ param 'Any', :from
2602
+ optional_param 'Boolean', :wrap
2603
+ end
2604
+
2605
+ def wrapped(from, _)
2606
+ from.is_a?(Array) ? from : [from]
2607
+ end
2608
+
2609
+ def to_array(from, _ = false)
2610
+ case from
2611
+ when Array
2612
+ from
2613
+ when Hash
2614
+ from.to_a
2615
+ when PBinaryType::Binary
2616
+ # For older rubies, the #bytes method returns an Enumerator that must be rolled out
2617
+ from.binary_buffer.bytes.to_a
2618
+ else
2619
+ Iterable.on(from).to_a
2620
+ end
2621
+ end
2622
+
2623
+ def on_error(from, _ = false)
2624
+ t = TypeCalculator.singleton.infer(from).generalize
2625
+ _("Value of type %{type} cannot be converted to Array") % { type: t }
2626
+ end
2627
+ end
2628
+ end
2629
+
2630
+ DEFAULT = PArrayType.new(nil)
2631
+ EMPTY = PArrayType.new(PUnitType::DEFAULT, ZERO_SIZE)
2632
+
2633
+ protected
2634
+
2635
+ # Array is assignable if o is an Array and o's element type is assignable, or if o is a Tuple
2636
+ # @api private
2637
+ def _assignable?(o, guard)
2638
+ if o.is_a?(PTupleType)
2639
+ o_types = o.types
2640
+ size_s = size_type || DEFAULT_SIZE
2641
+ size_o = o.size_type
2642
+ if size_o.nil?
2643
+ type_count = o_types.size
2644
+ size_o = PIntegerType.new(type_count, type_count)
2645
+ end
2646
+ size_s.assignable?(size_o) && o_types.all? { |ot| @element_type.assignable?(ot, guard) }
2647
+ elsif o.is_a?(PArrayType)
2648
+ super && @element_type.assignable?(o.element_type, guard)
2649
+ else
2650
+ false
2651
+ end
2652
+ end
2653
+ end
2654
+
2655
+ # @api public
2656
+ #
2657
+ class PHashType < PCollectionType
2658
+
2659
+ def self.register_ptype(loader, ir)
2660
+ create_ptype(loader, ir, 'CollectionType',
2661
+ 'key_type' => {
2662
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
2663
+ KEY_VALUE => PAnyType::DEFAULT
2664
+ },
2665
+ 'value_type' => {
2666
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
2667
+ KEY_VALUE => PAnyType::DEFAULT
2668
+ }
2669
+ )
2670
+ end
2671
+
2672
+ attr_accessor :key_type, :value_type
2673
+
2674
+ def initialize(key_type, value_type, size_type = nil)
2675
+ super(size_type)
2676
+ if !size_type.nil? && size_type.from == 0 && size_type.to == 0
2677
+ @key_type = PUnitType::DEFAULT
2678
+ @value_type = PUnitType::DEFAULT
2679
+ else
2680
+ @key_type = key_type.nil? ? PAnyType::DEFAULT : key_type
2681
+ @value_type = value_type.nil? ? PAnyType::DEFAULT : value_type
2682
+ end
2683
+ end
2684
+
2685
+ def accept(visitor, guard)
2686
+ super
2687
+ @key_type.accept(visitor, guard)
2688
+ @value_type.accept(visitor, guard)
2689
+ end
2690
+
2691
+ def element_type
2692
+ if Puppet[:strict] != :off
2693
+ #TRANSLATOR 'Puppet::Pops::Types::PHashType#element_type' and '#value_type' are class and method names and should not be translated
2694
+ Puppet.warn_once('deprecations', 'Puppet::Pops::Types::PHashType#element_type',
2695
+ _('Puppet::Pops::Types::PHashType#element_type is deprecated, use #value_type instead'))
2696
+ end
2697
+ @value_type
2698
+ end
2699
+
2700
+ def generalize
2701
+ if self == DEFAULT || self == EMPTY
2702
+ self
2703
+ else
2704
+ key_t = @key_type
2705
+ key_t = key_t.generalize
2706
+ value_t = @value_type
2707
+ value_t = value_t.generalize
2708
+ @size_type.nil? && @key_type.equal?(key_t) && @value_type.equal?(value_t) ? self : PHashType.new(key_t, value_t, nil)
2709
+ end
2710
+ end
2711
+
2712
+ def normalize(guard = nil)
2713
+ if self == DEFAULT || self == EMPTY
2714
+ self
2715
+ else
2716
+ key_t = @key_type.normalize(guard)
2717
+ value_t = @value_type.normalize(guard)
2718
+ @size_type.nil? && @key_type.equal?(key_t) && @value_type.equal?(value_t) ? self : PHashType.new(key_t, value_t, @size_type)
2719
+ end
2720
+ end
2721
+
2722
+ def hash
2723
+ super ^ @key_type.hash ^ @value_type.hash
2724
+ end
2725
+
2726
+ def instance?(o, guard = nil)
2727
+ # The inferred type of a class derived from Hash is either Runtime or Object. It's not assignable to the Hash type.
2728
+ return false unless o.instance_of?(Hash)
2729
+ if o.keys.all? {|key| @key_type.instance?(key, guard) } && o.values.all? {|value| @value_type.instance?(value, guard) }
2730
+ size_t = size_type
2731
+ size_t.nil? || size_t.instance?(o.size, guard)
2732
+ else
2733
+ false
2734
+ end
2735
+ end
2736
+
2737
+ def iterable?(guard = nil)
2738
+ true
2739
+ end
2740
+
2741
+ def iterable_type(guard = nil)
2742
+ if self == DEFAULT || self == EMPTY
2743
+ PIterableType.new(DEFAULT_KEY_PAIR_TUPLE)
2744
+ else
2745
+ PIterableType.new(PTupleType.new([@key_type, @value_type], KEY_PAIR_TUPLE_SIZE))
2746
+ end
2747
+ end
2748
+
2749
+ def eql?(o)
2750
+ super && @key_type == o.key_type && @value_type == o.value_type
2751
+ end
2752
+
2753
+ def is_the_empty_hash?
2754
+ self == EMPTY
2755
+ end
2756
+
2757
+ def resolve(loader)
2758
+ rkey_type = @key_type.resolve(loader)
2759
+ rvalue_type = @value_type.resolve(loader)
2760
+ rkey_type.equal?(@key_type) && rvalue_type.equal?(@value_type) ? self : self.class.new(rkey_type, rvalue_type, @size_type)
2761
+ end
2762
+
2763
+ def self.array_as_hash(value)
2764
+ return value unless value.is_a?(Array)
2765
+ result = {}
2766
+ value.each_with_index {|v, idx| result[idx] = array_as_hash(v) }
2767
+ result
2768
+ end
2769
+
2770
+ # Returns a new function that produces a Hash
2771
+ #
2772
+ def self.new_function(type)
2773
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_hash, type.loader) do
2774
+ local_types do
2775
+ type 'KeyValueArray = Array[Tuple[Any,Any],1]'
2776
+ type 'TreeArray = Array[Tuple[Array,Any],1]'
2777
+ type 'NewHashOption = Enum[tree, hash_tree]'
2778
+ end
2779
+
2780
+ dispatch :from_tree do
2781
+ param 'TreeArray', :from
2782
+ optional_param 'NewHashOption', :build_option
2783
+ end
2784
+
2785
+ dispatch :from_tuples do
2786
+ param 'KeyValueArray', :from
2787
+ end
2788
+
2789
+ dispatch :from_array do
2790
+ param 'Any', :from
2791
+ end
2792
+
2793
+ def from_tuples(tuple_array)
2794
+ Hash[tuple_array]
2795
+ end
2796
+
2797
+ def from_tree(tuple_array, build_option = nil)
2798
+ if build_option.nil?
2799
+ return from_tuples(tuple_array)
2800
+ end
2801
+ # only remaining possible options is 'tree' or 'hash_tree'
2802
+
2803
+ all_hashes = build_option == 'hash_tree'
2804
+ result = {}
2805
+ tuple_array.each do |entry|
2806
+ path = entry[0]
2807
+ value = entry[1]
2808
+ if path.empty?
2809
+ # root node (index [] was included - values merge into the result)
2810
+ # An array must be changed to a hash first as this is the root
2811
+ # (Cannot return an array from a Hash.new)
2812
+ if value.is_a?(Array)
2813
+ value.each_with_index {|v, idx| result[idx] = v }
2814
+ else
2815
+ result.merge!(value)
2816
+ end
2817
+ else
2818
+ r = path[0..-2].reduce(result) {|memo, idx| (memo.is_a?(Array) || memo.has_key?(idx)) ? memo[idx] : memo[idx] = {}}
2819
+ r[path[-1]]= (all_hashes ? PHashType.array_as_hash(value) : value)
2820
+ end
2821
+ end
2822
+ result
2823
+ end
2824
+
2825
+ def from_array(from)
2826
+ case from
2827
+ when Array
2828
+ if from.size == 0
2829
+ {}
2830
+ else
2831
+ unless from.size % 2 == 0
2832
+ raise TypeConversionError.new(_('odd number of arguments for Hash'))
2833
+ end
2834
+ Hash[*from]
2835
+ end
2836
+ when Hash
2837
+ from
2838
+ else
2839
+ if PIterableType::DEFAULT.instance?(from)
2840
+ Hash[*Iterable.on(from).to_a]
2841
+ else
2842
+ t = TypeCalculator.singleton.infer(from).generalize
2843
+ raise TypeConversionError.new(_("Value of type %{type} cannot be converted to Hash") % { type: t })
2844
+ end
2845
+ end
2846
+ end
2847
+ end
2848
+ end
2849
+
2850
+ DEFAULT = PHashType.new(nil, nil)
2851
+ KEY_PAIR_TUPLE_SIZE = PIntegerType.new(2,2)
2852
+ DEFAULT_KEY_PAIR_TUPLE = PTupleType.new([PUnitType::DEFAULT, PUnitType::DEFAULT], KEY_PAIR_TUPLE_SIZE)
2853
+ EMPTY = PHashType.new(PUnitType::DEFAULT, PUnitType::DEFAULT, PIntegerType.new(0, 0))
2854
+
2855
+ protected
2856
+
2857
+ # Hash is assignable if o is a Hash and o's key and element types are assignable
2858
+ # @api private
2859
+ def _assignable?(o, guard)
2860
+ case o
2861
+ when PHashType
2862
+ size_s = size_type
2863
+ return true if (size_s.nil? || size_s.from == 0) && o.is_the_empty_hash?
2864
+ return false unless @key_type.assignable?(o.key_type, guard) && @value_type.assignable?(o.value_type, guard)
2865
+ super
2866
+ when PStructType
2867
+ # hash must accept String as key type
2868
+ # hash must accept all value types
2869
+ # hash must accept the size of the struct
2870
+ o_elements = o.elements
2871
+ (size_type || DEFAULT_SIZE).instance?(o_elements.size, guard) &&
2872
+ o_elements.all? {|e| @key_type.instance?(e.name, guard) && @value_type.assignable?(e.value_type, guard) }
2873
+ else
2874
+ false
2875
+ end
2876
+ end
2877
+ end
2878
+
2879
+ # A flexible type describing an any? of other types
2880
+ # @api public
2881
+ #
2882
+ class PVariantType < PAnyType
2883
+ include Enumerable
2884
+
2885
+ def self.register_ptype(loader, ir)
2886
+ create_ptype(loader, ir, 'AnyType', 'types' => PArrayType.new(PTypeType::DEFAULT))
2887
+ end
2888
+
2889
+ attr_reader :types
2890
+
2891
+ # Checks if the number of unique types in the given array is greater than one, and if so
2892
+ # creates a Variant with those types and returns it. If only one unique type is found,
2893
+ # that type is instead returned.
2894
+ #
2895
+ # @param types [Array<PAnyType>] the variants
2896
+ # @return [PAnyType] the resulting type
2897
+ # @api public
2898
+ def self.maybe_create(types)
2899
+ types = flatten_variants(types).uniq
2900
+ types.size == 1 ? types[0] : new(types)
2901
+ end
2902
+
2903
+ # @param types [Array[PAnyType]] the variants
2904
+ def initialize(types)
2905
+ @types = types.freeze
2906
+ end
2907
+
2908
+ def accept(visitor, guard)
2909
+ super
2910
+ @types.each { |t| t.accept(visitor, guard) }
2911
+ end
2912
+
2913
+ def each
2914
+ if block_given?
2915
+ types.each { |t| yield t }
2916
+ else
2917
+ types.to_enum
2918
+ end
2919
+ end
2920
+
2921
+ def generalize
2922
+ if self == DEFAULT
2923
+ self
2924
+ else
2925
+ alter_type_array(@types, :generalize) { |altered| PVariantType.maybe_create(altered) }
2926
+ end
2927
+ end
2928
+
2929
+ def normalize(guard = nil)
2930
+ if self == DEFAULT || @types.empty?
2931
+ self
2932
+ else
2933
+ # Normalize all contained types
2934
+ modified = false
2935
+ types = alter_type_array(@types, :normalize, guard)
2936
+ if types == self
2937
+ types = @types
2938
+ else
2939
+ modified = true
2940
+ end
2941
+
2942
+ if types.size == 1
2943
+ types[0]
2944
+ elsif types.any? { |t| t.is_a?(PUndefType) || t.is_a?(POptionalType) }
2945
+ # Undef entry present. Use an OptionalType with a normalized Variant without Undefs and Optional wrappers
2946
+ POptionalType.new(PVariantType.maybe_create(types.reject { |t| t.is_a?(PUndefType) }.map { |t| t.is_a?(POptionalType) ? t.type : t })).normalize
2947
+ else
2948
+ # Merge all variants into this one
2949
+ types = PVariantType.flatten_variants(types)
2950
+ size_before_merge = types.size
2951
+
2952
+ types = swap_not_undefs(types)
2953
+ types = merge_enums(types)
2954
+ types = merge_patterns(types)
2955
+ types = merge_version_ranges(types)
2956
+ types = merge_numbers(PIntegerType, types)
2957
+ types = merge_numbers(PFloatType, types)
2958
+ types = merge_numbers(PTimespanType, types)
2959
+ types = merge_numbers(PTimestampType, types)
2960
+
2961
+ if types.size == 1
2962
+ types[0]
2963
+ else
2964
+ modified || types.size != size_before_merge ? PVariantType.maybe_create(types) : self
2965
+ end
2966
+ end
2967
+ end
2968
+ end
2969
+
2970
+ def self.flatten_variants(types)
2971
+ modified = false
2972
+ types = types.map do |t|
2973
+ if t.is_a?(PVariantType)
2974
+ modified = true
2975
+ t.types
2976
+ else
2977
+ t
2978
+ end
2979
+ end
2980
+ types.flatten! if modified
2981
+ types
2982
+ end
2983
+
2984
+ def hash
2985
+ @types.hash
2986
+ end
2987
+
2988
+ def instance?(o, guard = nil)
2989
+ # instance of variant if o is instance? of any of variant's types
2990
+ @types.any? { |type| type.instance?(o, guard) }
2991
+ end
2992
+
2993
+ def really_instance?(o, guard = nil)
2994
+ @types.reduce(-1) do |memo, type|
2995
+ ri = type.really_instance?(o, guard)
2996
+ break ri if ri > 0
2997
+ ri > memo ? ri : memo
2998
+ end
2999
+ end
3000
+
3001
+ def kind_of_callable?(optional = true, guard = nil)
3002
+ @types.all? { |type| type.kind_of_callable?(optional, guard) }
3003
+ end
3004
+
3005
+ def eql?(o)
3006
+ self.class == o.class && @types.size == o.types.size && (@types - o.types).empty?
3007
+ end
3008
+
3009
+ DEFAULT = PVariantType.new(EMPTY_ARRAY)
3010
+
3011
+ def assignable?(o, guard = nil)
3012
+ # an empty Variant does not match Undef (it is void - not even undef)
3013
+ if o.is_a?(PUndefType) && types.empty?
3014
+ return false
3015
+ end
3016
+
3017
+ return super unless o.is_a?(PVariantType)
3018
+ # If empty, all Variant types match irrespective of the types they hold (including being empty)
3019
+ return true if types.empty?
3020
+ # Since this variant is not empty, an empty Variant cannot match, because it matches nothing
3021
+ # otherwise all types in o must be assignable to this
3022
+ !o.types.empty? && o.types.all? { |vt| super(vt, guard) }
3023
+ end
3024
+
3025
+ protected
3026
+
3027
+ # @api private
3028
+ def _assignable?(o, guard)
3029
+ # A variant is assignable if o is assignable to any of its types
3030
+ types.any? { |option_t| option_t.assignable?(o, guard) }
3031
+ end
3032
+
3033
+ # @api private
3034
+ def swap_not_undefs(array)
3035
+ if array.size > 1
3036
+ parts = array.partition {|t| t.is_a?(PNotUndefType) }
3037
+ not_undefs = parts[0]
3038
+ if not_undefs.size > 1
3039
+ others = parts[1]
3040
+ others << PNotUndefType.new(PVariantType.maybe_create(not_undefs.map { |not_undef| not_undef.type }).normalize)
3041
+ array = others
3042
+ end
3043
+ end
3044
+ array
3045
+ end
3046
+
3047
+ # @api private
3048
+ def merge_enums(array)
3049
+ # Merge case sensitive enums and strings
3050
+ if array.size > 1
3051
+ parts = array.partition {|t| t.is_a?(PEnumType) && !t.values.empty? && !t.case_insensitive? || t.is_a?(PStringType) && !t.value.nil? }
3052
+ enums = parts[0]
3053
+ if enums.size > 1
3054
+ others = parts[1]
3055
+ others << PEnumType.new(enums.map { |enum| enum.is_a?(PStringType) ? enum.value : enum.values }.flatten.uniq)
3056
+ array = others
3057
+ end
3058
+ end
3059
+
3060
+ # Merge case insensitive enums
3061
+ if array.size > 1
3062
+ parts = array.partition {|t| t.is_a?(PEnumType) && !t.values.empty? && t.case_insensitive? }
3063
+ enums = parts[0]
3064
+ if enums.size > 1
3065
+ others = parts[1]
3066
+ values = []
3067
+ enums.each { |enum| enum.values.each { |value| values << value.downcase }}
3068
+ values.uniq!
3069
+ others << PEnumType.new(values, true)
3070
+ array = others
3071
+ end
3072
+ end
3073
+ array
3074
+ end
3075
+
3076
+ # @api private
3077
+ def merge_patterns(array)
3078
+ if array.size > 1
3079
+ parts = array.partition {|t| t.is_a?(PPatternType) }
3080
+ patterns = parts[0]
3081
+ if patterns.size > 1
3082
+ others = parts[1]
3083
+ others << PPatternType.new(patterns.map { |pattern| pattern.patterns }.flatten.uniq)
3084
+ array = others
3085
+ end
3086
+ end
3087
+ array
3088
+ end
3089
+
3090
+ # @api private
3091
+ def merge_numbers(clazz, array)
3092
+ if array.size > 1
3093
+ parts = array.partition {|t| t.is_a?(clazz) }
3094
+ ranges = parts[0]
3095
+ array = merge_ranges(ranges) + parts[1] if ranges.size > 1
3096
+ end
3097
+ array
3098
+ end
3099
+
3100
+ def merge_version_ranges(array)
3101
+ if array.size > 1
3102
+ parts = array.partition {|t| t.is_a?(PSemVerType) }
3103
+ ranges = parts[0]
3104
+ array = [PSemVerType.new(ranges.map(&:ranges).flatten)] + parts[1] if ranges.size > 1
3105
+ end
3106
+ array
3107
+ end
3108
+
3109
+ # @api private
3110
+ def merge_ranges(ranges)
3111
+ result = []
3112
+ until ranges.empty?
3113
+ unmerged = []
3114
+ x = ranges.pop
3115
+ result << ranges.inject(x) do |memo, y|
3116
+ merged = memo.merge(y)
3117
+ if merged.nil?
3118
+ unmerged << y
3119
+ else
3120
+ memo = merged
3121
+ end
3122
+ memo
3123
+ end
3124
+ ranges = unmerged
3125
+ end
3126
+ result
3127
+ end
3128
+ end
3129
+
3130
+ # Abstract representation of a type that can be placed in a Catalog.
3131
+ # @api public
3132
+ #
3133
+ class PCatalogEntryType < PAnyType
3134
+ def self.register_ptype(loader, ir)
3135
+ create_ptype(loader, ir, 'AnyType')
3136
+ end
3137
+
3138
+ DEFAULT = PCatalogEntryType.new
3139
+
3140
+ def instance?(o, guard = nil)
3141
+ assignable?(TypeCalculator.infer(o), guard)
3142
+ end
3143
+
3144
+ protected
3145
+ # @api private
3146
+ def _assignable?(o, guard)
3147
+ o.is_a?(PCatalogEntryType)
3148
+ end
3149
+ end
3150
+
3151
+ # Represents a (host-) class in the Puppet Language.
3152
+ # @api public
3153
+ #
3154
+ class PClassType < PCatalogEntryType
3155
+ attr_reader :class_name
3156
+
3157
+ def self.register_ptype(loader, ir)
3158
+ create_ptype(loader, ir, 'CatalogEntryType',
3159
+ 'class_name' => {
3160
+ KEY_TYPE => POptionalType.new(PStringType::NON_EMPTY),
3161
+ KEY_VALUE => nil
3162
+ }
3163
+ )
3164
+ end
3165
+
3166
+ def initialize(class_name)
3167
+ @class_name = class_name
3168
+ end
3169
+
3170
+ def hash
3171
+ 11 ^ @class_name.hash
3172
+ end
3173
+ def eql?(o)
3174
+ self.class == o.class && @class_name == o.class_name
3175
+ end
3176
+
3177
+ DEFAULT = PClassType.new(nil)
3178
+
3179
+ protected
3180
+
3181
+ # @api private
3182
+ def _assignable?(o, guard)
3183
+ return false unless o.is_a?(PClassType)
3184
+ # Class = Class[name}, Class[name] != Class
3185
+ return true if @class_name.nil?
3186
+ # Class[name] = Class[name]
3187
+ @class_name == o.class_name
3188
+ end
3189
+ end
3190
+
3191
+ # For backward compatibility
3192
+ PHostClassType = PClassType
3193
+
3194
+
3195
+ # Represents a Resource Type in the Puppet Language
3196
+ # @api public
3197
+ #
3198
+ class PResourceType < PCatalogEntryType
3199
+
3200
+ def self.register_ptype(loader, ir)
3201
+ create_ptype(loader, ir, 'CatalogEntryType',
3202
+ 'type_name' => {
3203
+ KEY_TYPE => POptionalType.new(PStringType::NON_EMPTY),
3204
+ KEY_VALUE => nil
3205
+ },
3206
+ 'title' => {
3207
+ KEY_TYPE => POptionalType.new(PStringType::NON_EMPTY),
3208
+ KEY_VALUE => nil
3209
+ }
3210
+ )
3211
+ end
3212
+
3213
+ attr_reader :type_name, :title, :downcased_name
3214
+
3215
+ def initialize(type_name, title = nil)
3216
+ @type_name = type_name.freeze
3217
+ @title = title.freeze
3218
+ @downcased_name = type_name.nil? ? nil : @type_name.downcase.freeze
3219
+ end
3220
+
3221
+ def eql?(o)
3222
+ self.class == o.class && @downcased_name == o.downcased_name && @title == o.title
3223
+ end
3224
+
3225
+ def hash
3226
+ @downcased_name.hash ^ @title.hash
3227
+ end
3228
+
3229
+ DEFAULT = PResourceType.new(nil)
3230
+
3231
+ protected
3232
+
3233
+ # @api private
3234
+ def _assignable?(o, guard)
3235
+ o.is_a?(PResourceType) && (@downcased_name.nil? || @downcased_name == o.downcased_name && (@title.nil? || @title == o.title))
3236
+ end
3237
+ end
3238
+
3239
+ # Represents a type that accept PUndefType instead of the type parameter
3240
+ # required_type - is a short hand for Variant[T, Undef]
3241
+ # @api public
3242
+ #
3243
+ class POptionalType < PTypeWithContainedType
3244
+
3245
+ def self.register_ptype(loader, ir)
3246
+ create_ptype(loader, ir, 'AnyType',
3247
+ 'type' => {
3248
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
3249
+ KEY_VALUE => nil
3250
+ }
3251
+ )
3252
+ end
3253
+
3254
+ def optional_type
3255
+ @type
3256
+ end
3257
+
3258
+ def kind_of_callable?(optional=true, guard = nil)
3259
+ optional && !@type.nil? && @type.kind_of_callable?(optional, guard)
3260
+ end
3261
+
3262
+ def instance?(o, guard = nil)
3263
+ PUndefType::DEFAULT.instance?(o, guard) || (!@type.nil? && @type.instance?(o, guard))
3264
+ end
3265
+
3266
+ def normalize(guard = nil)
3267
+ n = super
3268
+ if n.type.nil?
3269
+ n
3270
+ else
3271
+ if n.type.is_a?(PNotUndefType)
3272
+ # No point in having an NotUndef in an Optional
3273
+ POptionalType.new(n.type.type).normalize
3274
+ elsif n.type.assignable?(PUndefType::DEFAULT)
3275
+ # THe type is Optional anyway, so it can be stripped of
3276
+ n.type
3277
+ else
3278
+ n
3279
+ end
3280
+ end
3281
+ end
3282
+
3283
+ def new_function
3284
+ optional_type.new_function
3285
+ end
3286
+
3287
+ DEFAULT = POptionalType.new(nil)
3288
+
3289
+ protected
3290
+
3291
+ # @api private
3292
+ def _assignable?(o, guard)
3293
+ return true if o.is_a?(PUndefType)
3294
+ return true if @type.nil?
3295
+ if o.is_a?(POptionalType)
3296
+ @type.assignable?(o.optional_type, guard)
3297
+ else
3298
+ @type.assignable?(o, guard)
3299
+ end
3300
+ end
3301
+ end
3302
+
3303
+ class PTypeReferenceType < PAnyType
3304
+
3305
+ def self.register_ptype(loader, ir)
3306
+ create_ptype(loader, ir, 'AnyType', 'type_string' => PStringType::NON_EMPTY)
3307
+ end
3308
+
3309
+ attr_reader :type_string
3310
+
3311
+ def initialize(type_string)
3312
+ @type_string = type_string
3313
+ end
3314
+
3315
+ def callable?(args)
3316
+ false
3317
+ end
3318
+
3319
+ def instance?(o, guard = nil)
3320
+ false
3321
+ end
3322
+
3323
+ def hash
3324
+ @type_string.hash
3325
+ end
3326
+
3327
+ def eql?(o)
3328
+ super && o.type_string == @type_string
3329
+ end
3330
+
3331
+ def resolve(loader)
3332
+ TypeParser.singleton.parse(@type_string, loader)
3333
+ end
3334
+
3335
+ protected
3336
+
3337
+ def _assignable?(o, guard)
3338
+ # A type must be assignable to itself or a lot of unit tests will break
3339
+ o == self
3340
+ end
3341
+
3342
+ DEFAULT = PTypeReferenceType.new('UnresolvedReference')
3343
+ end
3344
+
3345
+ # Describes a named alias for another Type.
3346
+ # The alias is created with a name and an unresolved type expression. The type expression may
3347
+ # in turn contain other aliases (including the alias that contains it) which means that an alias
3348
+ # might contain self recursion. Whether or not that is the case is computed and remembered when the alias
3349
+ # is resolved since guarding against self recursive constructs is relatively expensive.
3350
+ #
3351
+ # @api public
3352
+ class PTypeAliasType < PAnyType
3353
+
3354
+ def self.register_ptype(loader, ir)
3355
+ create_ptype(loader, ir, 'AnyType',
3356
+ 'name' => PStringType::NON_EMPTY,
3357
+ 'type_expr' => PAnyType::DEFAULT,
3358
+ 'resolved_type' => {
3359
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
3360
+ KEY_VALUE => nil
3361
+ }
3362
+ )
3363
+ end
3364
+
3365
+ attr_reader :loader, :name
3366
+
3367
+ # @param name [String] The name of the type
3368
+ # @param type_expr [Model::PopsObject] The expression that describes the aliased type
3369
+ # @param resolved_type [PAnyType] the resolve type (only used for the DEFAULT initialization)
3370
+ def initialize(name, type_expr, resolved_type = nil)
3371
+ @name = name
3372
+ @type_expr = type_expr
3373
+ @resolved_type = resolved_type
3374
+ @self_recursion = false
3375
+ end
3376
+
3377
+ def assignable?(o, guard = nil)
3378
+ if @self_recursion
3379
+ guard ||= RecursionGuard.new
3380
+ guard.with_this(self) { |state| state == RecursionGuard::SELF_RECURSION_IN_BOTH ? true : super(o, guard) }
3381
+ else
3382
+ super(o, guard)
3383
+ end
3384
+ end
3385
+
3386
+ # Returns the resolved type. The type must have been resolved by a call prior to calls to this
3387
+ # method or an error will be raised.
3388
+ #
3389
+ # @return [PAnyType] The resolved type of this alias.
3390
+ # @raise [Puppet::Error] unless the type has been resolved prior to calling this method
3391
+ def resolved_type
3392
+ raise Puppet::Error, "Reference to unresolved type #{@name}" unless @resolved_type
3393
+ @resolved_type
3394
+ end
3395
+
3396
+ def callable_args?(callable, guard)
3397
+ guarded_recursion(guard, false) { |g| resolved_type.callable_args?(callable, g) }
3398
+ end
3399
+
3400
+ def check_self_recursion(originator)
3401
+ resolved_type.check_self_recursion(originator) unless originator.equal?(self)
3402
+ end
3403
+
3404
+ def kind_of_callable?(optional=true, guard = nil)
3405
+ guarded_recursion(guard, false) { |g| resolved_type.kind_of_callable?(optional, g) }
3406
+ end
3407
+
3408
+ def instance?(o, guard = nil)
3409
+ really_instance?(o, guard) == 1
3410
+ end
3411
+
3412
+ def iterable?(guard = nil)
3413
+ guarded_recursion(guard, false) { |g| resolved_type.iterable?(g) }
3414
+ end
3415
+
3416
+ def iterable_type(guard = nil)
3417
+ guarded_recursion(guard, nil) { |g| resolved_type.iterable_type(g) }
3418
+ end
3419
+
3420
+ def hash
3421
+ @name.hash
3422
+ end
3423
+
3424
+ # Acceptor used when checking for self recursion and that a type contains
3425
+ # something other than aliases or type references
3426
+ #
3427
+ # @api private
3428
+ class AssertOtherTypeAcceptor
3429
+ def initialize
3430
+ @other_type_detected = false
3431
+ end
3432
+
3433
+ def visit(type, _)
3434
+ unless type.is_a?(PTypeAliasType) || type.is_a?(PVariantType)
3435
+ @other_type_detected = true
3436
+ end
3437
+ end
3438
+
3439
+ def other_type_detected?
3440
+ @other_type_detected
3441
+ end
3442
+ end
3443
+
3444
+ # Acceptor used when re-checking for self recursion after a self recursion has been detected
3445
+ #
3446
+ # @api private
3447
+ class AssertSelfRecursionStatusAcceptor
3448
+ def visit(type, _)
3449
+ type.set_self_recursion_status if type.is_a?(PTypeAliasType)
3450
+ end
3451
+ end
3452
+
3453
+ def set_self_recursion_status
3454
+ return if @self_recursion || @resolved_type.is_a?(PTypeReferenceType)
3455
+ @self_recursion = true
3456
+ guard = RecursionGuard.new
3457
+ accept(NoopTypeAcceptor::INSTANCE, guard)
3458
+ @self_recursion = guard.recursive_this?(self)
3459
+ when_self_recursion_detected if @self_recursion # no difference
3460
+ end
3461
+
3462
+ # Called from the TypeParser once it has found a type using the Loader. The TypeParser will
3463
+ # interpret the contained expression and the resolved type is remembered. This method also
3464
+ # checks and remembers if the resolve type contains self recursion.
3465
+ #
3466
+ # @param type_parser [TypeParser] type parser that will interpret the type expression
3467
+ # @param loader [Loader::Loader] loader to use when loading type aliases
3468
+ # @return [PTypeAliasType] the receiver of the call, i.e. `self`
3469
+ # @api private
3470
+ def resolve(loader)
3471
+ @loader = loader
3472
+ if @resolved_type.nil?
3473
+ # resolved to PTypeReferenceType::DEFAULT during resolve to avoid endless recursion
3474
+ @resolved_type = PTypeReferenceType::DEFAULT
3475
+ @self_recursion = true # assumed while it being found out below
3476
+ begin
3477
+ if @type_expr.is_a?(PTypeReferenceType)
3478
+ @resolved_type = @type_expr.resolve(loader)
3479
+ else
3480
+ @resolved_type = TypeParser.singleton.interpret(@type_expr, loader).normalize
3481
+ end
3482
+
3483
+ # Find out if this type is recursive. A recursive type has performance implications
3484
+ # on several methods and this knowledge is used to avoid that for non-recursive
3485
+ # types.
3486
+ guard = RecursionGuard.new
3487
+ real_type_asserter = AssertOtherTypeAcceptor.new
3488
+ accept(real_type_asserter, guard)
3489
+ unless real_type_asserter.other_type_detected?
3490
+ raise ArgumentError, "Type alias '#{name}' cannot be resolved to a real type"
3491
+ end
3492
+ @self_recursion = guard.recursive_this?(self)
3493
+ # All aliases involved must re-check status since this alias is now resolved
3494
+ if @self_recursion
3495
+ accept(AssertSelfRecursionStatusAcceptor.new, RecursionGuard.new)
3496
+ when_self_recursion_detected
3497
+ end
3498
+ rescue
3499
+ @resolved_type = nil
3500
+ raise
3501
+ end
3502
+ else
3503
+ # An alias may appoint an Object type that isn't resolved yet. The default type
3504
+ # reference is used to prevent endless recursion and should not be resolved here.
3505
+ @resolved_type.resolve(loader) unless @resolved_type.equal?(PTypeReferenceType::DEFAULT)
3506
+ end
3507
+ self
3508
+ end
3509
+
3510
+ def eql?(o)
3511
+ super && o.name == @name
3512
+ end
3513
+
3514
+ def accept(visitor, guard)
3515
+ guarded_recursion(guard, nil) do |g|
3516
+ super(visitor, g)
3517
+ @resolved_type.accept(visitor, g) unless @resolved_type.nil?
3518
+ end
3519
+ end
3520
+
3521
+ def self_recursion?
3522
+ @self_recursion
3523
+ end
3524
+
3525
+ # Returns the expanded string the form of the alias, e.g. <alias name> = <resolved type>
3526
+ #
3527
+ # @return [String] the expanded form of this alias
3528
+ # @api public
3529
+ def to_s
3530
+ TypeFormatter.singleton.alias_expanded_string(self)
3531
+ end
3532
+
3533
+ # Delegates to resolved type
3534
+ def respond_to_missing?(name, include_private)
3535
+ resolved_type.respond_to?(name, include_private)
3536
+ end
3537
+
3538
+ # Delegates to resolved type
3539
+ def method_missing(name, *arguments, &block)
3540
+ super if @resolved_type.equal?(PTypeReferenceType::DEFAULT)
3541
+ resolved_type.send(name, *arguments, &block)
3542
+ end
3543
+
3544
+ # @api private
3545
+ def really_instance?(o, guard = nil)
3546
+ if @self_recursion
3547
+ guard ||= RecursionGuard.new
3548
+ guard.with_that(o) do
3549
+ guard.with_this(self) { |state| state == RecursionGuard::SELF_RECURSION_IN_BOTH ? 0 : resolved_type.really_instance?(o, guard) }
3550
+ end
3551
+ else
3552
+ resolved_type.really_instance?(o, guard)
3553
+ end
3554
+ end
3555
+
3556
+ # @return `nil` to prevent serialization of the type_expr used when first initializing this instance
3557
+ # @api private
3558
+ def type_expr
3559
+ nil
3560
+ end
3561
+
3562
+ protected
3563
+
3564
+ def _assignable?(o, guard)
3565
+ resolved_type.assignable?(o, guard)
3566
+ end
3567
+
3568
+ def new_function
3569
+ resolved_type.new_function
3570
+ end
3571
+
3572
+ private
3573
+
3574
+ def guarded_recursion(guard, dflt)
3575
+ if @self_recursion
3576
+ guard ||= RecursionGuard.new
3577
+ guard.with_this(self) { |state| (state & RecursionGuard::SELF_RECURSION_IN_THIS) == 0 ? yield(guard) : dflt }
3578
+ else
3579
+ yield(guard)
3580
+ end
3581
+ end
3582
+
3583
+ def when_self_recursion_detected
3584
+ if @resolved_type.is_a?(PVariantType)
3585
+ # Drop variants that are not real types
3586
+ resolved_types = @resolved_type.types
3587
+ real_types = resolved_types.select do |type|
3588
+ next false if type == self
3589
+ real_type_asserter = AssertOtherTypeAcceptor.new
3590
+ type.accept(real_type_asserter, RecursionGuard.new)
3591
+ real_type_asserter.other_type_detected?
3592
+ end
3593
+ if real_types.size != resolved_types.size
3594
+ if real_types.size == 1
3595
+ @resolved_type = real_types[0]
3596
+ else
3597
+ @resolved_type = PVariantType.maybe_create(real_types)
3598
+ end
3599
+ # Drop self recursion status in case it's not self recursive anymore
3600
+ guard = RecursionGuard.new
3601
+ accept(NoopTypeAcceptor::INSTANCE, guard)
3602
+ @self_recursion = guard.recursive_this?(self)
3603
+ end
3604
+ end
3605
+ @resolved_type.check_self_recursion(self) if @self_recursion
3606
+ end
3607
+
3608
+ DEFAULT = PTypeAliasType.new('UnresolvedAlias', nil, PTypeReferenceType::DEFAULT)
3609
+ end
3610
+ end
3611
+ end
3612
+
3613
+ require_relative '../../../puppet/pops/pcore'
3614
+
3615
+ require_relative 'annotatable'
3616
+ require_relative 'p_meta_type'
3617
+ require_relative 'p_object_type'
3618
+ require_relative 'annotation'
3619
+ require_relative 'ruby_method'
3620
+ require_relative 'p_runtime_type'
3621
+ require_relative 'p_sem_ver_type'
3622
+ require_relative 'p_sem_ver_range_type'
3623
+ require_relative 'p_sensitive_type'
3624
+ require_relative 'p_type_set_type'
3625
+ require_relative 'p_timespan_type'
3626
+ require_relative 'p_timestamp_type'
3627
+ require_relative 'p_binary_type'
3628
+ require_relative 'p_init_type'
3629
+ require_relative 'p_object_type_extension'
3630
+ require_relative 'p_uri_type'
3631
+ require_relative 'type_set_reference'
3632
+ require_relative 'implementation_registry'
3633
+ require_relative 'tree_iterators'