Aug 4, 2010, 12:46 PM
Post #5 of 5
(3426 views)
Permalink
Using Embperl 2.4.0_3
- embperl1.pl -
use Embperl;
my $obj = Embperl::Execute({ object => 'test.epl' });
print "[$obj]\n";
if($obj->can('head')) {
print "YES";
$obj->head();
}
- test.epl -
[$ sub head $]
head
[$ endsub $]
main
---
%: perl embperl1.pl
[0]
Can't call method "can" without a package or object reference at
embperl1.pl line 6.
%: perl -v
This is perl, v5.10.1 (*) built for IA64.ARCHREV_0-thread-multi
From: Gerald Richter - ECOS [mailto:gerald.richter@ecos.de]
Sent: Monday, August 02, 2010 5:21 AM
To: Thompson, John; embperl@perl.apache.org
Subject: RE: Execute({ object => '...' })
Hi,
You don't need Embperl::Object. Embperl::Object is only if you need to
search (sub-)directories, like objects.
You should do something the following
Gerald
use Embperl;
my $obj = Embperl::Execute({ object => 'test.epl' });
$obj -> head ;
- test.epl -
[$ sub head $]
Text in head
[$ endsub $]
---------- Forwarded message ----------
From: Thompson, John <jthomp@midwestern.edu
<mailto:jthomp@midwestern.edu> >
Date: 2010/7/27
Subject: RE: Execute({ object => '...' })
To: embperl@perl.apache.org
OK, so I've decided to try to use import instead. I'm seeing this error:
--- embperl2.pl ---
use Embperl;
Embperl::Execute({ inputfile => 'test.epl', 'import' => 1 });
head();
--- test.epl ---
[$ sub head $]
head
[$ endsub $]
main
---
%perl embperl2.pl
[14900]ERR: 72: A Embperl sub is called and no Embperl request is
running
$Embperl::req undefined DOM.xs 284 at
/home/carsids/jthomp/perl/test/test.epl line 11.
I thought maybe it'd help if I was running this inside of an Apache
request (I'm using CGI), but I get the same error.
From: Andrew O'Brien [mailto:andrewo@oriel.com.au]
Sent: Tuesday, July 27, 2010 10:07 AM
To: Thompson, John
Subject: RE: Execute({ object => '...' })
Can you use import => 1 to get all the subs into the current namespace
and just check there?
Embperl::Object adds some overhead so I was just trying to avoid that.
If thats not an issue then just go ahead and set up the %ENV entries
according to the Embperl::Object doco and you're good to proceed with
your $obj->can checks like you intended.
-----Original Message-----
From: Thompson, John [mailto:jthomp@midwestern.edu]
Sent: Wed 28/07/2010 02:42
To: Andrew O'Brien
Subject: RE: Execute({ object => '...' })
You are correct, I wasn't thinking when I set up that epl file. As far
as the Execute({ sub => '...' }) option, I have been using that, however
I wanted to avoid the overhead of grep'ing the file first to see if the
function even exists. I want to call it if it exists, and not if it
doesn't. I figured the fastest way was to have Embperl process it using
object, and then do "if($obj->can('head')) { $obj->head(); }". Is there
a better way? (Also realize, that Embperl will be processing the whole
template in a second, so I figured since it does caching, I'd have very
little performance penalty.)
-----Original Message-----
From: Andrew O'Brien [mailto:andrewo@oriel.com.au]
Sent: Monday, July 26, 2010 4:56 PM
To: Thompson, John; embperl@perl.apache.org
Subject: RE: Execute({ object => '...' })
> From: Thompson, John [mailto:jthomp@midwestern.edu]
> Sent: Tuesday, 27 July 2010 2:47 AM
Hi John,
> I am attempting to use the Execute({ object => '...' })
> feature but am seeing strange results. Here are my two files:
Firstly, test.epl does not do what you think it does. It should read:
[$ sub head $]
[- print "head\n"; -]
[$ endsub $]
Secondly, to use embperl files as objects I believe you need to be using
Embperl::Object which has additional configuration requirements. For
offline processing I would suggest that it may be overkill.
If all you want to do is execute a sub in another file then following
approaches both work with standard Embperl:
use Embperl;
Embperl::Execute( { inputfile => 'test.epl', sub => 'head' } );
Embperl::Execute( 'test.epl#head' );
Cheers,
Andrew
> - embperl1.pl -
>
> use Embperl;
>
>
>
> my $obj = Embperl::Execute({ object => 'test.epl' });
>
> print "[$obj]\n";
>
> ---
>
>
>
> - test.epl -
>
> [$ sub head $]
>
> print "head\n";
>
> [$ endsub $]
>
>
>
> print "main\n";
>
> ---
>
>
>
> When I execute embperl1.pl I get:
>
>
>
> % perl embperl1.pl
>
> [0]
>
>
>
> Any ideas? I am on HP-UX itanium ia64, Embperl 2.3.0. I
> decided to double check and make sure Embperl passed all
> tests when I built it, it did.
>
>