Junco Code - DisplayPageOOHash.pm - old style hash version #juncocode #objectoriented code=yes ####### # test perl script #!/usr/bin/perl -wT use strict; $|++; use lib 'Kestrel/lib'; use Kestrel::DisplayPageOOHash; print "hello\n"; my %hash; $hash{function} = "riding the horse"; # DisplayPageOOHash->do_invalid_function(\%hash); # DisplayPageOOHash->report_error("user", "testing", "debug"); my $a = DisplayPageOOHash->new("test"); $a->set_template_variable("hello", "first message"); $a->set_template_variable("world", "second message"); $a->display_page(); ########################## package DisplayPageOOHash; use strict; use warnings; use NEXT; { $CGI::HEADERS_ONCE=1; use HTML::Template; use Config::Config; use Kestrel::Modules; use Kestrel::User; sub new { my ($class, $template_name) = @_; my $self = { TMPL => undef }; my $kestrel_th = Config::get_value_for("template_home"); $ENV{HTML_TEMPLATE_ROOT} = $kestrel_th; $self->{TMPL} = HTML::Template->new(filename => "$kestrel_th/$template_name.tmpl"); bless($self, $class); return $self; } sub set_template_variable { my ($self, $var_name, $var_value) = @_; $self->{TMPL}->param("$var_name" => $var_value); } sub set_template_loop_data { my ($self, $loop_name, $loop_data) = @_; $self->{TMPL}->param("$loop_name" => $loop_data); } sub display_page { my ($self, $function) = @_; my @http_header = ("Content-type: text/html;\n\n", ""); my $http_header_var = 0; print $http_header[$http_header_var]; __set_template_variable($self, "home_page", Config::get_value_for("home_page")); __set_template_variable($self, "loggedin", User::get_logged_in_flag()); __set_template_variable($self, "username", User::get_logged_in_username()); __set_template_variable($self, "cgi_app", Config::get_value_for("cgi_app")); __set_template_variable($self, "site_name", Config::get_value_for("site_name")); print $self->{TMPL}->output; exit; } sub do_invalid_function { my ($self, $tmp_hash) = @_; my $function = $tmp_hash->{function}; $self->report_error("user", "Invalid function: $function", "It's not supported."); } sub report_error { my ($self, $type, $cusmsg, $sysmsg) = @_; my $o = $self->new("$type" . "error"); $o->set_template_variable("cusmsg", "$cusmsg"); if ( $type eq "user" ) { $o->set_template_variable("sysmsg", "$sysmsg"); } elsif ( ($type eq "system") and Config::get_value_for("debug_mode") ) { $o->set_template_variable("sysmsg", "$sysmsg"); } $o->set_template_variable("referer", Utils::get_http_referer()); $o->display_page("Error"); exit; } sub DESTROY { my ($self) = @_; $self->EVERY::__destroy; } ##### private routines sub __destroy { my ($self) = @_; delete $self->{TMPL}; } sub __set_template_variable { my ($self, $var_name, $var_value) = @_; $self->{TMPL}->param("$var_name" => $var_value); } } 1;