bolt 0.20.0 → 0.20.2

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

Potentially problematic release.


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

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