Skip to content

Commit 49b71ca

Browse files
miharpclaude
andcommitted
Document the remaining undocumented data types
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>
1 parent ec6d406 commit 49b71ca

3 files changed

Lines changed: 155 additions & 2 deletions

File tree

docs/_openvox_8x/lang_data_abstract.md

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ title: "Language: Data types: Abstract data types"
1212
[hashes]: ./lang_data_hash.html
1313
[hash_missing_key_access]: ./lang_data_hash.html#accessing-values
1414
[numbers]: ./lang_data_number.html
15+
[semver]: ./lang_data_semver.html
16+
[time]: ./lang_data_time.html
17+
[binary]: ./lang_data_binary.html
18+
[error]: ./lang_data_error.html
19+
[sensitive]: ./lang_data_sensitive.html
20+
[typecasting]: ./lang_typecasting.html
1521

1622
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`.)
1723

@@ -257,12 +263,27 @@ The `Scalar` data type matches _all_ values of the following concrete data types
257263
* [Strings][]
258264
* [Booleans][]
259265
* [Regular expressions][]
266+
* [`SemVer` and `SemVerRange`][semver]
267+
* [`Timestamp` and `Timespan`][time]
260268

261269
Note that it doesn't match `undef`, `default`, resource references, arrays, or hashes.
262270

263271
It takes no parameters.
264272

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.
266287

267288
### `Data`
268289

@@ -278,6 +299,26 @@ It takes no parameters.
278299

279300
`Data` is especially useful because it represents the subset of types that can be directly represented in almost all serialization formats (e.g. JSON).
280301

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+
281322
### `Collection`
282323

283324
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
286327

287328
`Collection` is equivalent to `Variant[Array[Any], Hash[Any, Any]]`.
288329

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+
289364
### `Catalogentry`
290365

291366
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) {
358433
$int_value = Integer($x) # Safe conversion
359434
}
360435
```
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
455+
that names it and lists its attributes:
456+
457+
```puppet
458+
$greeter = Object[{name => 'Greeter', attributes => {greeting => String}}]
459+
$g = $greeter.new('hello')
460+
461+
notice($g.greeting) # hello
462+
notice($g =~ $greeter) # true
463+
```
464+
465+
In practice you rarely write this form inline. Modules declare object types in their `types` directory,
466+
where each file contributes to the module's type set.
467+
468+
### `TypeSet`
469+
470+
The `TypeSet` data type groups several object types together under one name and version, so a module can
471+
publish a related family of types. Type sets are declared in a module's `types` directory rather than
472+
written inline in a manifest, and they record a name, a version, and the types they contain.
473+
474+
The type parser accepts any capitalization, so `Typeset` also works, but `TypeSet` is the spelling OpenVox
475+
itself uses when it renders the type.

docs/_openvox_8x/lang_data_boolean.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,26 @@ If you want to convert other values to booleans with more permissive rules (`0`
3333

3434
The [data type][] of boolean values is `Boolean`.
3535

36-
It matches only the values `true` or `false`, and accepts no parameters.
36+
On its own it matches only the values `true` or `false`.
3737

38+
### Parameters
39+
40+
`Boolean` takes an optional parameter that narrows it to one of the two values:
41+
42+
```puppet
43+
notice(true =~ Boolean[true]) # true
44+
notice(false =~ Boolean[true]) # false
45+
notice(false =~ Boolean[false]) # true
46+
```
47+
48+
This is useful when a parameter must be one specific value rather than either, such as a flag that may only
49+
ever be switched on:
50+
51+
```puppet
52+
class example (
53+
Boolean[true] $must_be_enabled = true,
54+
) { }
55+
```
3856

3957
### Related data types
4058

docs/_openvox_8x/lang_data_type.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ title: "Language: Data types: Data type syntax"
3636
[catalogentry]: ./lang_data_abstract.html#catalogentry
3737
[any]: ./lang_data_abstract.html#any
3838
[callable]: ./lang_data_abstract.html#callable
39+
[sensitive]: ./lang_data_sensitive.html
40+
[notundef]: ./lang_data_abstract.html#notundef
41+
[init]: ./lang_data_abstract.html#init
42+
[scalardata]: ./lang_data_abstract.html#scalardata
43+
[richdata]: ./lang_data_abstract.html#richdata
44+
[iterable]: ./lang_data_abstract.html#iterable
45+
[iterator]: ./lang_data_abstract.html#iterator
46+
[runtime]: ./lang_data_abstract.html#runtime
47+
[object]: ./lang_data_abstract.html#object
48+
[typeset]: ./lang_data_abstract.html#typeset
3949

4050
Each value in the Puppet language has a data type, like "string." There is also a set of values _whose data type is "data type."_
4151

@@ -158,6 +168,7 @@ These are the "real" data types, which make up the most common values you'll int
158168
* [`Timestamp` and `Timespan`][time]
159169
* [`SemVer` and `SemVerRange`][semver]
160170
* [`Error`][error]
171+
* [`Sensitive`][sensitive]
161172
* [`Undef`][undef]
162173
* [`Default`][default]
163174

@@ -173,18 +184,27 @@ Resource references and class references are implemented as data types, although
173184
Abstract data types let you do more sophisticated or permissive type checking.
174185

175186
* [`Scalar`][Scalar]
187+
* [`ScalarData`][ScalarData]
176188
* [`Collection`][Collection]
177189
* [`Variant`][Variant]
178190
* [`Data`][Data]
191+
* [`RichData`][RichData]
179192
* [`Pattern`][Pattern]
180193
* [`Enum`][Enum]
181194
* [`Tuple`][Tuple]
182195
* [`Struct`][Struct]
183196
* [`Optional`][Optional]
197+
* [`NotUndef`][NotUndef]
184198
* [`Catalogentry`][Catalogentry]
185199
* [`Type`][inpage_type]
186200
* [`Any`][Any]
187201
* [`Callable`][Callable]
202+
* [`Init`][Init]
203+
* [`Iterable`][Iterable]
204+
* [`Iterator`][Iterator]
205+
* [`Runtime`][Runtime]
206+
* [`Object`][Object]
207+
* [`TypeSet`][TypeSet]
188208

189209
## The `Type` data type
190210

0 commit comments

Comments
 (0)