Details
-
Improvement
-
Status: Closed
-
Normal
-
Resolution: Fixed
-
None
-
None
-
None
-
2
-
Language 2016-02-24, Language 2016-03-09, Language 2016-03-23, Language 2016-04-06, Language 2016-04-20
-
New Feature
-
In preparation for future features in puppet, the abstract type {{Object}} has bee added to the type system.
Description
In the Puppet Core Type Model (PCore) that will be used to describe all serialization using the Puppet Type System it is essential to have an Object[T] type that matches instances of user defined type T. We also need the run time abstract Object from which the concrete instances of user defined data types are derived.
This work is also required to enable the full user defined type definition using the syntax:
type TypeName inherits SuperTypeName { |
# attribute definitions |
}
|
Which will be added in a separate ticket.
Update
We have decided (after many rounds of proposals) to use the following syntax for the Object type:
type T = Object[{ |
parent => < parent-type >, |
attributes => { <attributes-hash> }.
|
functions => { <functions-hash> },
|
equality => [ <equality-array> ],
|
equality_includes_type => Boolean,
|
}]
|
Those are the basic features that the Object will have. Additional features can be expected later (separate tickets) to handle invariants.
ATTRIBUTES
The attributes feature is a map from name to Type for attributes that do not require a default value, or other special settings. For attributes where more than a type is required a hash is used.
attributes => {
|
name1 => Type,
|
name2 => {
|
type => Type, # the type of the value |
kind => Enum[given, derived, given_or_derived, constant],
|
value => 'default value literal', |
final => Boolean,
|
override => Boolean,
|
}
|
}
|
The above example shows one short form, and one long form attribute. Expect there to be additional properties that can be set on an attribute.
FUNCTIONS
The function feature has fewer properties. Basically this is a name to type map.
functions {
|
name1 => Callable[ ... ],
|
name2 => Callable[ ... ],
|
}
|
If a long form is needed it is defined the same way as for attributes.
EQUALITY
Equality can be specified by giving a list of attributes that must be equal for two instances of the object to be considered equal. If not given. Equality s base on all regular fields (i.e. excluding derived/computed and constant value attributes).
equality => | 'a', 'b', 'c' ] |
IMPLEMENTATION
Object type's not bound to an implementation can be used (a dynamic/generic implementation), but the operations are then not available. For operations to be available there must be a binding between an implementation type, and the Object type. Such a binding can be achieved in different ways.
- via a special type alias that binds the object type to a Runtime type
- via syntax to be added in a separate ticket that makes it possible to implement an object type in puppet.
type T = Object[{ ... } ] # defines the Object type (the interface) |
type T = Runtime['ruby'', SomeModule::Somewhere::MyImplOfT ] |
The example shows a definition of the object and a binding to a runtime implementation. This will follow in subsequent tickets.
ACCEPTANCE CRITERIA
There is not that much that can be directly used from Puppet when this ticket is finished. it will be useful when support for the 'new' function has been added, and that the type algebra is implemented (matching on type etc).
Attachments
Issue Links
- blocks
-
PUP-5906 Native Puppet Parser - make puppet use native parse and validate
-
- Closed
-
-
PUP-5946 Puppet Resource Types
-
- Closed
-
-
PUP-5907 Define the PCore Serialization API and Features
-
- Resolved
-
-
PUP-6137 Name anonymous Object when bound to a type name.
-
- Closed
-
- is blocked by
-
PUP-5927 Add default value to Default type
-
- Closed
-