[PUP-6338] Allow arrow syntax following call to include, contain or require Created: 2016/05/21  Updated: 2017/09/08  Resolved: 2016/09/02

Status: Closed
Project: Puppet
Component/s: Language
Affects Version/s: None
Fix Version/s: PUP 4.8.0

Type: New Feature Priority: Minor
Reporter: Jesús M. Navarro Assignee: qa
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by PUP-4946 Contain, include functions should be ... Closed
Relates
Template:
Acceptance Criteria:

The functions include and contain should return an array of the resources that were included / contained.

Epic Link: 4.x TechDebt
Story Points: 2
Sprint: Language 2016-09-07
Release Notes Summary: The functions {{include}} and {{contain}} now returns an Array containing resource references to the included / contained resources that the function operated on. This allows further chaining of the result (for example using a dependency arrow).

 Description   

Given the following declaration:

class { 'someclass': } ~> Resource['some::resource']
contain 'someclass'

Allow for this shortcut:

contain('someclass') ~> Resource['some::resource']

The above should be valid for all arrow operators.

Henrik: The above was updated as the calls to the contain, include, and require functions must have the arguments in parentheses to be able to continue with an arrow.



 Comments   
Comment by Henrik Lindberg [ 2016/05/22 ]

Jesús M. Navarro
Which version of Puppet are you using? (3.x, if so, with future parser on, or 4.x)?

Do you get the error:

Illegal relationship operand, can not form a relationship with an Undef Value. A Catalog type is required.

The wanted behaviour could be achieved by lettering the contain function return an Array[Class[name]] (i.e. the input given to the function resolved to types). Thus, in the example, the returned value would be [Class\['someclass'], and the arrow operator would then work. This can only be changed for 4.x.

Alternatively, it may be possible to do this with a call to with, like this:

with('someclass') |$name| { contain($name); Class[$name] } -> Notify[x]

Or:

with(Class['someclass']) |$classes| { contain($classes); classes } -> Notify[x]

With this example, the input to with can be a single reference, or an array of references. (This is what a modified contain would do in principle).

Currently the contain (as well as the include function) always return undef.

Comment by Henrik Lindberg [ 2016/05/22 ]

If doing this also consider moving the function to 4.x API.

Comment by Jesús M. Navarro [ 2016/05/28 ]

I'm using puppet 3.x with future parser enabled, as I'm in the process to migrate to 4.x.

As a general matter, I'd consider making the reserved word 'contain' an overload of 'clas's so thigks like this are possible:

contain { 'someclass':
  param => value,
  requires => this,
  notifies => that;
} ~> something_else

or, alternatively, if thought this would be more clear:

contain class { 'someclass': ... }

Comment by Henrik Lindberg [ 2016/05/28 ]

We cannot do those changes as they would be backwards incompatible. It is a function call now, not a keyword. Making it a keyword can only be made at a major version boundary.

What we can do is to return a reference to what was contained, or included as that would allow the use of an arrow expression.

Comment by Thomas Hallgren [ 2016/08/25 ]

Merged to master at 8d366d7

Generated at Sat Feb 22 05:24:56 PST 2020 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.