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


  • ... Влад Сафронов
    • ... Perrin Harkins

Reply via email to