You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by will trillich <wi...@serensoft.com> on 2001/05/03 07:29:53 UTC

mod_perl subs defined, but DON'T EXIST? wtf?!

long version--

okay, i'm confused, and this time it's not related to cookies.
it happens to be the same bloinkin' project, but this time it's
perl in general, that's got me baffled...

if have a subroutine that's defined, but it's not showing up as
defined. i used the *Symbol::Table::name{CODE} method myself and
sure enough, there's no CODE for the defined subroutine...

here's my debug snippet, in context--

###########################################

package My::Access;
# File: My/Access.pm

use strict;
use Apache::Constants qw(OK SERVER_ERROR);
use Apache::TicketTool;
use Apache::Log;

sub handler {
	my $r = shift;

	{
		no strict;
		# see camel book, page 282
		my $x = '';
		my @key = qw(
			SCALAR ARRAY HASH
			CODE FILEHANDLE
		);	# ignore GLOB, PACKAGE, NAME
		foreach my $item ( sort keys %My::Access:: ) {
			my $descr = '';
			foreach ( @key ) {
				$descr .= "\t$_\n"
					if defined( *{$item}{$_} );
			}
			$x .= "$item\n$descr";
		}
		#$r->log->debug('My::Access::handler -- ' . join '/',grep *{$_}{CODE},sort keys %My::Access::);
		$r->log->debug("My::Access::handler -- \n$x");
	}

	if ( &needs_login($r) ) {

		if ( &logging_in($r) ) {

			# currently trying to log in (user/password supplied)
			$r->log->debug('My::Access::handler logging in (PerlHandler=>checkUser())');

			my $h = $r->get_handlers( 'PerlHandler' );
			unshift @{$h},\&checkUser ; # do &checkUser first
			$r->set_handlers( PerlHandler => $h );

		} else {

			# no ticket, no username -- so ask for login
			$r->log->debug('My::Access::handler needs login (PerlHandler=>ask_login())');

			$r->set_handlers( PerlHandler => [ \&ask_login ] );

		}
	}

	return OK;
}

sub logging_in {	 #exists, but not as code?
...
}

sub needs_login {	 #exists, but not as code?
...
}

sub ask_login {	 #exists, but not as code?
...
}

sub make_login {	# doesn't exist at all???
...
}

sub checkUser {	 #exists, but not as code?
...
}

sub make_welcome {	# doesn't exist at all???
...
}

sub need_cookies {	# doesn't exist at all???
...
}

1;

__END__


###########################################

and here's the resulting log output, which gives my mind a
temporal inversion tachyon matrix pulse*:

###########################################

[Thu May  3 00:09:04 2001] [notice] Apache/1.3.9 configured -- resuming normal operations
[Thu May  3 00:09:04 2001] [notice] suEXEC mechanism enabled (wrapper: /usr/lib/apache/suexec)
[Thu May  3 00:09:05 2001] [debug] /usr/local/lib/site_perl/My/Access.pm(52): [client 208.33.90.85] My::Access::handler -- 
BEGIN
	SCALAR
OK
	SCALAR
	CODE
SERVER_ERROR
	SCALAR
	CODE
ask_login
	SCALAR
checkUser
	SCALAR
handler
	SCALAR
	CODE
logging_in
	SCALAR
needs_login
	SCALAR

[Thu May  3 00:09:05 2001] [error] Undefined subroutine &My::Access::needs_login called at /usr/local/lib/site_perl/My/Access.pm line 55.

where's make_login? make_welcome? need_cookies? hmm? aaugh!

if it was a non-terminated string or something of that nature 1)
the perl tokenizer would object and 2) it would then be "all are
screwy from line X on downward" which ain't the case (checkUser
seems to show up on the radar, and it comes after make_login,
which is nowhere to be seen).

###########################################

*star trek speak for "i have no *#$! idea what's happening here."

any wild-ass guesses would be appreciated.  (do i win a prize for
the most difficulty with a simple situation? or at least an
honorable mention for most belligerent refusal to move on and get
a life?)

###########################################

short version--

WTF?

-- 
will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

Re: [OT] Re: mod_perl subs defined, but don't exist? SOLVED mostly

Posted by will trillich <wi...@serensoft.com>.
On Fri, May 04, 2001 at 12:29:30AM -0500, Ken Williams wrote:
> will@serensoft.com (will trillich) wrote:
> > >    sub search {
> > >        # ....
> > >        {
> > >            use CGI qw/:standard/;
> > >            my	$form = join '',
> > >                map {
> > >                    hidden(
> > >                        -name => $_,
> > >                        -value => $arg->{$_},
> > >                        ) . "\n"
> > >                }
> > >                grep(
> > >                    $arg->{$_} and ($_ ne 'd') and ($_ ne 'go')
> >
> >as is, the functions that follow (top-level 'sub xyz {}') get
> >screwy. code disappears.
> >
> >replace "and" with "&&" and all is well. boggles my mind.
> 
> 
> Well, as far as I can tell, the original code doesn't even compile
> because there aren't enough arguments to grep().  That's why I couldn't
> test it.  

	grep(
		$arg->{$_} and ($_ ne 'd') and ($_ ne 'go')
	, keys %$arg # note the leading comma...
	)

aha -- so maybe "x and y and z , pdq" has lexical precedence
where the (z,pdq) parses higher, as in

	x and y and (z , pdq)

versus what i expected, which was

	(x and y and z) , pdq

hmm?

-- 
will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!

[OT] Re: mod_perl subs defined, but don't exist? SOLVED mostly

Posted by Ken Williams <ke...@forum.swarthmore.edu>.
will@serensoft.com (will trillich) wrote:
> >    sub search {
> >        # ....
> >        {
> >            use CGI qw/:standard/;
> >            my	$form = join '',
> >                map {
> >                    hidden(
> >                        -name => $_,
> >                        -value => $arg->{$_},
> >                        ) . "\n"
> >                }
> >                grep(
> >                    $arg->{$_} and ($_ ne 'd') and ($_ ne 'go')
>
>as is, the functions that follow (top-level 'sub xyz {}') get
>screwy. code disappears.
>
>replace "and" with "&&" and all is well. boggles my mind.


Well, as far as I can tell, the original code doesn't even compile
because there aren't enough arguments to grep().  That's why I couldn't
test it.  I suppose changing the precedence helped things out.  Perhaps
you should use the more explicit BLOCK version:

            my $form = join '',
                map 
                  {
                    hidden(
                        -name => $_,
                        -value => $arg->{$_},
                        ) . "\n"
                  }
                grep 
                  {
                    $arg->{$_} and ($_ ne 'd') and ($_ ne 'go')
                  }
                keys %$arg;

>
>with 'and' *{$My::Debacle::{handler}}{CODE} doesn't exist.

That's an illusion.  The truth is that with 'and' the code is checking
something completely different, or not working at all.

This is turning out to be pretty well off-topic for the mod_perl list,
so we should cease.


  -------------------                            -------------------
  Ken Williams                             Last Bastion of Euclidity
  ken@forum.swarthmore.edu                            The Math Forum

Re: mod_perl subs defined, but don't exist? SOLVED mostly

Posted by will trillich <wi...@serensoft.com>.
On Thu, May 03, 2001 at 08:52:38PM -0500, Ken Williams wrote:
> I can't follow this test case.  Your previous message had a test case,
> but it was way too big.  Can you whittle this down into the smallest
> possible program that demonstrates something you don't understand, and
> post that?  My guess is that you'll figure out the problem in the
> process, but if not, post it here.

i found the culprit, but it's like finding out that a butterfly
burned down your house. i still don't see how it's possible.

when i distill it, of course, the problem vanishes. but see
below--

> By the way, I don't think you mean $My::Debacle::handler{CODE}.  If you
> look closely, you'll see that it's just a regular hash entry.  I think
> you mean *{$My::Debacle::{handler}}{CODE}.  That's the CODE component of
> a symbol table entry.

right. whoops. boy, that stuff gets deep, quick.

> If you have "Effective Perl Programming", look on page 239.

eagle book, camel book, but no "shiny ball book". yet. :)

> I know this stuff is hard to spot when you've been banging your head
> against it for days.  For that, I recommend "Zen and the Art of
> Motorcycle Maintenance".

a very good read, that.

> will@serensoft.com (will trillich) wrote:
> >okay, here was the problem.
> >
> >    package My::Debacle;
> >
> >    sub search {
> >        # ....
> >        {
> >            use CGI qw/:standard/;
> >            my	$form = join '',
> >                map {
> >                    hidden(
> >                        -name => $_,
> >                        -value => $arg->{$_},
> >                        ) . "\n"
> >                }
> >                grep(
> >                    $arg->{$_} and ($_ ne 'd') and ($_ ne 'go')

as is, the functions that follow (top-level 'sub xyz {}') get
screwy. code disappears.

replace "and" with "&&" and all is well. boggles my mind.

> >                , keys %$arg
> >                )
> >            ;
> >            # ....
> >        }
> >        # ....
> >    }
> >
> >    sub this { # ...
> >    }
> >    sub that { # ...
> >    }
> >    sub something_else { # ...
> >    }
> >    sub whatever_the_hell { # ...
> >    }
> >    sub handler { # ...
> >    }

with 'and' *{$My::Debacle::{handler}}{CODE} doesn't exist.

i've got a similar snag in a different module, now, where defined
subs are disappearing. but i can't trace it to a stray 'and'
here... must be something deeper?

-- 
will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!

Re: mod_perl subs defined, but don't exist? SOLVED mostly

Posted by Ken Williams <ke...@forum.swarthmore.edu>.
I can't follow this test case.  Your previous message had a test case,
but it was way too big.  Can you whittle this down into the smallest
possible program that demonstrates something you don't understand, and
post that?  My guess is that you'll figure out the problem in the
process, but if not, post it here.

By the way, I don't think you mean $My::Debacle::handler{CODE}.  If you
look closely, you'll see that it's just a regular hash entry.  I think
you mean *{$My::Debacle::{handler}}{CODE}.  That's the CODE component of
a symbol table entry.

If you have "Effective Perl Programming", look on page 239.

I know this stuff is hard to spot when you've been banging your head
against it for days.  For that, I recommend "Zen and the Art of
Motorcycle Maintenance".


will@serensoft.com (will trillich) wrote:
>okay, here was the problem.
>
>    package My::Debacle;
>
>    sub search {
>        # ....
>        {
>            use CGI qw/:standard/;
>            my	$form = join '',
>                map {
>                    hidden(
>                        -name => $_,
>                        -value => $arg->{$_},
>                        ) . "\n"
>                }
>                grep(
>                    $arg->{$_} and ($_ ne 'd') and ($_ ne 'go')
>                , keys %$arg
>                )
>            ;
>            # ....
>        }
>        # ....
>    }
>
>    sub this { # ...
>    }
>    sub that { # ...
>    }
>    sub something_else { # ...
>    }
>    sub whatever_the_hell { # ...
>    }
>    sub handler { # ...
>    }
>
>can you spot the problem?
>
>with that, poof! $My::Debacle::handler{CODE} doesn't exist.
>WHY?
>
>-- 
>will@serensoft.com
>http://sourceforge.net/projects/newbiedoc -- we need your brain!
>http://www.dontUthink.com/ -- your brain needs us!
>

  -------------------                            -------------------
  Ken Williams                             Last Bastion of Euclidity
  ken@forum.swarthmore.edu                            The Math Forum

Re: mod_perl subs defined, but don't exist? SOLVED mostly

Posted by will trillich <wi...@serensoft.com>.
On Thu, May 03, 2001 at 01:19:45AM -0500, will trillich wrote:
> On Thu, May 03, 2001 at 12:29:53AM -0500, will trillich wrote:
> > long version--
> > 
> > I have a subroutine that IS DEFINED, but it's not showing up as
> > defined. I used the *Symbol::Table::name{CODE} method myself and
> > sure enough, there's no CODE for the defined subroutine...
> 
> [snip]
> 
> > ANY wild-ass guesses would be appreciated.  (Do i win a prize for
> > the most difficulty with a simple situation? Or at least an
> > honorable mention for most belligerent refusal to move on and get
> > a life?)
> > 
> > ###########################################
> > 
> > short version--
> > 
> > WTF?
> 
> how can a defined subroutine NOT have any code in the symbol
> table? grr! this is quite a puzzle...

okay, here was the problem.

    package My::Debacle;

    sub search {
        # ....
        {
            use CGI qw/:standard/;
            my	$form = join '',
                map {
                    hidden(
                        -name => $_,
                        -value => $arg->{$_},
                        ) . "\n"
                }
                grep(
                    $arg->{$_} and ($_ ne 'd') and ($_ ne 'go')
                , keys %$arg
                )
            ;
            # ....
        }
        # ....
    }

    sub this { # ...
    }
    sub that { # ...
    }
    sub something_else { # ...
    }
    sub whatever_the_hell { # ...
    }
    sub handler { # ...
    }

can you spot the problem?

with that, poof! $My::Debacle::handler{CODE} doesn't exist.
WHY?

-- 
will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

Re: mod_perl subs defined, but DON'T EXIST? wtf?!

Posted by will trillich <wi...@serensoft.com>.
On Thu, May 03, 2001 at 12:29:53AM -0500, will trillich wrote:
> long version--
> 
> I have a subroutine that IS DEFINED, but it's not showing up as
> defined. I used the *Symbol::Table::name{CODE} method myself and
> sure enough, there's no CODE for the defined subroutine...

[snip]

> ANY wild-ass guesses would be appreciated.  (Do i win a prize for
> the most difficulty with a simple situation? Or at least an
> honorable mention for most belligerent refusal to move on and get
> a life?)
> 
> ###########################################
> 
> short version--
> 
> WTF?

how can a defined subroutine NOT have any code in the symbol
table? grr! this is quite a puzzle...

my version info is as follows, in case it's germane:

$ apache -v
Server version: Apache/1.3.9 (Unix) Debian/GNU
Server built:   Apr 30 2000 12:54:24

$ cat /etc/debian_version
2.2

$ perl -MTie::DBI -MCGI::Cookie -MMD5 -MLWP::Simple \
	-MApache::File -MApache::URI -MApache \
	-e 'print map {s/.pm$//;s%/%::%g;"$_ => ".${$_."::VERSION"}."\n"} sort keys %INC'
Apache => 1.26
Apache::Connection => 1.00
Apache::Constants => 1.09
Apache::Constants::Exports => 
Apache::File => 1.01
Apache::Server => 1.01
Apache::URI => 1.00
AutoLoader => 
CGI::Cookie => 1.20
CGI::Util => 1.2
Carp => 
DBI => 1.13
Digest::MD5 => 2.09
DynaLoader => 1.03
Exporter => 
Fcntl => 1.03
HTTP::Status => 1.26
LWP::Simple => 1.34
MD5 => 2.01
Tie::DBI => 0.91
mod_perl => 1.2103
overload => 
strict => 1.01
vars => 

-- 
will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!