You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Влад Сафронов <vl...@immo.ru> on 2003/07/21 13:31:04 UTC

Question to mod_perl gurus. Take 1 minute. Just choose right answer from list!

Hi, 

recently I got in trouble with old Apache::ePerl module 
(I know there a lot of better html toolkits, but this one is suits for
my WAP-related tasks)

so the question:
we have package, handler for *.perl-embed files

package Apache::ePerl;
use vars qw ($Cache);

$Cache = {};

sub handler {
    my ($r) = @_;
    my ($filename, $func);

    send some content type header

    if (CALL_SCRIPT_1) {
	# if not precompiled yet
      if (!$Cache{SCRIPT_1}) {
    		eval { $func = sub { package Apache::ePerlCache;
<SCRIPT_1> }; }
		$Cache{SCRIPT_1} = $func;
	} else {
		$func = $Cache{SCRIPT_1};
	}
	eval &{$func};
    } elsif (EVAL_SCRIPT_2) {
	# if not precompiled
      if (!$Cache{SCRIPT_2}) {
    		eval { $func = sub { package Apache::ePerlCache;
<SCRIPT_2> }; }
		$Cache{SCRIPT_2} = $func;
	} else {
		$func = $Cache{SCRIPT_2};
	}
	eval &{$func};	
    }
    return OK;
}

=== SCRIPT_1

print "some header"
# the main code
main_deck();

sub main_deck {
	print "Hi, it's SCRIPT_1!";
}

=end

=== SCRIPT_2

print "some header"
# the main code
main_deck();

# the same name!
sub main_deck {
	print "Bye, it was SCRIPT_2!";
}

=end


now we call:

CALL_SCRIPT_1
CALL_SCRIPT_2

got all scripts in Cache:
and now call

CALL_SCRIPT_1 again

so the question:
which sub "main_deck" will be executed?

1. Hi, it's SCRIPT_1!
2. Bye, it was SCRIPT_2!

-vlad



Re: Question to mod_perl gurus. Take 1 minute. Just choose right answer from list!

Posted by Perrin Harkins <pe...@elem.com>.
On Mon, 2003-07-21 at 07:31, Влад Сафронов wrote:
> so the question:
> which sub "main_deck" will be executed?
> 
> 1. Hi, it's SCRIPT_1!
> 2. Bye, it was SCRIPT_2!

I think #2, because it was the last one eval'ed, and you can only have
one sub with a given name in one package namespace.  Apache::ePerl does
not really support the use of in-line subs.  You have to put them in a
separate module.

- Perrin