#!/usr/bin/perl -wT use strict; use warnings; use CGI; use CGI::Session; use CustomObject; my $cgi = new CGI; my $session = new CGI::Session("driver:File", $cgi, {Directory => "/tmp"}); print $cgi->header(-type => "text/html", -charset => "utf-8"), $cgi->start_html("Session management"); # Initialize session object. unless ($session->param("custom_object")) { my $customObject = new CustomObject("test_login", "test_password"); $session->param("custom_object", $customObject); print $cgi->p("Custom object initialized"); } my $customObject = $session->param("custom_object"); print $cgi->p("Login: " . $customObject->login()), $cgi->p("Password: " . $customObject->password()), $cgi->end_html(); #### package CustomObject; sub login { my $self = shift; return $self->{LOGIN}; } sub new { my ($className, $login, $password) = @_; my $self = bless { LOGIN => $login, PASSWORD => $password }, $className; return $self; } sub password { my $self = shift; return $self->{PASSWORD}; } 1;