MrCBofBCinTX
Technical User
I saw a method I wanted to try under mod_perl.
Was in perl cookbook:
I adapted this technique to a mod_perl package
in sub handler
but
made ALL of the subroutines run.
I kept hash, but made change below and works fine.
I'm a little fuzzy this week because of some meds I'm going to stop taking. I'd like to understand why the first attempt failed in package?
Was in perl cookbook:
Code:
my %States; # state table mapping pages to functions
my $Current_Screen; # the current screen
croak "This CGI works only over HTTPS"
if $ENV{'SERVER_PORT'} && !$ENV{'HTTPS'};
# Since we deal with sensitive data like credit card numbers
# Hash of pages and functions.
%States = (
'Default' => \&front_page,
'Shirt' => \&shirt,
'Sweater' => \&sweater,
'Checkout' => \&checkout,
'Card' => \&credit_card,
'Order' => \&order,
'Cancel' => \&front_page,
);
$Current_Screen = param(".State") || "Default";
dmy %States; # state table mapping pages to functions
my $Current_Screen; # the current screen
croak "This CGI works only over HTTPS"
if $ENV{'SERVER_PORT'} && !$ENV{'HTTPS'};
# Since we deal with sensitive data like credit card numbers
# Hash of pages and functions.
%States = (
'Default' => \&front_page,
'Shirt' => \&shirt,
'Sweater' => \&sweater,
'Checkout' => \&checkout,
'Card' => \&credit_card,
'Order' => \&order,
'Cancel' => \&front_page,
);
$Current_Screen = param(".State") || "Default";
die "No screen for $Current_Screen" unless $States{$Current_Screen};
# Generate the current page.
standard_header( );
while (my($screen_name, $function) = each %States) {
$function->($screen_name eq $Current_Screen);
}
standard_footer( );
exit;ie "No screen for $Current_Screen" unless $States{$Current_Screen};
# Generate the current page.
standard_header( );
while (my($screen_name, $function) = each %States) {
$function->($screen_name eq $Current_Screen);
}
standard_footer( );
exit;
in sub handler
but
Code:
while (my($screen_name, $function) = each %States) {
$function->($screen_name eq $Current_Screen);
}
made ALL of the subroutines run.
I kept hash, but made change below and works fine.
Code:
sub handler
{
$r = shift;
my $dbh = dbi_con();
my $body_add = "";
($sessionID,$action) = init();
die "No screen for $action" unless $States{$action};
print_header();
print_action($top_page, $body, "", "");
#######
## Select a sub to return a body with results like from perl cookbook example?
$r->print("<p>$action</p>");
$States{$action}($dbh);## THIS WORKS JUST FINE
$r->print("<p>$action</p>");
print_action("", "", $body_add, $bottom_page);
return OK;
}
I'm a little fuzzy this week because of some meds I'm going to stop taking. I'd like to understand why the first attempt failed in package?