Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cgi doesn't work under mod_perl

Status
Not open for further replies.

MrCBofBCinTX

Technical User
Dec 24, 2003
164
0
0
US
I saw a method I wanted to try under mod_perl.
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;
I adapted this technique to a mod_perl package
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?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top