Sha256: 444cfa4b00c1279d5d4f8135163bbf0fa4e52130a80312a837f3171706ed0600

Contents?: true

Size: 1.85 KB

Versions: 96

Compression:

Stored size: 1.85 KB

Contents

Puppet::Parser::Functions::newfunction(
  :return,
  :arity => -2,
  :doc => <<-DOC
Immediately returns the given optional value from a function, class body or user defined type body.
If a value is not given, an `undef` value is returned. This function does not return to the immediate caller.
If called from within a lambda the return will return from the function evaluating the lambda.

The signal produced to return a value bubbles up through
the call stack until reaching a function, class definition or
definition of a user defined type at which point the value given to the function will
be produced as the result of that body of code. An error is raised
if the signal to return a value reaches the end of the call stack.

**Example:** Using `return`

```puppet
function example($x) {
  # handle trivial cases first for better readability of
  # what follows
  if $x == undef or $x == [] or $x == '' {
    return false
  }
  # complex logic to determine if value is true
  true 
}
notice example([]) # would notice false
notice example(42) # would notice true
```

**Example:** Using `return` in a class

```puppet
class example($x) {
  # handle trivial cases first for better readability of
  # what follows
  if $x == undef or $x == [] or $x == '' {
    # Do some default configuration of this class
    notice 'foo'
    return()
  }
  # complex logic configuring the class if something more interesting
  # was given in $x
  notice 'bar'
}
```

When used like this:

```puppet
class { example: x => [] }
```

The code would notice `'foo'`, but not `'bar'`.

When used like this:

```puppet
class { example: x => [some_value] }
```

The code would notice `'bar'` but not `'foo'`

Note that the returned value is ignored if used in a class or user defined type.

* Also see functions `return` and `break`
* Since 4.8.0
DOC
) do |args|
  Puppet::Parser::Functions::Error.is4x('return')
end

Version data entries

96 entries across 96 versions & 3 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/parser/functions/return.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/parser/functions/return.rb
bolt-0.20.3 vendored/puppet/lib/puppet/parser/functions/return.rb
bolt-0.20.2 vendored/puppet/lib/puppet/parser/functions/return.rb
bolt-0.19.1 vendored/puppet/lib/puppet/parser/functions/return.rb
bolt-0.19.0 vendored/puppet/lib/puppet/parser/functions/return.rb
bolt-0.18.2 vendored/puppet/lib/puppet/parser/functions/return.rb
bolt-0.18.1 vendored/puppet/lib/puppet/parser/functions/return.rb
bolt-0.18.0 vendored/puppet/lib/puppet/parser/functions/return.rb
puppet-5.5.0 lib/puppet/parser/functions/return.rb
puppet-5.5.0-x86-mingw32 lib/puppet/parser/functions/return.rb
puppet-5.5.0-x64-mingw32 lib/puppet/parser/functions/return.rb
puppet-5.5.0-universal-darwin lib/puppet/parser/functions/return.rb
bolt-0.17.2 vendored/puppet/lib/puppet/parser/functions/return.rb
bolt-0.17.1 vendored/puppet/lib/puppet/parser/functions/return.rb
bolt-0.17.0 vendored/puppet/lib/puppet/parser/functions/return.rb
bolt-0.16.4 vendored/puppet/lib/puppet/parser/functions/return.rb
bolt-0.16.3 vendored/puppet/lib/puppet/parser/functions/return.rb
bolt-0.16.2 vendored/puppet/lib/puppet/parser/functions/return.rb
puppet-5.4.0 lib/puppet/parser/functions/return.rb