The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
    $self -> AddRTFCmdWithEnd  ('else', 'endif',
                            { 
                            perlcode => '} else {',
                            removenode => 10,
                            mayjump     => 1,
                            stackname   => 'metacmd',
                            stackmatch  => 'if',
                            'push'      => 'if',
                            }) ;
    $self -> AddRTFCmdWithEnd  ('elsif', 'endif',
                            { 
                            perlcode => '} elsif (%&<noname>%) { ', 
                            removenode => 10,
                            mayjump     => 1,
                            stackname   => 'metacmd',
                            stackmatch  => 'if',
                            'push'      => 'if',
                            }) ;
    $self -> AddRTFCmd ('endif',
                            { 
                            perlcode => '}', 
                            removenode => 10,
                            mayjump     => 1,
                            stackname   => 'metacmd',
                            stackmatch  => 'if',
                            }) ;
    $self -> AddRTFCmdBlock  ('while', 'endwhile',
                { 
                perlcode => 'while (%&<noname>%) { ', 
                removenode => 10,
                mayjump     => 1,
                },
                { 
                perlcode => '};', 
                removenode => 10,
                mayjump     => 1,
                }) ;
    $self -> AddRTFCmdBlock  ('foreach', 'endforeach',
                { 
                perlcode => 'foreach %&<noname>% { ', 
                removenode => 10,
                mayjump     => 1,
                },
                { 
                perlcode => '};', 
                removenode => 10,
                mayjump     => 1,
                }) ;
    $self -> AddRTFCmdBlock  ('do', 'until',
                { 
                perlcode => 'do { ', 
                removenode => 10,
                mayjump     => 1,
                },
                { 
                perlcode => '} until (%&<noname>%) ; ',
                removenode => 10,
                mayjump     => 1,
                }) ;
    $self -> AddRTFCmd ('var',
                { 
                compiletimeperlcode => 'use strict ; use vars qw{%%CLEANUP %&<noname>%} ; map { $CLEANUP{substr($_,1)} = 1 } qw{%&<noname>%} ;', 
                perlcode => 'use strict ;', 
                removenode => 3,
                }) ;
    $self -> AddRTFCmd ('hidden',
                { 
                perlcode => '_ep_hid(%$n%,%&\'<noname>%);', 
                removenode => 8,
                }) ;
    $self -> AddRTFCmd ('syntax',
                { 
                compiletimeperlcode => '$_[0] -> Syntax (HTML::Embperl::Syntax::GetSyntax(%&\'<noname>%, $_[0] -> SyntaxName));', 
                removenode => 3,
                },
                { 
                parsetimeperlcode => '$_[0] -> Syntax (HTML::Embperl::Syntax::GetSyntax(\'%%\', $_[0] -> SyntaxName)) ;', 
                },
                ) ;
    $self -> AddRTFCmdBlock ('sub', 'endsub',
                { 
                perlcode => 'sub _ep_sub_%&<noname>% { ', 
                removenode => 10,
                mayjump     => 1,
                stackname2   => 'subname',
                push2        => '%&<noname>%',
                switchcodetype => 2,
                },
                { 
                perlcode => '};  sub %^subname% { my @_ep_save ; HTML::Embperl::Cmd::SubStart(\\$_ep_DomTree,%$q%,\\@_ep_save); my $_ep_ret = _ep_sub_%^subname% (@_); HTML::Embperl::Cmd::SubEnd(\\@_ep_save); return $_ep_ret } ; $_[0] -> ExportHash ->



 {%^"subname%} = \&%^subname% ; ', 
                removenode => 10,
                mayjump     => 1,
                pop2        => 'subname',
                switchcodetype => 1,
                }) ;
                            my $x = $_[0] -> Code ;
                            my ($op, $cmp, $a, $b) = XML::Embperl::DOM::Node::iChildsText (%$q%,%$x%,1) =~ /\:([=<>])+\s*\"(.*?)\"(?:\s*\"(.*?)\"\s*\"(.*?)\")?/ ;
                            
                            if ($op eq '=') { $op = 'eq' }
                            elsif ($op eq '<') { $op = 'lt' }
                            elsif ($op eq '>') { $op = 'gt' }
                            elsif ($op eq '>=') { $op = 'ge' }
                            elsif ($op eq '<=') { $op = 'le' }

                            print "\n#" . __LINE__ . " op = $op cmp = $cmp a = $a b = $b code=$_ep_rtf_code tmp=$_ep_rtf_tmp 0=$param[0]{'adressen_anrede'} ndx=$_ep_rtf_ndx eval=qq[$_ep_rtf_code]\n" ;
                            $_ep_rtf_code =~ s/\$a/q\[$a\]/g ;
                            $_ep_rtf_code =~ s/\$b/q\[$b\]/g ;
                            $_ep_rtf_code =~ s/\$cmp/q\[$cmp\]/g ;
                            $_ep_rtf_code =~ s/\$op/$op/g ;
                            $_ep_rtf_code =~ s/\$x/$x/g ;
                            print "result=$_ep_rtf_code\n" ;
                            
                            warn "RTF IF syntax error. Missing operator" if (!$op) ;

NAME

HTML::Embperl::Syntax::RTF

SYNOPSIS

DESCRIPTION

Class derived from HTML::Embperl::Syntax to define the syntax for RTF files. RTF files can be read and written by various word processing programms. This allows you to create dynamic wordprocessing documents or let process serial letters thru Embperl.

Currently Embperl regocnices the fields DOCVARIABLE, MERGEFIELD and NEXT. Variablenames are resolved as hash keys to $param[0] e.g. foo.bar referes to $param[0]{foo}{bar}, the @param Array can by set via the param parameter of the Execute function. NEXT moves to the next element of the @param array. If the end of the document is reached, Embperl repeats the document until all element of @param are processed. This can for example be use to tie a database table to @param and generate a serial letter.

NOTE: Extenting this syntax to support full Embperl support (like embedding Perl into RTF file is planned, but not implemented yet)

Example for generating a serial letter from a database

  use DBIx::Recordset ;
  use HTML::Embperl ;

  *set = DBIx::Recordset -> Search({'!DataSource' => $db, '!Table' => 'address', '!WriteMode' => 0}) ;

  die DBIx::Recordset -> LastError if (DBIx::Recordset -> LastError) ;

  HTML::Embperl::Execute ({'inputfile' => 'address.rtf', param => \@set, syntax => 'RTF'}) ;


  # if your database table contains fields 'name' and 'street' you can now simply insert a
  # fields call 'name' and 'street' in your RTF file and Embperl will repeat the document
  # until all records are outputed

Methods

HTML::Embperl::Syntax::RTF defines the following methods:

HTML::Embperl::Syntax::RTF -> new / $self -> new

Create a new syntax class. This method should only be called inside a constructor of a derived class.

AddRTFCmd ($cmdname, $procinfo)

Add a new RTF command with name $cmdname and use processor info from $procinfo. See HTML::Embperl::Syntax for a definition of procinfo.

AddRTFCmdWithEnd ($cmdname, $endname, $procinfo)

Add a new RTF command with name $cmdname and use processor info from $procinfo. Addtionaly specify that a matching $endname RTF command must be found to end the block, that is started by this RTF command. See HTML::Embperl::Syntax for a definition of procinfo.

AddRTFCmdBlock ($cmdname, $endname, $procinfostart, $procinfoend)

Add a new RTF command with name $cmdname and and a second RTF command $endname which ends the block that is started by $cmdname. Use processor info from $procinfo. See HTML::Embperl::Syntax for a definition of procinfo.

Author

G. Richter (richter@dev.ecos.de)

See Also

HTML::Embperl::Syntax

3 POD Errors

The following errors were encountered while parsing the POD:

Around line 276:

=pod directives shouldn't be over one line long! Ignoring all 9 lines of content

Around line 539:

=pod directives shouldn't be over one line long! Ignoring all 15 lines of content

Around line 740:

=pod directives shouldn't be over one line long! Ignoring all 2 lines of content