Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add private() function #270

Merged
merged 1 commit into from Jun 18, 2014
Merged

Add private() function #270

merged 1 commit into from Jun 18, 2014

Conversation

raphink
Copy link
Contributor

@raphink raphink commented Jun 11, 2014

private

This function sets the current class or definition as private.
Calling the class or definition from outside the current module will fail.

Examples:

private()

called in class foo::bar will output the following message if class is called
from outside module foo:

Class foo::bar is private

You can specify the error message you want to use as a parameter:

private("You're not supposed to do that!")
  • Type: statement

@igalic
Copy link
Contributor

igalic commented Jun 11, 2014

nice!

@jhoblitt
Copy link

👍

apenney pushed a commit that referenced this pull request Jun 18, 2014
@apenney apenney merged commit f049509 into puppetlabs:master Jun 18, 2014
@hlindberg
Copy link
Contributor

hm... this was added, but "private" is a reserved keyword in future parser in 3.7, and is an error in Puppet 4.0.0 until support for this has been added to the language for classes, defines, and variables (planned for 4.x). This function can then not be called because its name is reserved.

@hlindberg
Copy link
Contributor

You can achieve this without this function:

class foo::bar {
if $module_name != $caller_module_name {
fail 'foo::bar is private'
}
}

@raphink
Copy link
Contributor Author

raphink commented Jul 13, 2014

Hi @hlindberg,

It's good to know that the future parser will have a private concept. The goal of this function was precisely to make it easier to use the $module_name != $caller_module_name trick, without copying/pasting it into every function. Do you suggest this function be renamed? Does it cover the same scope as the concept in the future parser?

@hlindberg
Copy link
Contributor

The future language concept "private" covers the functionality of this function. My suggestion is to not include the function in standard lib at all.

@raphink
Copy link
Contributor Author

raphink commented Jul 13, 2014

How about keeping it and specifying that it will be deprecated in Puppet 4?

@hlindberg
Copy link
Contributor

So people have to change their code first to use it, and then change it? At least rename it.

@raphink
Copy link
Contributor Author

raphink commented Jul 21, 2014

What is the syntax of the private statement in the future parser?

@zaphod42
Copy link
Contributor

@raphink it isn't in yet, at this point we've just reserved the word, but it'll likely be something like private class foo {} and private define bar() {}. I think @hlindberg is also looking at allowing it for variables: class foo(private $data) and private $var = 3.

@raphink
Copy link
Contributor Author

raphink commented Jul 21, 2014

OK. What do you suggest for a renaming?

@igalic
Copy link
Contributor

igalic commented Jul 22, 2014

@raphink how about privatize()

I'd also suggest checking for the puppet version, and issue a warning for >= 4.

@hlindberg
Copy link
Contributor

Some suggestions, private_class(), make_class_private(), make_private(), assert_private(), assert_module_private(), module_private(), of those I like assert_private() and module_private() best.

fpletz added a commit to mayflower/puppetlabs-stdlib that referenced this pull request Dec 19, 2014
As mentioned in puppetlabs#270, private is a reserved keyword in the future parser
which is to be released with Puppet 4. As it stands, this function is
not useable with the future parser so it needs to renamed.

This is a breaking change.
cyberious pushed a commit to cyberious/puppetlabs-stdlib that referenced this pull request Mar 5, 2015
As mentioned in puppetlabs#270, private is a reserved keyword in the future parser
which is to be released with Puppet 4. As it stands, this function is
not useable with the future parser so it needs to renamed.

This is a breaking change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants