You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The language collection described several types only in passing, or not at
all. Close the smaller gaps left over from the Puppet 5.5 import:
* Add ScalarData, RichData, Iterable, and Iterator to the abstract data
types page, alongside the parent types they belong with.
* Add Runtime, Object, and TypeSet under unusual types. TypeSet is the
spelling OpenVox renders, though the parser accepts any capitalization.
* Index Sensitive under core data types, and NotUndef, Init, and the seven
types above under abstract data types, in lang_data_type.md. All were
either documented but unlisted, or absent entirely.
* Document the Boolean[true] and Boolean[false] parameters. The page said
Boolean "accepts no parameters", which is incorrect.
Also correct the Scalar section, which claimed Scalar is equivalent to
Variant[Integer, Float, String, Boolean, Regexp]. In OpenVox 8 Scalar also
matches SemVer, SemVerRange, Timestamp, and Timespan, none of which that
Variant matches. The equivalence claim is removed and the list of matched
types extended. The SemVer page already contradicted this.
Every example is verified against OpenVox 8.28.1 with puppet apply.
Part of #407
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Michael Harp <mike@mikeharp.com>
As described in [the Data Type Syntax][types] page, each of Puppet's main [data types][] has a corresponding value that _represents_ that data type, which can be used to match values of that type in several contexts. (For example, `String` or `Array`.)
17
23
@@ -257,12 +263,27 @@ The `Scalar` data type matches _all_ values of the following concrete data types
257
263
*[Strings][]
258
264
*[Booleans][]
259
265
*[Regular expressions][]
266
+
*[`SemVer` and `SemVerRange`][semver]
267
+
*[`Timestamp` and `Timespan`][time]
260
268
261
269
Note that it doesn't match `undef`, `default`, resource references, arrays, or hashes.
262
270
263
271
It takes no parameters.
264
272
265
-
`Scalar` is equivalent to `Variant[Integer, Float, String, Boolean, Regexp]`.
273
+
### `ScalarData`
274
+
275
+
The `ScalarData` data type matches the subset of `Scalar` that can be represented directly in JSON:
276
+
277
+
*[Numbers][] (both integers and floats)
278
+
*[Strings][]
279
+
*[Booleans][]
280
+
281
+
It doesn't match regular expressions, `SemVer`, `SemVerRange`, `Timestamp`, or `Timespan`, all of which
282
+
`Scalar` does match. Like `Scalar`, it doesn't match `undef` or `default`.
283
+
284
+
It takes no parameters.
285
+
286
+
`ScalarData` is to `Scalar` what `Data` is to `RichData`: the JSON-compatible subset.
266
287
267
288
### `Data`
268
289
@@ -278,6 +299,26 @@ It takes no parameters.
278
299
279
300
`Data` is especially useful because it represents the subset of types that can be directly represented in almost all serialization formats (e.g. JSON).
280
301
302
+
### `RichData`
303
+
304
+
The `RichData` data type matches any value that would match `Data`, and also matches the types that have no
305
+
direct JSON equivalent:
306
+
307
+
*[`Binary`][binary]
308
+
*[`Timestamp` and `Timespan`][time]
309
+
*[`SemVer` and `SemVerRange`][semver]
310
+
*[`Error`][error]
311
+
*[`Sensitive`][sensitive]
312
+
* Data types themselves, such as `Integer`
313
+
*`default`
314
+
*[Arrays][] and [hashes][] containing any of the above
315
+
316
+
It takes no parameters.
317
+
318
+
`RichData` is what a parameter or function should accept when it needs to handle any ordinary Puppet value.
319
+
Use `Data` instead when the value has to survive being serialized to JSON, and note that this is the
320
+
distinction that makes `Error('boom') =~ Data` false while `Error('boom') =~ RichData` is true.
321
+
281
322
### `Collection`
282
323
283
324
The `Collection` type matches _any_ array or hash, regardless of what kinds of values (and/or keys) it contains.
@@ -286,6 +327,40 @@ Note that this means it only partially overlaps with `Data` --- there are values
286
327
287
328
`Collection` is equivalent to `Variant[Array[Any], Hash[Any, Any]]`.
288
329
330
+
### `Iterable`
331
+
332
+
The `Iterable` data type matches any value that an iterative function such as `each` or `map` can walk over.
333
+
That includes arrays, hashes, strings, integers, and the `Iterator` values described below:
334
+
335
+
```puppet
336
+
notice([1, 2] =~ Iterable) # true
337
+
notice({'a' => 1} =~ Iterable) # true
338
+
notice('abc' =~ Iterable) # true
339
+
notice(5 =~ Iterable) # true
340
+
notice(undef =~ Iterable) # false
341
+
```
342
+
343
+
An optional parameter constrains what the value iterates over, so `Iterable[Integer]` matches only things
344
+
that yield integers:
345
+
346
+
```puppet
347
+
notice(5 =~ Iterable[Integer]) # true
348
+
```
349
+
350
+
### `Iterator`
351
+
352
+
The `Iterator` data type matches the lazy sequences produced by the chained forms of some iterative
353
+
functions, such as `reverse_each` and `step` called without a block. Every `Iterator` is also `Iterable`,
354
+
but ordinary arrays and hashes are not `Iterator`:
355
+
356
+
```puppet
357
+
notice([1, 2].reverse_each =~ Iterator) # true
358
+
notice([1, 2] =~ Iterator) # false
359
+
```
360
+
361
+
Like `Iterable`, it accepts an optional parameter for the type it yields. You rarely write `Iterator`
362
+
yourself; it matters mainly when a function returns one and you want to constrain what it produces.
363
+
289
364
### `Catalogentry`
290
365
291
366
The `Catalogentry` data type is the parent type of `Resource` and `Class`. This means that, like those types, the Puppet language contains no values that it will ever match. However, the type `Type[Catalogentry]` will match any class reference or resource reference.
@@ -358,3 +433,43 @@ function example(Variant[Integer, Init[Integer]] $x) {
358
433
$int_value = Integer($x) # Safe conversion
359
434
}
360
435
```
436
+
437
+
See [typecasting][] for the conversions `Init` tests against.
438
+
439
+
### `Runtime`
440
+
441
+
The `Runtime` data type matches values that belong to the implementation language underneath Puppet rather
442
+
than to the Puppet language itself. It takes the runtime name and the type name within it:
443
+
444
+
```puppet
445
+
Runtime['ruby', 'Symbol']
446
+
```
447
+
448
+
You cannot create such a value in a manifest. The type exists so that Ruby functions and types can describe
449
+
arguments that are Ruby objects with no Puppet equivalent, and so those arguments can be type-checked.
450
+
451
+
### `Object`
452
+
453
+
The `Object` data type is the parent of types created with the Pcore object model, which is how modules
454
+
define types that have named attributes and their own methods. An object type is declared by passing a hash
0 commit comments