The group section parser
The parser for the groups:
section will define classes based on other classes' existence. For
instance, "a = ( b )" will define "a" only if "b" has already been
defined. The group-based class definition abilities of cfengine/cfperl
are very powerful.
|
As with all other cfperl parsers, this one has an input()
method. Here, input()
can only do one thing: define groups. Remember that with the Parse::RecDescent
module, all rules are also methods, which is why we regard input()
as a method.
The define_group
rule is based on the class and class_definition
rules. The class can only be a word made up of what Perl considers word (\w
)
characters, but we can change that definition if we have to. For
instance, we could have "word: /[\w-]+/" as a rule if we wanted hyphens
to also be valid class characters.
The class_definition
rule is made up of at least one class name. Thus, "groupname = ()" would not be a valid line in the groups:
section in cfperl. If we wanted to allow that, we could use
"class_definition: class(s?)" in the rule. But we don't, because it
makes no sense to have that.
The define_group
rule uses class
and class_definition
to build a group definition action. It is more liberal than cfengine's
group definition rule, which requires that the parentheses be
surrounded with space, so "groupname = (linux)" is invalid. Cfperl will
parse that line happily. If you wanted to force cfengine's behavior,
you could use the following:
|
That stricter behavior, however, is unnecessary in my opinion.
The define_group rule
uses the Parse::RecDescent
data structures to build the two parameters to the external define_group()
function. Note that the external define_group()
function is global, as denoted by the two colons before its name.
View The road to better programming: Chapter 9. The classes and default parsers Discussion
Page: 1 2 3 4 5 6 Next Page: The define_group() function