You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Neil Gunton <ne...@nilspace.com> on 2002/02/25 22:35:56 UTC

Local [$ sub $] variables in 2.0

Hi Gerald,

I have a feature suggestion for 2.0, unless you've already done it. I
took a look at the docs for 2.0 and couldn't find any mention of this,
but I could be mistaken. If I'm missing something that's already there,
then I apologise in advance!

I'd like to be able to make variables local to a [$ sub $] subroutine
(like 'my' for a standard perl sub). Will this be possible in 2.0, maybe
using the [$ var $] directive combined with a local namespace for the
[$ sub $]? The [$ var $] would then be local to the sub, rather than
the whole file. Like this:

[$ sub foo $]

   [$ var $x, $y, $z $]
   [- ($x, $y, $z) = @_ -]

[$ endsub $]

[# Can't refer to $x etc here #]

... or something similar. Of course, the ideal solution would be for the
standard 'my' to apply to the whole Embperl sub. I don't know if this is
feasible given the implementation of Embperl and Perl itself.

This would greatly aid maintenance and debugging of large projects (like
mine is growing to be) which have a number of Embperl subs in each file.
Currently all the vars are global (within that file).

Also, while I'm on the topic, would recursion be possible at any point?
Not as pressing, but always useful.

Thanks!

-Neil

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


Re: Local [$ sub $] variables in 2.0

Posted by Neil Gunton <ne...@nilspace.com>.
> Ok, so I've installed 2.0b5 now, and here's the first problem. Is [$ var
> $] not valid any more? I have that on line 1 of one of my subroutine
> files, executed using Execute ({object => ...}). I get the following
> error: (this is using EmbperlObject)
> 
> [1410]ERR: 24: Error in Perl code: 'undef' is not a valid variable name
> at /www/vhosts/www.crazyguyonabike.com/htdocs/Core.epl line 1
>     \<br\>\&nbsp;\&nbsp;\&nbsp;\&nbsp;BEGIN failed--compilation aborted
> (in cleanup) 'undef' is not a valid variable name at
> /www/vhosts/www.crazyguyonabike.com/htdocs/Core.epl line 1
>     \<br\>\&nbsp;\&nbsp;\&nbsp;\&nbsp;BEGIN failed--compilation aborted
> at /www/vhosts/www.crazyguyonabike.com/htdocs/Core.epl line
> 1.
> 
> I tried adding an actual variable, e.g. [$ var $xxx $], but same error.

Oops. Looks like I was editing the wrong file here. I have Core.epl in
another virtual host, and was trying this on the wrong version. The [$
var $xxx $] makes the error go away. I guess the question still stands,
though - should [$ var $] by itself work? Is this a bug or a feature?

Apologies for the confusion.

(sound of hand repeatedly slapping forehead)

/Neil

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


Re: Local [$ sub $] variables in 2.0

Posted by Kee Hinckley <na...@somewhere.com>.
At 4:18 PM +0100 2/26/02, Gerald Richter wrote:
>Wait for 2.0b6. 2.0b6 have moved from HTML::Embperl to Embperl namespace, so
>you are able to install both at the same time. You can run your production
>with 1.3.4 and test with 2.0 without interferences.

That's great news!  I was going to set up a second IP address and 
Apache server on the machine, but this will be much easier.
-- 

Kee Hinckley - Somewhere.Com, LLC
http://consulting.somewhere.com/
nazgul@somewhere.com

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

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


Re: Local [$ sub $] variables in 2.0

Posted by Neil Gunton <ne...@nilspace.com>.
Gerald Richter wrote:
> This only works in 2.0bx, not in 1.3.4. I see if I could add the [$ var $]
> to 2.0, so you don't have these kinds of problems

Thanks, Gerald. I look forward to being able to test out 2.0 on my
existing codebase, so that I can help in finding lingering bugs.
Meantime, I'll just keep plugging away with 1.3.4...

-Neil

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


Re: Local [$ sub $] variables in 2.0

Posted by Gerald Richter <ri...@ecos.de>.
>
> Sorry, looks like I misunderstood the syntax here. I thought you could
> just put [$ var $] (without any variables) to force the file to use the
> equivalent of 'strict'.
>

You just used it in a way I never tought of :-)

> > Put a [* use strict ; *] at the top of your page, by this you should get
the
> > same result.
>
> When I try this (in 1.3.4) the page blows up with a non-useful error
> message:

This only works in 2.0bx, not in 1.3.4. I see if I could add the [$ var $]
to 2.0, so you don't have these kinds of problems

Gerald


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------



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


Re: Local [$ sub $] variables in 2.0

Posted by Neil Gunton <ne...@nilspace.com>.
> Wait for 2.0b6. 2.0b6 have moved from HTML::Embperl to Embperl namespace, so
> you are able to install both at the same time. You can run your production
> with 1.3.4 and test with 2.0 without interferences.

Ok...

> > Ok, so I've installed 2.0b5 now, and here's the first problem. Is [$ var
> > $] not valid any more?
> 
> Ooh, does it work in 1.3.4? It was never ment to work....

Sorry, looks like I misunderstood the syntax here. I thought you could
just put [$ var $] (without any variables) to force the file to use the
equivalent of 'strict'.

> Put a [* use strict ; *] at the top of your page, by this you should get the
> same result.

When I try this (in 1.3.4) the page blows up with a non-useful error
message:

[1768]ERR: 24: Error in Perl code: Can't locate object method "init" via
package "HTML::Embperl::DOC::_8" at
/www/vhosts/home.nilspace.com/htdocs/base.epl line 10.

[1768]ERR: 24: Error in Perl code: Can't locate object method
"email_summary" via package "HTML::Embperl::DOC::_8" at
/www/vhosts/home.nilspace.com/htdocs/index.html line 8.

Not sure what's happening here. When I put the [$ var $] back it works.
Is it worth trying to debug this, or perhaps better to just wait for
2.0b6 and go from there?

Thanks again

-Neil

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


Re: Local [$ sub $] variables in 2.0

Posted by Gerald Richter <ri...@ecos.de>.
>
> I haven't used [* *] yet, mainly because the documentation still says
> it's very experimental.

Yes it is experminetal, but it works as long as you don't mix loops and
conditionals from Embperl and from Perl

>
> I have tried to test out Embperl 2.0b5 before, but put off real effort
> because it always fails big time on my existing (large!) codebase, and I
> am currently very short of spare time. Also, I noticed in the README.v2
> that [- exit -] doesn't work (which I use extensively),

This will (hopefully) work in 2.0b6

> and print OUT
> doesn't work in loops (I use that frequently for debugging).

print OUT works in 2.0b5, I have to correct the README.v2

>
> I guess it's time now to invest the effort required to make everything
> work under 2.0... What's the best way to do this?

Wait for 2.0b6. 2.0b6 have moved from HTML::Embperl to Embperl namespace, so
you are able to install both at the same time. You can run your production
with 1.3.4 and test with 2.0 without interferences.

>
> Ok, so I've installed 2.0b5 now, and here's the first problem. Is [$ var
> $] not valid any more?

Ooh, does it work in 1.3.4? It was never ment to work....

Put a [* use strict ; *] at the top of your page, by this you should get the
same result.

Gerald



-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------



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


Re: Local [$ sub $] variables in 2.0

Posted by Neil Gunton <ne...@nilspace.com>.
Gerald Richter wrote:
> 
> You can use 'my' or 'local' just like in Perl with 2.0:
> 
> [$sub foo $]
> [* my $a *]
> 
> .....
> 
> [$endsub$]
> 
> BTW: [* local $x *] already works since 1.2

I haven't used [* *] yet, mainly because the documentation still says
it's very experimental. Also, the docs say that this makes the variable
scope across multiple Embperl blocks for the *whole file*. Thus I
assumed that this would not be useful for individual [$ sub $] blocks.

I have tried to test out Embperl 2.0b5 before, but put off real effort
because it always fails big time on my existing (large!) codebase, and I
am currently very short of spare time. Also, I noticed in the README.v2
that [- exit -] doesn't work (which I use extensively), and print OUT
doesn't work in loops (I use that frequently for debugging). This is why
I've put off a full migration to 2.0.

I guess it's time now to invest the effort required to make everything
work under 2.0... What's the best way to do this? I'd like to help you
debug, but I can't do my major development work with an incomplete
toolset. So I switch back and forth (using 'make install'), try out,
send you the bug report, and then go back to 1.3.4 to continue
development in the meantime? Are there any httpd.conf settings which are
recommended for this process? (e.g. to generate the best logfile for
you).

Ok, so I've installed 2.0b5 now, and here's the first problem. Is [$ var
$] not valid any more? I have that on line 1 of one of my subroutine
files, executed using Execute ({object => ...}). I get the following
error: (this is using EmbperlObject)

[1410]ERR: 24: Error in Perl code: 'undef' is not a valid variable name
at /www/vhosts/www.crazyguyonabike.com/htdocs/Core.epl line 1 
    \<br\>\&nbsp;\&nbsp;\&nbsp;\&nbsp;BEGIN failed--compilation aborted
(in cleanup) 'undef' is not a valid variable name at
/www/vhosts/www.crazyguyonabike.com/htdocs/Core.epl line 1 
    \<br\>\&nbsp;\&nbsp;\&nbsp;\&nbsp;BEGIN failed--compilation aborted
at /www/vhosts/www.crazyguyonabike.com/htdocs/Core.epl line
1.

I tried adding an actual variable, e.g. [$ var $xxx $], but same error.

TIA

-Neil

p.s. httpd.conf settings are:

PerlSetEnv EMBPERL_SESSION_HANDLER_CLASS no
PerlSetEnv EMBPERL_DEBUG 0
PerlSetEnv EMBPERL_LOG /dev/null
PerlSetEnv EMBPERL_ESCMODE 0
PerlSetEnv EMBPERL_OPTIONS 16
PerlSetEnv EMBPERL_MAILHOST mail.nilspace.com
PerlSetEnv EMBPERL_OBJECT_BASE base.epl
PerlSetEnv EMBPERL_OBJECT_FALLBACK notfound.html
PerlSetEnv EMBPERL_OBJECT_ADDPATH /www/vhosts/lib/perl/Apache/Nilspace/

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


Re: Local [$ sub $] variables in 2.0

Posted by Gerald Richter <ri...@ecos.de>.
>
> ... or something similar. Of course, the ideal solution would be for the
> standard 'my' to apply to the whole Embperl sub. I don't know if this is
> feasible given the implementation of Embperl and Perl itself.
>

You can use 'my' or 'local' just like in Perl with 2.0:

[$sub foo $]
[* my $a *]

.....

[$endsub$]

BTW: [* local $x *] already works since 1.2

>
> Also, while I'm on the topic, would recursion be possible at any point?

Yes, with [* local $foo *] it's already possible since 1.2. In 2.0 you can
addionaly use the [* my $foo *].

Gerald

-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------



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