You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Steve Wilder <st...@matrixInteractive.net> on 2001/02/08 16:15:21 UTC

Scope of a an external package

  Hello.

  I just upgraded Embperl to 1.3.0 from 1.2.9.  With the previous version, I
was able to create an external package, and invoke the use command inside a
[! !] block.  Then I could call a subroutine from within normal [- -] or [+
+] blocks.

  But, with 1.3.0, if I put the "use cart_support.pm" inside a [! !] block,
I getting errors like the following...
Error in Perl code: Can't use global @_ in "my" at
/usr/local/apache/lib/perl/cart_support.pm line 446.

Which looks like this:
sub emailCustomer

        my ($fdata, $aCart, $an_array) = @_;

  If I put the "use cart_support.pm" inside a [- -] block, the error stops.

  I would rather not have to import/compile this package on every invocation
of the page, how can I get it back into the [! !] block?

  Thank you.

Steve Wilder
Matrix Interactive, Inc.
http://www.matrixinteractive.net/
Desk: 248.814.8235
Cell: 248.894.3128
Fax : 248.814.8236

Re: Scope of a an external package

Posted by Gerald Richter <ri...@ecos.de>.
>
> I think the reason the message stopped when I took it out of the [! !] was
> that was when I was dealing with the database connect problem.  I just
> caused the database connect problem to happen before the above syntax
> problem. :-(
>
> Sorry again.
>


No problem! I am happy that you found the error

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
-------------------------------------------------------------



RE: Scope of a an external package

Posted by Steve Wilder <st...@matrixInteractive.net>.
  :-( It was a stupid bug in my code.  Sorry to send you on a goose chase.

  A for-loop statement in the previous subroutine was constructed like so:
	for (my $i=$item_count+1; $i <=4, $i++) {

So, when it got to the next subroutine, it thought I was including the
"shift @_" in the "my" statement.

I think the reason the message stopped when I took it out of the [! !] was
that was when I was dealing with the database connect problem.  I just
caused the database connect problem to happen before the above syntax
problem. :-(

Sorry again.

Steve Wilder
Matrix Interactive, Inc.
http://www.matrixinteractive.net/
Desk: 248.814.8235
Cell: 248.894.3128
Fax : 248.814.8236

-----Original Message-----
From: Gerald Richter [mailto:richter@ecos.de]
Sent: Thursday, February 08, 2001 11:49 PM
To: Steve Wilder
Cc: Embperl
Subject: Re: Scope of a an external package




>
>   Nope.  I had the ; in the code, just didn't put it in the example here.
> This is what the real code looks like:
> [!
>         use DBI;
>         use DBD::mysql;
>         $connect_string = "DBI:mysql:topconlaser";
>         $Persistent::dbc = DBI->connect($connect_string, "*****",
"*****");
>         use CGI;
>         # use cart_support;
> !]
> [-
>         use cart_support;
>         $cgi = new CGI();
>         $cart_id = $cgi->cookie('cart_id');
>         $items_deleted = "";
> -]
>


This really sounds strange. There soundn't be a difference where you use
your module. The only thing that I can imagine at the moment, is if you
include the file, via the Execute import parameter, or if you use it
together with EmbperlObject, do you ? The [! !] will be executed when the
import happens and the [- -] not (that was different in 1.2.x)

Does the cart_support file has it's own package ?

Gerald

P.S. use is a compile time statement, so it is executed at the same time in
both cases and when the code is executed Perl doesn't do anything with the
use (even not check if the module is already there, as I wrote in my last
mail)


-------------------------------------------------------------
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: Scope of a an external package

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

>
>   Nope.  I had the ; in the code, just didn't put it in the example here.
> This is what the real code looks like:
> [!
>         use DBI;
>         use DBD::mysql;
>         $connect_string = "DBI:mysql:topconlaser";
>         $Persistent::dbc = DBI->connect($connect_string, "*****",
"*****");
>         use CGI;
>         # use cart_support;
> !]
> [-
>         use cart_support;
>         $cgi = new CGI();
>         $cart_id = $cgi->cookie('cart_id');
>         $items_deleted = "";
> -]
>


This really sounds strange. There soundn't be a difference where you use
your module. The only thing that I can imagine at the moment, is if you
include the file, via the Execute import parameter, or if you use it
together with EmbperlObject, do you ? The [! !] will be executed when the
import happens and the [- -] not (that was different in 1.2.x)

Does the cart_support file has it's own package ?

Gerald

P.S. use is a compile time statement, so it is executed at the same time in
both cases and when the code is executed Perl doesn't do anything with the
use (even not check if the module is already there, as I wrote in my last
mail)


-------------------------------------------------------------
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
-------------------------------------------------------------



Re: How can I have multiple OBJECT_BASE for differnt directoriesforone site ?

Posted by Gerald Richter <ri...@ecos.de>.
>
> Here's a quick observation. I was doing [- Execute ("header.html") -] it
> is much better to give it full path because the template file looks in the
> current direcoty as its root. So even [- Execute ("/header.html") -] fails
> under the /login directory because the file.html is in the / directory.
>
> [- Execute ("$docroot/header.html") -] works fine from any base file.
>

Yes, this works, but then you can't overwrite your header.html in a
subdirectory. It's better to set EMBPERL_OBJECT_STOPDIR to docroot, in this
case Embperl searches always upwards to the stopdir, regardless where it
founds the base template, so header.html without path will work again.

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
-------------------------------------------------------------



Re: How can I have multiple OBJECT_BASE for differnt directoriesforone site ?

Posted by bt...@linuxmonth.com.

On Fri, 9 Feb 2001, Gerald Richter wrote:

> >
> > Just an idea, as a workaround:
> >
> 
> Neil, you are right. We don't need two configurations blocks and it's not
> only a workaround, this is the better solution.
> 

Thanks Neil and Gerald. The below solution works great. Maybe add that to
the document.

> Just write
> 
> <Location />
>     PerlSetEnv EMBPERL_OBJECT_BASE sat-template.html
>     PerlSetEnv EMBPERL_FILESMATCH "\.html"
>     SetHandler perl-script
>     PerlHandler HTML::EmbperlObject
>     Options ExecCGI FollowSymLinks
> </Location>
> 
> and rename /login/sat-login-template.html to /login/sat-template.html and
> EmbperlObject will pickup the correct template
> 
> Sorry, Baiju, I could thought of this earlier. That's a much better way to
> go (at least if there isn't something in your special case that I am
> missing)

Here's a quick observation. I was doing [- Execute ("header.html") -] it
is much better to give it full path because the template file looks in the
current direcoty as its root. So even [- Execute ("/header.html") -] fails
under the /login directory because the file.html is in the / directory.

[- Execute ("$docroot/header.html") -] works fine from any base file.

Thank you very much. 

~Baiju


Re: How can I have multiple OBJECT_BASE for differnt directoriesforone site ?

Posted by Gerald Richter <ri...@ecos.de>.
>
> Just an idea, as a workaround:
>

Neil, you are right. We don't need two configurations blocks and it's not
only a workaround, this is the better solution.

Just write

<Location />
    PerlSetEnv EMBPERL_OBJECT_BASE sat-template.html
    PerlSetEnv EMBPERL_FILESMATCH "\.html"
    SetHandler perl-script
    PerlHandler HTML::EmbperlObject
    Options ExecCGI FollowSymLinks
</Location>

and rename /login/sat-login-template.html to /login/sat-template.html and
EmbperlObject will pickup the correct template

Sorry, Baiju, I could thought of this earlier. That's a much better way to
go (at least if there isn't something in your special case that I am
missing)

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
-------------------------------------------------------------



Re: How can I have multiple OBJECT_BASE for differnt directoriesforone site ?

Posted by Neil Gunton <ne...@nilspace.com>.
> > >
> > > Any other ideas ?
> > >
> >
> > Not so much. Maybe you can try to use <Directory> Blocks, instead of
> > <Location> and see if this changes anything (they are handle slightly
> > different inside of Apache)
> 
> Yeah, I had tried the <Directory> blocks first. Sigh.
> 
> ~Baiju

Just an idea, as a workaround:

If you want to achieve the effect of having two seperate
EMBPERL_OBJECT_BASE documents, why not just have one in the root
directory of your site, named (say) root_base.html and  have it include
a file called base.html. You then redefine base.html in whatever
subdirectories you have. In other words, using the "file inheritance" of
EmbperlObject you can achieve much the same effect as having two
separate base.html's. For example:

In httpd.conf:

	<Location />
		PerlSetEnv EMBPERL_OBJECT_BASE root_base.html
    		PerlSetEnv EMBPERL_FILESMATCH "\.html"
    		SetHandler perl-script
    		PerlHandler HTML::EmbperlObject
    		Options ExecCGI FollowSymLinks
	</Location>

/root_base.html

	[- Execute ('base.html') -]

/base.html

	(do some stuff relevant to the root of your website)

/login/base.html

	(do some stuff relevant to login)

I know this doesn't fix your specific problem, but it might help...

-Neil

Re: How can I have multiple OBJECT_BASE for differnt directoriesfor one site ?

Posted by Gerald Richter <ri...@ecos.de>.
>
> > >
> > > Any other ideas ?
> > >
> >
> > Not so much. Maybe you can try to use <Directory> Blocks, instead of
> > <Location> and see if this changes anything (they are handle slightly
> > different inside of Apache)
>
> Yeah, I had tried the <Directory> blocks first. Sigh.
>
>

Strange! I try to set it up here over the weekend and let you know if I find
anything, why this doesn't work.

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
-------------------------------------------------------------



Re: How can I have multiple OBJECT_BASE for differnt directoriesfor one site ?

Posted by bt...@linuxmonth.com.

On Fri, 9 Feb 2001, Gerald Richter wrote:

> >
> > Any other ideas ?
> >
> 
> Not so much. Maybe you can try to use <Directory> Blocks, instead of
> <Location> and see if this changes anything (they are handle slightly
> different inside of Apache)

Yeah, I had tried the <Directory> blocks first. Sigh.


~Baiju


Re: How can I have multiple OBJECT_BASE for differnt directoriesfor one site ?

Posted by Gerald Richter <ri...@ecos.de>.
>
> Any other ideas ?
>

Not so much. Maybe you can try to use <Directory> Blocks, instead of
<Location> and see if this changes anything (they are handle slightly
different inside of Apache)

Gerald



Re: How can I have multiple OBJECT_BASE for differnt directories for one site ?

Posted by bt...@linuxmonth.com.

On Fri, 9 Feb 2001, Gerald Richter wrote:

> >
> > I tried to following, but it did not work. Any suggestions or hints ? I
> > could not find anything under the EmbperlObject docs.
> >
> 
> Normaly this should work this way. What happens if you remove the first
> Location block, so that only the /login block exists? Is the right template
> now used ?

Yes, If the first one is removed the second template is used for /login
and nothing is used for /.

> 
> In the past there were some problems that mod_perl didn't set env vars
> correct, maybe, if you do not already, an upgrade to mod_perl 1.25 helps.
> (but I am not sure if all issuses with env vars are sorted out in 1.25)

I am using mod_perl 1.25 / Apache 1.3.17 / Perk 5.5003

Any other ideas ?

~Baiju


Re: How can I have multiple OBJECT_BASE for differnt directories for one site ?

Posted by Gerald Richter <ri...@ecos.de>.
>
> I tried to following, but it did not work. Any suggestions or hints ? I
> could not find anything under the EmbperlObject docs.
>

Normaly this should work this way. What happens if you remove the first
Location block, so that only the /login block exists? Is the right template
now used ?

In the past there were some problems that mod_perl didn't set env vars
correct, maybe, if you do not already, an upgrade to mod_perl 1.25 helps.
(but I am not sure if all issuses with env vars are sorted out in 1.25)

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
-------------------------------------------------------------



How can I have multiple OBJECT_BASE for differnt directories for one site ?

Posted by bt...@linuxmonth.com.
I tried to following, but it did not work. Any suggestions or hints ? I
could not find anything under the EmbperlObject docs.

<Location />
    PerlSetEnv EMBPERL_OBJECT_BASE sat-template.html
    PerlSetEnv EMBPERL_FILESMATCH "\.html"
    SetHandler perl-script
    PerlHandler HTML::EmbperlObject
    Options ExecCGI FollowSymLinks
</Location>

<Location /login>
    PerlSetEnv EMBPERL_OBJECT_BASE sat-login-template.html
    PerlSetEnv EMBPERL_FILESMATCH "\.html"
    SetHandler perl-script
    PerlHandler HTML::EmbperlObject
    Options ExecCGI FollowSymLinks
</Location>

The first Location directives object_base gets used for /login
I thought the the last Directive gets executed first? What am I missing ?

Thank you in advance.

-------------------------------------------------------------------------
Baiju Thakkar
http://www.perlmonth.com                        http://www.linuxmonth.com
Just use Perl;                                  #!/boot/linux



RE: Scope of a an external package

Posted by Steve Wilder <st...@matrixInteractive.net>.
  Nope.  I had the ; in the code, just didn't put it in the example here.
This is what the real code looks like:
[!
        use DBI;
        use DBD::mysql;
        $connect_string = "DBI:mysql:topconlaser";
        $Persistent::dbc = DBI->connect($connect_string, "*****", "*****");
        use CGI;
        # use cart_support;
!]
[-
        use cart_support;
        $cgi = new CGI();
        $cart_id = $cgi->cookie('cart_id');
        $items_deleted = "";
-]

Steve Wilder
Matrix Interactive, Inc.
http://www.matrixinteractive.net/
Desk: 248.814.8235
Cell: 248.894.3128
Fax : 248.814.8236

-----Original Message-----
From: Gerald Richter [mailto:richter@ecos.de]
Sent: Thursday, February 08, 2001 2:51 PM
To: Steve Wilder; Embperl
Subject: Re: Scope of a an external package


Hi,

>
>   I just upgraded Embperl to 1.3.0 from 1.2.9.  With the previous version,
I
> was able to create an external package, and invoke the use command inside
a
> [! !] block.  Then I could call a subroutine from within normal [- -] or
[+
> +] blocks.
>
>   But, with 1.3.0, if I put the "use cart_support.pm" inside a [! !]
block,
> I getting errors like the following...
> Error in Perl code: Can't use global @_ in "my" at
> /usr/local/apache/lib/perl/cart_support.pm line 446.
>

Looks like you missing the semikolon after use. For whatever reason after
the use Perl want's the semikolon, while it isn't necessary for all other
statements. Try

[! use cart_support.pm ; !]

>
>   I would rather not have to import/compile this package on every
invocation
> of the page, how can I get it back into the [! !] block?
>

Also is you would do it in a [- -] block, Perl itself compiles modules that
are included via use only once, so there is only a very small overhead for
perl to see if the module has already compiled. Anyway there is no need to
put it into a [- -] block.

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
-------------------------------------------------------------



Re: Scope of a an external package

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

>
>   I just upgraded Embperl to 1.3.0 from 1.2.9.  With the previous version,
I
> was able to create an external package, and invoke the use command inside
a
> [! !] block.  Then I could call a subroutine from within normal [- -] or
[+
> +] blocks.
>
>   But, with 1.3.0, if I put the "use cart_support.pm" inside a [! !]
block,
> I getting errors like the following...
> Error in Perl code: Can't use global @_ in "my" at
> /usr/local/apache/lib/perl/cart_support.pm line 446.
>

Looks like you missing the semikolon after use. For whatever reason after
the use Perl want's the semikolon, while it isn't necessary for all other
statements. Try

[! use cart_support.pm ; !]

>
>   I would rather not have to import/compile this package on every
invocation
> of the page, how can I get it back into the [! !] block?
>

Also is you would do it in a [- -] block, Perl itself compiles modules that
are included via use only once, so there is only a very small overhead for
perl to see if the module has already compiled. Anyway there is no need to
put it into a [- -] block.

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
-------------------------------------------------------------