Developer Forums | About Us | Site Map
Search  
HOME > TUTORIALS > SERVER SIDE CODING > PERL TUTORIALS > THE ROAD TO BETTER PROGRAMMING: CHAPTER 9. THE CLASSES AND DEFAULT PARSERS


Sponsors





Useful Lists

Web Host
site hosted by netplex

Online Manuals

The road to better programming: Chapter 9. The classes and default parsers
By Teodor Zlatanov - 2004-03-29 Page:  1 2 3 4 5 6

The default parser

Any cfrun atoms handed to the dispatch() function have a section attribute. The dispatch() function will look for an appropriate parser for each atom, based on the section. For instance, there's a specific parser for the users: section that understands commands like add_user.

In the case that there is no explicitly defined parser to handle a cfrun atom, the default parser is invoked. The default parser does not do anything at all -- it is only a placeholder. Cfperl was explicitly designed so that it would supplement cfengine, so cfengine sections such as editfiles: and files: should not be handled by cfperl at all. Thus, the default parser is invoked by dispatch():

Listing 3. The default parser, sort of Zen but more so
       
$parsers{DEFAULT_SECTION()} = new Parse::RecDescent(q{ input: });
Listing 4. dispatch() invokes the appropriate parser, or the default parser otherwise
        
 if (exists $parsers->{$section})
 {
  out (3, "dispatch: Invoking specific parser for section $section");
  $retval = $parsers->{$section}->input($line);
 }
 else
 {
  die "No default parser found, quitting" unless exists $parsers->{DEFAULT_SECTION()};
  out(3, "dispatch: Given section $section does not have a parser,
                             using default for command [$line]");
  $retval = $parsers->{DEFAULT_SECTION()}->input($line);  
 }

As an amusing side note, the DEFAULT_SECTION constant has to be invoked as a function, or Perl assumes you mean the string "DEFAULT_SECTION" rather than the constant named so.



View The road to better programming: Chapter 9. The classes and default parsers Discussion

Page:  1 2 3 4 5 6 Next Page: The group section parser

First published by IBM developerWorks


Copyright 2004-2024 GrindingGears.com. All rights reserved.
Article copyright and all rights retained by the author.