You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Kinetic Slam <ki...@gmail.com> on 2006/10/03 18:00:48 UTC

Embperl::Object::Execute help within PERL scripts for templating.

Hello,

I'm running Embperl 2.2.0, mod_perl 2.0.2 under Apache 2.2.3.  I have
successfully setup Embperl 2 for templating my website (templates display
properly for .html files).  What I am trying to do now is convert some PERL
scripts I have to make use of the Embperl templating features with only
minor modifications ($r->print to Embperl::Object::Execute...).

Here is a test script before conversion:

my $r = shift;
subTest(\$r);
sub subTest {
        my $r = shift;
        my ($content,$cgienvvar);
        $content = "<HTML><BODY>";
        $content .= "<H1> Test </H1>\n";
        $content .= "</BODY></HTML>";
        $$r->content_type("text/html");
        $$r->print("$content");
        return Apache2::Const::OK;
} # end subTest

Result: Displays as expected.

Here is the same script after I converted to work with Embperl:

use Embperl;
use Embperl::Object;
my $r = shift;
subTest(\$r);
sub subTest {
        my $r = shift;
        my ($content,$cgienvvar);
        $content = "<H1> Test </H1>\n";
        Embperl::Object::Execute({
                input => \$content,
                mtime => 1,
                req_rec => $$r
        });
} # end subTest

Result: Displays the HTML properly but the Embperl template is not used.

And here are the Apache conf pieces relevant for Embperl:

    AddType text/html .epl
    EMBPERL_APPNAME testapp
    EMBPERL_DEBUG 0x7fffffff
    EMBPERL_ESCMODE 0
    EMBPERL_OPTIONS 16
    EMBPERL_OBJECT_BASE _base.epl
    PerlModule Embperl

    <FilesMatch "\.htm.?|\.epl$">
        SetHandler perl-script
        PerlHandler Embperl::Object
    </FilesMatch>

        ScriptAlias /cgi-bin/ /data/apache/htdocs/testsite/cgi-bin/
        <Directory "/data/apache/htdocs/testsite/cgi-bin/">
        <FilesMatch "\.pl$">
                EMBPERL_APPNAME test
                SetHandler perl-script
                PerlResponseHandler ModPerl::Registry
        </FilesMatch>
                SSLRequireSSL
                SSLOptions +StdEnvVars
                AllowOverride None
                Options None +ExecCGI
                Order allow,deny
                Allow from all
        </Directory>

When *.html files are processed I can see Embperl (embperl.log) going
through the _base.epl file then to each of the other parts of the template.
When the *.pl script is run the embperl.log file shows the new APPNAME
'test" and only _base.epl being found and imported, I don't see references
to any other piece of the template and none of the template is sent to the
browser.  I've attempted many variations on Embperl::Object::Execute
including specifying appname, object_base/object_addpath, and inputfile
values.

Am I way off on how I am trying to use Embperl::Object::Execute in this
way?  For the purposes of this exercise I want to avoid a complete
conversion to Embedded perl within .html files.

Thanks for the help,

Chris

Re: Embperl::Object::Execute help within PERL scripts for templating.

Posted by Kinetic Slam <ki...@gmail.com>.
> I'm running Embperl 2.2.0, mod_perl 2.0.2 under Apache 2.2.3.  I have
> successfully setup Embperl 2 for templating my website (templates display
> properly for .html files).  What I am trying to do now is convert some
PERL
> scripts I have to make use of the Embperl templating features with only
> minor modifications ($r->print to Embperl::Object::Execute...).

A bit of additional information on my end goal for this effort is to get
Embperl templating to work with my existing AuthCookie handler (putting any
discussion of using Embperl cookie handlers aside for the moment).  Pounding
away at this I, have stumbled across something that seems to be working for
me right now.  I have an .html file being handled by Embperl which just
contains the line:

[- Execute ({subreq => '/cgi-bin/mytestloginscreen.pl'}) -]

I then have changed my AuthCookie handler setup in Apache conf from:

PerlSetVar authLoginScript /cgi-bin/mytestloginscreen.pl

TO

PerlSetVar authLoginScript /mytestloginscreen.html

My solution seems like a bit of a duct tape and glue approach to me.  Is
there a better, more efficient way to use an established Embperl template
from within a ModPerl::Registry perl script under Apache2?

Thanks,

Chris

RE: Embperl::Object::Execute help within PERL scripts for templating.

Posted by Gerald Richter <ri...@ecos.de>.
Hello,

If I understand right, you what to have Embperl::Object generate the base
template and include your old pages, which are written in pure Perl, into
it, like other Embperl pages, right?

In this case you should go the other way round. Instead of using
Apache::Registry you should call your Perl script in your base.epl, with the
Paramter syntax => 'Perl'. 

You could also overwrite the method get_receipe of the application object,
to automaticly set the syntax value (see eg/web/epwepapp.pl for an example)

Gerald


> 
> I'm running Embperl 2.2.0, mod_perl 2.0.2 under Apache 2.2.3. 
>  I have successfully setup Embperl 2 for templating my 
> website (templates display properly for .html files).  What I 
> am trying to do now is convert some PERL scripts I have to 
> make use of the Embperl templating features with only minor 
> modifications ($r->print to Embperl::Object::Execute...).
> 
> Here is a test script before conversion:
> 
> my $r = shift;
> subTest(\$r);
> sub subTest {
>         my $r = shift;
>         my ($content,$cgienvvar);
>         $content = "<HTML><BODY>";
>         $content .= "<H1> Test </H1>\n";
>         $content .= "</BODY></HTML>";
>         $$r->content_type("text/html");
>         $$r->print("$content");
>         return Apache2::Const::OK;
> } # end subTest
> 
> Result: Displays as expected.
> 
> Here is the same script after I converted to work with Embperl:
> 
> use Embperl;
> use Embperl::Object;
> my $r = shift;
> subTest(\$r);
> sub subTest {
>         my $r = shift;
>         my ($content,$cgienvvar);
>         $content = "<H1> Test </H1>\n";
>         Embperl::Object::Execute({
>                 input => \$content,
>                 mtime => 1,
>                 req_rec => $$r
>         });
> } # end subTest
> 
> Result: Displays the HTML properly but the Embperl template 
> is not used.
> 
> And here are the Apache conf pieces relevant for Embperl:
> 
>     AddType text/html .epl
>     EMBPERL_APPNAME testapp
>     EMBPERL_DEBUG 0x7fffffff
>     EMBPERL_ESCMODE 0
>     EMBPERL_OPTIONS 16
>     EMBPERL_OBJECT_BASE _base.epl
>     PerlModule Embperl
> 
>     <FilesMatch "\.htm.?|\.epl$">
>         SetHandler perl-script
>         PerlHandler Embperl::Object
>     </FilesMatch>
> 
>         ScriptAlias /cgi-bin/ /data/apache/htdocs/testsite/cgi-bin/
>         <Directory "/data/apache/htdocs/testsite/cgi-bin/">
>         <FilesMatch "\.pl$">
>                 EMBPERL_APPNAME test
>                 SetHandler perl-script
>                 PerlResponseHandler ModPerl::Registry
>         </FilesMatch>
>                 SSLRequireSSL
>                 SSLOptions +StdEnvVars
>                 AllowOverride None
>                 Options None +ExecCGI
>                 Order allow,deny
>                 Allow from all
>         </Directory>
> 
> When *.html files are processed I can see Embperl 
> (embperl.log) going through the _base.epl file then to each 
> of the other parts of the template.  When the *.pl script is 
> run the embperl.log file shows the new APPNAME 'test" and 
> only _base.epl being found and imported, I don't see 
> references to any other piece of the template and none of the 
> template is sent to the browser.  I've attempted many 
> variations on Embperl::Object::Execute including specifying 
> appname, object_base/object_addpath, and inputfile values.
> 
> Am I way off on how I am trying to use 
> Embperl::Object::Execute in this way?  For the purposes of 
> this exercise I want to avoid a complete conversion to 
> Embedded perl within .html files.
> 
> Thanks for the help,
> 
> Chris
> 
> 


 
** Virus checked by BB-5000 Mailfilter ** 


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org