package Pos::Webtop::Web::IndividualSignup; use strict; use HTML::Entities (); use CGI (); sub new { # In a perl object constructor, the first parameter to the function call # is the name of the class, or a reference to an already existing object. # In our case, it's going to always be either a reference to an existing IndividualSignup # object, or the string "Pos::Webtop::Web::IndividualSignup". my $this = shift; # Get the class name (perl package name) of the first parameter, or treat the first # parameter AS the class name. my $class = ref($this) || $this; # class is now "Pos::Webtop::Web::IndividualSignup" if this class is instantiated directly. # Now we need to bring our object to life by blessing our data storage area as a new object # of type $class. For data storage, we will use a hash. my $self = {}; bless($self,$class); # get rest of args out my ($customerId) = @{{@_}}{qw/customerId/}; # setup our data $self->{'customerId'} = $customerId; $self->{'getPageHeaderHandler'} = \&defaultGetPageHeaderHandler; $self->{'getPageFooterHandler'} = \&defaultGetPageFooterHandler; # last thing object constructor does is return the new blessed reference # (otherwise known as instantiated object) return $self; } # getter and setter for customerId sub getCustomerId { my $self = shift; return $self->{'customerId'}; } sub setCustomerId { my $self = shift; my ($customerId) = @{{@_}}{qw/customerId/}; $self->{'customerId'} = $customerId; } # setters for setting the page footer and header handlers sub setGetPageHeaderHandler { my $self = shift; my ($handler) = @{{@_}}{qw/handler/}; $self->{'getPageHeaderHandler'} = $handler; } sub setGetPageFooterHandler { my $self = shift; my ($handler) = @{{@_}}{qw/handler/}; $self->{'getPageFooterHandler'} = $handler; } sub defaultGetPageHeaderHandler { my ($title) = @{{@_}}{qw/title/}; my $ret = ""; $ret .= "Content-type: text/html\n\n " . HTML::Entities::encode($title) . " "; } sub defaultGetPageFooterHandler { return " "; } # print $signup->getPageHeader( title=> "bob" ); sub getPageHeader { my $self = shift; my $handler = $self->{'getPageHeaderHandler'}; return $handler->( @_ ); } sub getPageFooter { my $self = shift; my $handler = $self->{'getPageFooterHandler'}; return $handler->( @_ ); } # MAIN LINE CGI CALLED FROM EACH .PL FILE sub main { my $self = shift; my $cgi = CGI->new(); if ( $cgi->param('submit') ) { print $self->getPageHeader( title=> "Testing SUBMIT PAGE" ); print "SUBMIT PAGE"; print $self->getPageFooter(); } else { # default page print $self->getPageHeader( title=> "Testing DEFAULT PAGE" ); print "DEFAULT PAGE"; print $self->getPageFooter(); } } 1;