Hub::Parse::Parser - Template parser


hub-standard documentation  | view source Contained in the hub-standard distribution.

Index


NAME

Top

Hub::Parse::Parser - Template parser

SYNOPSIS

Top



  use Hub qw(:standard);

  my $text = 'Hello [#/user], it is [#/date/month]';
  my $values = {
    user => ryan,
    date => {
      year => 2007,
      day => 10,
      month => March
    },
  };

  my $parser = mkinst('Parser', -tempate => \$text);
  print $parser->parse($values);

Will produce the result:

  Hello ryan, it is March







DESCRIPTION

Top

Intention

PUBLIC METHODS

Top

new

Construct a new instance


 Usage: new -template => \$text|$text, [options]




options:



  -var_begin => $string     # Identifies beginning of a variable (no regexp)
  -var_end => $string       # Identifies the end of a variable (no regexp)




refresh

Return instance to initial state

populate

 Usage: populate \HASH+

Populate our template with provided variable definitions.

PARAMETERS:



  \HASH               Variable name to definition map

Example: (matches)

    my $parser = mkinst( 'Parser', -template => 'Hello [#who]' );
              ${$parser->populate( { who => 'World' } )};




    Hello World




get_evaluator

Hook into evaluator loop by overriding this method.





 Usage: get_evaluator $directive




Returns a subroutine (CODE) reference.

This method is used by this base class to get the evaluator when a particular directive is incountered. For instance, if the template contains:



  Hello  Usage: get_evaluator('if') will be called.  See L<Hub::Parse::StandardParser> for
an example of how this class is extended.







get_value

Search the provided hashes for a value


 Usage: get_value $name, $hash, [$hash..]




resolve

Get a string representation of a value

get_hint

Show where we are in parsing the text


 Usage: get_hint $position, \$text




remove_variables

Remove variable statements from the text


 Usage: remove_variables \$text
This will *not* remove parents of nested variables.







INTERNAL METHODS

Top

_populate

 Usage: _populate [OPTIONS], \HASH+

Internal worker function.

Recursive.

PARAMETERS:



  \HASH               Variable name to definition map




OPTIONS:



  -text   \SCALAR     Template text to populate




_evaluate

Evaluate the expression


 Usage: _evaluate \@value_data, @parameters




Where @parameters are:



  -fields     => \@fields
  -outer_str  => $outer_str
  -pos        => $position
  -text       => \$text




_to_string

_value_of - The default string value of an object

_get_block

Find the block for a given directive


 Usage: _get_block $start_position, \$text, $type




_find_point

Find the next occurance of a single argument directive


 Usage: _find_point \$text, $begin_point, $directive_name, $argument_value




If you are looking for: then you would use this method as:



  _find_point($text, $pos, 'parser', 'on');




_find_end_point

Find the '' marker


 Usage: _find_end_point - \$text, $begin_point, $type




Returns the beg

_padding

Get number of preceeding and trailing whitespace characters


 Usage: _padding \$text, $pos, $width




  \$text    template
  $pos      current position in $$text
  $width    width of the current match




Returns an array of widths: ($w1, $w2)



  $w1 = Number of preceeding whitespace characters
  $w2 = Number of trailing whitespace characters




Returns an empty array if non-whitespace characters are found in the preceeding or trailing regions.

We will look up to 80 characters in front of the current position (ie, 80 character indent maximum.)

_split_if_else

AUTHOR

Top

Ryan Gies (ryangies@livesite.net)

COPYRIGHT

Top

UPDATED

Top

08/02/2007


hub-standard documentation  | view source Contained in the hub-standard distribution.