my %page_control = ( edit => { product => { page => 'ps-main-product-edit.tmpl', function => \&edit_product }, }, default => { page => 'ps-main.tmpl', function => '' } ); # not worried about auto-vivification because false entries will go to defaults my ( $page, $function ); if ( $action and $type ) { $page = $page_control{ $action }{ $type }{ page }; $function = $page_control{ $action }{ $type }{ function }; } $page ||= $page_control{ default }{ page } my $permissions = $sec->get_permissions( $section ); if ( $action and $page =~ /^$secured/ ) { if ( exists $page_control{ $action } and exists $page_control{ $action }{ $permType } and ! $permissions->{ $type }{ $action } ) { my $article = $type =~ /^[aeiouAEIOU]/ ? 'an' : 'a'; $sec->force_logout( "$user tried to $action $article $type." ); } } # call correct function my ( $template_data, $new_page ) = $function->( $query, $db, $mod, $sec ) if defined $function and $function; $page = $new_page if defined $new_page and $new_page; $template->process( $page, $template_data ) or dienice $template->error();