You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Justin Harrison <ju...@astyrrian.com> on 2003/07/26 21:13:01 UTC

Modules not functioning correctly

Hi,

I have the following code:

[- $verify = Execute ({'object' => '/.../code.pm',syntax => 'Perl'}); -]

Inside code.pm:

sub code_form_input_errors {
use Embperl::Form::Validate;
use lib '/.../code';
use rules;
my $epf = new Embperl::Form::Validate(&codeform);

my $errors = $epf -> validate_messages;


if (@{$errors}) {
	return $errors;
} else {
	return;
}	
}

However, randomly, when I invoke:

[- $code_input_errors = $code->code_form_input_errors -]

I get:

[26754]ERR: 24: Error in Perl code: Undefined subroutine
&Embperl::__4::codeform called at /.../code.pm line 8.  

Sometimes it happens. Sometimes it doesn't. Why? What is going on?

Rules.pm looks like this:

sub codeform {
return([
	[-key => 'username',
  	-name => 'Username',
  	-msg => 'Please enter a Username.',
  	required =>'1',
	-msg => 'The Username entered was too short.',
	length_min =>'1',
	-msg => 'The Username entered was too long.',
	length_max =>'15',
	],

	[-key => 'token',
	-name => 'Verification Token',
  	-msg => 'Please enter a Verification Token.',
  	required => '1',
	-msg => 'The Verification Token entered was too short.',
	length_min => '1',
	-msg => "The Verification Token entered was too long.",
	length_max => '60',
	],        	
]);
}

1;

I've avoided explicitly stating package names, but I still get this madness?

Justin


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


RE: Modules not functioning correctly

Posted by Bengt Rasmusson <be...@kabkonsult.se>.
When encountering the problem mentioned in this thread I have successfully
used Angus solutions - I usually use solution 2. But today I experienced
something curious (I am using b08).

In my previous .epl pages I successfully used "use conn;" which referred to
a file named conn.pm which at the top included the line "package conn;". In
conn.pm I have a sub called "connection" and in the .epl pages I refer to it
as "conn::connection()".

Today I created a new .epl file as a copy of one of the working .epl pages
and named it test.epl. I also created new .pm file called conn_pages.pm. In
test.epl I have the line "use conn_pages;" and in conn_pages.pm I have the
line "package conn_pages;".  In conn_pages.pm I have a sub called
"connection" and in the .epl page I refer to it as
"conn_pages::connection()". But this don't work - now and then I receive the
familiar error message about undefined function.

I then made an exakt copy of test.epl and of conn_pages.pm, and named them
test2.epl and pagesconn.pm. In test2.epl I have the line "use pagesconn;"
and in pagesconn.pm the line "package pagesconn;". And as suspected: In
pagesconn.pm I have a sub called "connection" and in the .epl page I refer
to it as "pagesconn::connection()". This works fine!

So in summary:
"use conn;", "conn::connection()", conn.pm, and "package conn;" works!
"use conn_pages;", "conn_pages::connection()", conn_pages.pm, and "package
conn_pages;" does *not* work!
"use pagesconn;", "pagesconn::connection()", pagesconn.pm, and "package
pagesconn;" works!

Can anyone explane this behavior? Isn't underscore an allowed character in a
package name? Or in library file names? Or?

Bengt

-----Ursprungligt meddelande-----
Fran: Angus Lees [mailto:gus@inodes.org]
Skickat: den 28 juli 2003 19:48
Till: Justin Harrison
Kopia: embperl@perl.apache.org
Amne: Re: Modules not functioning correctly


At Sat, 26 Jul 2003 22:08:50 -0400, Justin Harrison wrote:
> All the files are uniquely titled. i.e, there is only one code.pm, one
> rules.pm, etc. Many other embperl pages "use" rules.pm, but they are all
the
> same files.

When you do "use rules;" the first time, perl finds the right rules.pm
file and compiles it.  It then remembers that it has done so (in %INC)
and later "use rules;" invocations do nothing.  This means that every
page after the first (for each apache child process), encounters an
undefined &codeform.


So you have several solutions:

1.  ensure rules.pm gets reloaded every time.

Try replacing "use rules;" with "do $path_to_rules_pm;".  This will
force perl to recompile rules.pm every time.  Fairly nasty since it
ends up duplicating the function for each caller, each time its run.


2.  compile it once and put &codeform somewhere you can find it.

Add "package rules;" to the top of rules.pm.

Everywhere you use "&codeform", replace it with "&rules::codeform".

This is the most efficient solution, since the first bit of code to
"use rules" actually loads and compiles rules.pm and then everyone
just refers to the same function.


3.  compile it once and import an alias for &codeform into each
    caller.

Add this to the top of rules.pm:

 package rules;

 use base qw(Exporter);
 our @EXPORT = qw(&codeform);

The other thing that "use" does is invoke "import PackageName".  In
addition to method (2), the above code inherits a suitable import()
function from Exporter.  This import function will make an alias for
&rules::codeform in all packages that do "use rules".

This is the easiest solution, since you shouldn't have to actually
modify any code beyond those simple changes to rules.pm.



For more information, see "perldoc -f package", "perldoc -f use" and
"perldoc Exporter" (probably in that order).

--
 - Gus

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



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


Re: Modules not functioning correctly

Posted by Angus Lees <gu...@inodes.org>.
At Sat, 26 Jul 2003 22:08:50 -0400, Justin Harrison wrote:
> All the files are uniquely titled. i.e, there is only one code.pm, one
> rules.pm, etc. Many other embperl pages "use" rules.pm, but they are all the
> same files.

When you do "use rules;" the first time, perl finds the right rules.pm
file and compiles it.  It then remembers that it has done so (in %INC)
and later "use rules;" invocations do nothing.  This means that every
page after the first (for each apache child process), encounters an
undefined &codeform.


So you have several solutions:

1.  ensure rules.pm gets reloaded every time.

Try replacing "use rules;" with "do $path_to_rules_pm;".  This will
force perl to recompile rules.pm every time.  Fairly nasty since it
ends up duplicating the function for each caller, each time its run.


2.  compile it once and put &codeform somewhere you can find it.

Add "package rules;" to the top of rules.pm.

Everywhere you use "&codeform", replace it with "&rules::codeform".

This is the most efficient solution, since the first bit of code to
"use rules" actually loads and compiles rules.pm and then everyone
just refers to the same function.


3.  compile it once and import an alias for &codeform into each
    caller.

Add this to the top of rules.pm:

 package rules;

 use base qw(Exporter);
 our @EXPORT = qw(&codeform);

The other thing that "use" does is invoke "import PackageName".  In
addition to method (2), the above code inherits a suitable import()
function from Exporter.  This import function will make an alias for
&rules::codeform in all packages that do "use rules".

This is the easiest solution, since you shouldn't have to actually
modify any code beyond those simple changes to rules.pm.



For more information, see "perldoc -f package", "perldoc -f use" and
"perldoc Exporter" (probably in that order).

-- 
 - Gus

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


RE: Modules not functioning correctly

Posted by "Cameron B. Prince" <cp...@rideware.com>.
Hi Justin,

You may know this already, if so, sorry... I'm using packages with my
Embperl project too...

To troubleshoot them, you can actually use Vim to run perl against them.

Open your package in vi or vim (vi is an alias for Vim on RH when it's
installed) and do the following:

Shift g (move all the way to the end of the file)
v (go into visual mode)
gg (highlight to the top)
!perl -wc -Mstrict (run perl on the highlighted portion)

This will replace your file's contents with the output of running perl on
it. So be sure to use u to undo it after you read it.

This may help you isolate problems that aren't visible when calling the
package with Embperl.

Good luck,
Cameron


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


RE: Modules not functioning correctly

Posted by Justin Harrison <ju...@astyrrian.com>.
I figure this might be mentionable (Not that I want to flood the mailing
list or anything - Sorry everyone!) - I've been running a dev build of
Embperl b9 for a few months now, which is what may have attributed to some
instability. Last night I upgraded to the newest build from June, however.
Is there anyway to verify that it definitely updated?

Justin 

> -----Original Message-----
> From: Justin Harrison [mailto:justin@astyrrian.com] 
> Sent: Sunday, July 27, 2003 2:40 PM
> To: embperl@perl.apache.org
> Subject: RE: Modules not functioning correctly
> 
> After I had just restarted apache I tried to run one Embperl page and
> received:
> 
> [Sun Jul 27 14:32:04 2003] [error] [30184]ERR:  24:  Error in 
> Perl code:
> Undefined subroutine &Embperl::__6::helpform called at 
> /home/zo/zo/lib/zoweb/help/help.pm line 8.
> 
> 
> Again, the same code area - trying to use a sub routine in 
> rules.pm, which is included in the sub routine called from 
> the Embperl directly. This time it didn't segfault (That 
> isn't too typical and usually I can try to figure out what 
> causes it, typically bad code on my part). This behavior 
> occurs 90% of the time on page refreshes (Not sure how!). If 
> I refresh enough, the error doesn't occur - And I've been 
> refreshing quite a bit now, and I can't even reproduce it.
> 
> Justin 
> 
> > -----Original Message-----
> > From: Justin Harrison [mailto:shadowj4@doublebagel.com]
> > Sent: Sunday, July 27, 2003 2:31 PM
> > To: cprince@rideware.com; 'Justin Harrison'; 'Angus Lees'
> > Cc: embperl@perl.apache.org
> > Subject: RE: Modules not functioning correctly
> > 
> > [Sun Jul 27 14:26:25 2003] [error] [30184]ERR:  24:  Error in Perl 
> > code:
> > Undefined subroutine &Embperl::__5::signupform called at 
> > /home/zo/zo/lib/zoweb/signup/signup.pm line 8.
> > [Sun Jul 27 14:26:36 2003] [notice] child pid 7437 exit signal 
> > Segmentation fault (11)
> > 
> > 
> > This is after apache has definitely been restarted, and in another 
> > block of code entirely that uses the same design. I can't _imagine_ 
> > why it would segfault - it works other times.
> > But this is typical of behavior I have experienced in 
> trying to code 
> > on Embperl. It is so eratic and sometimes unstable, and I can't 
> > possibly figure out why. It is very annoying. I love 
> Embperl. It is a 
> > great framework. But I can't at all understand _why_ it 
> does this. Its 
> > so undesirable! Ugh!
> > 
> > Justin
> > 
> > > -----Original Message-----
> > > From: Cameron B. Prince [mailto:cprince@rideware.com]
> > > Sent: Sunday, July 27, 2003 2:22 PM
> > > To: 'Justin Harrison'; 'Angus Lees'
> > > Cc: embperl@perl.apache.org
> > > Subject: RE: Modules not functioning correctly
> > > 
> > > 
> > > > All the files are uniquely titled. i.e, there is only one
> > > code.pm, one
> > > > rules.pm, etc. Many other embperl pages "use" rules.pm, but
> > > they are
> > > > all the same files.
> > > 
> > > I have noticed this behavior on occasion. I tracked it down to a 
> > > problem with my code in a specific block. I only got the 
> error when 
> > > that block was executed. However, each time, I found the 
> error was 
> > > listed in the primary apache error.log file.
> > > 
> > > You might try a 'tail -f error.log' and then reproduce the error. 
> > > Hopefully you will then see the cause.
> > > 
> > > Good luck,
> > > Cameron
> > > 
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
> 


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


RE: Modules not functioning correctly

Posted by Justin Harrison <ju...@astyrrian.com>.
After I had just restarted apache I tried to run one Embperl page and
received:

[Sun Jul 27 14:32:04 2003] [error] [30184]ERR:  24:  Error in Perl code:
Undefined subroutine &Embperl::__6::helpform called at
/home/zo/zo/lib/zoweb/help/help.pm line 8.


Again, the same code area - trying to use a sub routine in rules.pm, which
is included in the sub routine called from the Embperl directly. This time
it didn't segfault (That isn't too typical and usually I can try to figure
out what causes it, typically bad code on my part). This behavior occurs 90%
of the time on page refreshes (Not sure how!). If I refresh enough, the
error doesn't occur - And I've been refreshing quite a bit now, and I can't
even reproduce it.

Justin 

> -----Original Message-----
> From: Justin Harrison [mailto:shadowj4@doublebagel.com] 
> Sent: Sunday, July 27, 2003 2:31 PM
> To: cprince@rideware.com; 'Justin Harrison'; 'Angus Lees'
> Cc: embperl@perl.apache.org
> Subject: RE: Modules not functioning correctly
> 
> [Sun Jul 27 14:26:25 2003] [error] [30184]ERR:  24:  Error in 
> Perl code:
> Undefined subroutine &Embperl::__5::signupform called at 
> /home/zo/zo/lib/zoweb/signup/signup.pm line 8.
> [Sun Jul 27 14:26:36 2003] [notice] child pid 7437 exit 
> signal Segmentation fault (11)
> 
> 
> This is after apache has definitely been restarted, and in 
> another block of code entirely that uses the same design. I 
> can't _imagine_ why it would segfault - it works other times. 
> But this is typical of behavior I have experienced in trying 
> to code on Embperl. It is so eratic and sometimes unstable, 
> and I can't possibly figure out why. It is very annoying. I 
> love Embperl. It is a great framework. But I can't at all 
> understand _why_ it does this. Its so undesirable! Ugh!
> 
> Justin 
> 
> > -----Original Message-----
> > From: Cameron B. Prince [mailto:cprince@rideware.com]
> > Sent: Sunday, July 27, 2003 2:22 PM
> > To: 'Justin Harrison'; 'Angus Lees'
> > Cc: embperl@perl.apache.org
> > Subject: RE: Modules not functioning correctly
> > 
> > 
> > > All the files are uniquely titled. i.e, there is only one
> > code.pm, one
> > > rules.pm, etc. Many other embperl pages "use" rules.pm, but
> > they are
> > > all the same files.
> > 
> > I have noticed this behavior on occasion. I tracked it down to a 
> > problem with my code in a specific block. I only got the error when 
> > that block was executed. However, each time, I found the error was 
> > listed in the primary apache error.log file.
> > 
> > You might try a 'tail -f error.log' and then reproduce the error. 
> > Hopefully you will then see the cause.
> > 
> > Good luck,
> > Cameron
> > 
> 


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


RE: Modules not functioning correctly

Posted by Justin Harrison <sh...@doublebagel.com>.
[Sun Jul 27 14:26:25 2003] [error] [30184]ERR:  24:  Error in Perl code:
Undefined subroutine &Embperl::__5::signupform called at
/home/zo/zo/lib/zoweb/signup/signup.pm line 8.
[Sun Jul 27 14:26:36 2003] [notice] child pid 7437 exit signal Segmentation
fault (11)


This is after apache has definitely been restarted, and in another block of
code entirely that uses the same design. I can't _imagine_ why it would
segfault - it works other times. But this is typical of behavior I have
experienced in trying to code on Embperl. It is so eratic and sometimes
unstable, and I can't possibly figure out why. It is very annoying. I love
Embperl. It is a great framework. But I can't at all understand _why_ it
does this. Its so undesirable! Ugh!

Justin 

> -----Original Message-----
> From: Cameron B. Prince [mailto:cprince@rideware.com] 
> Sent: Sunday, July 27, 2003 2:22 PM
> To: 'Justin Harrison'; 'Angus Lees'
> Cc: embperl@perl.apache.org
> Subject: RE: Modules not functioning correctly
> 
> 
> > All the files are uniquely titled. i.e, there is only one 
> code.pm, one 
> > rules.pm, etc. Many other embperl pages "use" rules.pm, but 
> they are 
> > all the same files.
> 
> I have noticed this behavior on occasion. I tracked it down 
> to a problem with my code in a specific block. I only got the 
> error when that block was executed. However, each time, I 
> found the error was listed in the primary apache error.log file.
> 
> You might try a 'tail -f error.log' and then reproduce the 
> error. Hopefully you will then see the cause.
> 
> Good luck,
> Cameron
> 


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


RE: Modules not functioning correctly

Posted by "Cameron B. Prince" <cp...@rideware.com>.
> All the files are uniquely titled. i.e, there is only one code.pm, one
> rules.pm, etc. Many other embperl pages "use" rules.pm, but
> they are all the
> same files.

I have noticed this behavior on occasion. I tracked it down to a problem
with my code in a specific block. I only got the error when that block was
executed. However, each time, I found the error was listed in the primary
apache error.log file.

You might try a 'tail -f error.log' and then reproduce the error. Hopefully
you will then see the cause.

Good luck,
Cameron


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


RE: Modules not functioning correctly

Posted by Justin Harrison <ju...@astyrrian.com>.
All the files are uniquely titled. i.e, there is only one code.pm, one
rules.pm, etc. Many other embperl pages "use" rules.pm, but they are all the
same files.


Justin 

-----Original Message-----
From: Angus Lees [mailto:gus@inodes.org] 
Sent: Saturday, July 26, 2003 9:29 PM
To: Justin Harrison
Cc: embperl@perl.apache.org
Subject: Re: Modules not functioning correctly


do you use more than one rules.pm or more than one code.pm anywhere in your
site?

--
 - Gus


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


Re: Modules not functioning correctly

Posted by Angus Lees <gu...@inodes.org>.
do you use more than one rules.pm or more than one code.pm anywhere in
your site?

-- 
 - Gus

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


RE: Modules not functioning correctly

Posted by Justin Harrison <sh...@doublebagel.com>.
..If I refresh enough it randomly works fine.

Whats going on?

Justin 

-----Original Message-----
From: Justin Harrison [mailto:justin@astyrrian.com] 
Sent: Saturday, July 26, 2003 3:13 PM
To: embperl@perl.apache.org
Subject: Modules not functioning correctly

Hi,

I have the following code:

[- $verify = Execute ({'object' => '/.../code.pm',syntax => 'Perl'}); -]

Inside code.pm:

sub code_form_input_errors {
use Embperl::Form::Validate;
use lib '/.../code';
use rules;
my $epf = new Embperl::Form::Validate(&codeform);

my $errors = $epf -> validate_messages;


if (@{$errors}) {
	return $errors;
} else {
	return;
}	
}

However, randomly, when I invoke:

[- $code_input_errors = $code->code_form_input_errors -]

I get:

[26754]ERR: 24: Error in Perl code: Undefined subroutine
&Embperl::__4::codeform called at /.../code.pm line 8.  

Sometimes it happens. Sometimes it doesn't. Why? What is going on?

Rules.pm looks like this:

sub codeform {
return([
	[-key => 'username',
  	-name => 'Username',
  	-msg => 'Please enter a Username.',
  	required =>'1',
	-msg => 'The Username entered was too short.',
	length_min =>'1',
	-msg => 'The Username entered was too long.',
	length_max =>'15',
	],

	[-key => 'token',
	-name => 'Verification Token',
  	-msg => 'Please enter a Verification Token.',
  	required => '1',
	-msg => 'The Verification Token entered was too short.',
	length_min => '1',
	-msg => "The Verification Token entered was too long.",
	length_max => '60',
	],        	
]);
}

1;

I've avoided explicitly stating package names, but I still get this madness?

Justin


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


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