CGI-Framework

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

	  introduced new method finalize()

0.13
	- Implemented new constructor parameter: expire
	- log_this now also logs the IP address from REMOTE_ADDR
	- Internal HTML::Template object is now initialized with option
	  loop_context_vars, allowing for loop vars such as __odd__
	  and __inner__

0.12
	- Implemented support for 4 new callbacks:
	    pre__pre__all()
	    post__pre__all()
	    pre__post__all()
	    post__post__all()

0.11
	- Implemented new method: return_template()
	- Implemented 2 new special variables: _missing_info and
	  _missing_info_caller
   - Calling the clear_session() method will now preserve

Changes  view on Meta::CPAN

	- add_error() method no longer restricted to being called from inside a
	  validate_templatename() routine.  That gives the flexibility to add_error()
	  followed by manually calling show_template() at any time.
	- The INITIALIZENEWPROJECT function now creates an /images/ subdirectory
	  inside the /public_html/ subdirectory and places a couple of small images in
	  it, which the errors.html template references. It looks nicer :)

0.05
	- Fixed a bug that caused the framework not to call the pre_templatename and
	  validate_templatename subroutines if the non-OOP (function-based) approach using
	  the initialize_cgi_framework initializer was used, and the callbacks_namespace
	  parameter was not supplied.

0.04
	- Any methods and initializer parameters that were made up of 2 concatenated words
	  have now been separated by an underscore.  The following are affected:

	  Methods/Functions:
	  adderror		=>	add_error
	  clearsession	=> clear_session
	  showtemplate	=> show_template

	  Constructor/Initializer parameters:
	  callbacksnamespace	=>	callbacks_namespace
	  cookiename			=>	cookie_name
	  initialtemplate		=>	initial_template
	  sessionsdir			=>	sessions_dir
	  templatesdir			=>	templates_dir
	  validlanguages		=>	valid_languages

	  The old names will still be available for compatability-purposes however will be
	  phased out sometime in the future for code-cleanliness.  All existing and new
	  programs should use the new naming convention.

lib/CGI/Framework.pm  view on Meta::CPAN

This is the standard object-oriented constructor.  When called, will return a new CGI::Framework instance.  It accepts a hash (or a hashref) with the following keys:

=over 4

=item action

B<OPTIONAL>

If this key is supplied, it should contain the value to be used in the <form> HTML element's "action" parameter.  If not supplied, it will default to environment variable SCRIPT_NAME

=item callbacks_namespace

B<OPTIONAL>

This key should have a scalar value with the name of the namespace that you will put all the validate_templatename(), pre_templatename(), post_templatename(), pre__pre__all(), post__pre__all(), pre__post__all() and post__post__all() subroutines in.  ...

The main use of this option is to allow you, if you so choose, to place your callbacks subs into any arbitrary namespace you decide on (to avoid pollution of your main namespace for example).

=item cookie_domain
   
B<OPTIONAL>
	   
The key should have a scalar value with the domain that cookie_name is set to.  If not supplied the cookie will not be assigned to a specific domain, essentially making tied to the current hostname.

=item cookie_name

B<OPTIONAL>

lib/CGI/Framework.pm  view on Meta::CPAN


			#
			# Otherwise we validate the template they're submitting
			#
			$validate_template = $self->form("_template");
		}

		#
		# We implement validation if possible
		#
		if ($validate_template && defined &{"$self->{callbacks_namespace}::validate_$validate_template"}) {
			&{"$self->{callbacks_namespace}::validate_$validate_template"}($self);
			if ($self->{_html}->{_errors}) {

				#
				# The validation didn't go so well and errors were recorded
				# so we re-show the template the failed validation
				#
				$self->show_template($validate_template);
			}
		}
	}

lib/CGI/Framework.pm  view on Meta::CPAN

	my $self = _getself(\@_);
	my $initial_template = shift || croak "initial template not supplied";
	$self->{initial_template} = $initial_template;
}

#
# An alias to new(), to be used in nooop mode
#
sub initialize_cgi_framework {
	my %para = ref($_[0]) eq "HASH" ? %{ $_[0] } : @_;
	$para{callbacks_namespace} ||= (caller)[0] || "main";
	return new("CGI::Framework", \%para);
}

#
# The constructor.  Initializes pretty much everything, returns a new bless()ed instance
#
sub new {
	my $class = shift || "CGI::Framework";
	my %para = ref($_[0]) eq "HASH" ? %{ $_[0] } : @_;
	my $self = {};

lib/CGI/Framework.pm  view on Meta::CPAN

	#
	# Paranoia: It should be clear anyways... but
	#
	if ($LASTINSTANCE) {
		$LASTINSTANCE->finalize();
	}

	#
	# Backwards compatability support
	#
	foreach (qw(callbacks_namespace cookie_name import_form initial_template sessions_dir templates_dir valid_languages)) {
		$temp = $_;
		$temp =~ s/_//g;
		if (!exists $para{$_} && exists $para{$temp}) {
			$para{$_} = $para{$temp};
			delete $para{$temp};
		}
	}

	#
	# Custom fatal error handling

lib/CGI/Framework.pm  view on Meta::CPAN


	#
	# Some initial setup
	#
	$para{_html} = {};

	#
	# We set some defaults if unsupplied
	#
	$para{valid_languages} ||= [];
	$para{callbacks_namespace} ||= (caller)[0] || "main";
	if (!$para{cookie_name}) {
		$para{cookie_name} = "sessionid_$ENV{SCRIPT_NAME}";
		$para{cookie_name} =~ s/[^0-9a-z]//gi;
	}
	if (!$para{sessions_mysql_dbh} && !$para{sessions_dir}) {

		#
		# They didn't supply any sessions stuff, so let's take a guess at some directories for file-based storage:
		#
		foreach (qw(/tmp /var/tmp c:/tmp c:/temp c:/windows/temp)) {

lib/CGI/Framework.pm  view on Meta::CPAN

		open(FH, ">>$para{log_filename}") || croak "Log filename $para{log_filename} is not writeable by me: $@";
		close(FH);
	}
	if ($para{output_filter}) {
		if (ref($para{output_filter}) eq "CODE") {

			#
			# It's a code ref - good
			#
		}
		elsif (defined &{"$self->{callbacks_namespace}::$para{output_filter}"}) {

			#
			# It's a sub name that exists. good
			#
			$para{output_filter} = &{"$self->{callbacks_namespace}::$para{output_filter}"};
		}
		else {
			croak "Output filter not a code ref and not a sub name that I can find";
		}
	}

	#
	# And now some initialization
	#
	$self->{action}              = $para{action};
	$self->{valid_languages}     = $para{valid_languages};
	$self->{templates_dir}       = $para{templates_dir};
	$self->{initial_template}    = $para{initial_template};
	$self->{callbacks_namespace} = $para{callbacks_namespace};
	$self->{log_filename}        = $para{log_filename};
	$self->{disable_back_button} = $para{disable_back_button};
	$self->{output_filter}       = $para{output_filter};
	$self->{_cgi}                = new CGI || die "Failed to create a new CGI instance: $! $@\n";
	$cookie_value = $self->{_cgi}->cookie($para{cookie_name}) || undef;

	if ($para{"maketext_class_name"}) {
		undef $@;
		eval { eval("require $para{'maketext_class_name'};") || die "Failed to require() $para{'maketext_class_name'}: $! $@"; };
		if ($@) {

lib/CGI/Framework.pm  view on Meta::CPAN

#
sub show_template {
	my $self          = _getself(\@_);
	my $template_name = shift || croak "Template name not supplied";
	my $nofinalize    = shift;
	my $content;
	my $content_type;

	no strict 'refs';

	if (defined &{"$self->{callbacks_namespace}::pre__pre__all"}) {

		#
		# Execute a pre__pre__all
		#
		&{"$self->{callbacks_namespace}::pre__pre__all"}($self, $template_name);
	}

	if (defined &{"$self->{callbacks_namespace}::pre_$template_name"}) {

		#
		# Execute a pre_ for this template
		#
		&{"$self->{callbacks_namespace}::pre_$template_name"}($self, $template_name);
	}

	if (defined &{"$self->{callbacks_namespace}::post__pre__all"}) {

		#
		# Execute a post__pre__all
		#
		&{"$self->{callbacks_namespace}::post__pre__all"}($self, $template_name);
	}

	#
	# Parse template
	#
	($content, $content_type) = $self->return_template($template_name);

	#
	# Implement outbound filter
	#

lib/CGI/Framework.pm  view on Meta::CPAN

	print "Content-type: $content_type\n";
	if ($self->{disable_back_button}) {
		print "Cache-control: no-cache\n";
		print "Pragma: no-cache\n";
		print "Expires: Thu, 01 Dec 1994 16:00:00 GMT\n";
	}
	print "\n";
	print $content;
	$self->session("_lastsent", $template_name);

	if (defined &{"$self->{callbacks_namespace}::pre__post__all"}) {

		#
		# Execute a pre__post__all
		#
		&{"$self->{callbacks_namespace}::pre__post__all"}($self, $template_name);
	}

	if (defined &{"$self->{callbacks_namespace}::post_$template_name"}) {

		#
		# Execute a post_ for this template
		#
		&{"$self->{callbacks_namespace}::post_$template_name"}($self);
	}

	if (defined &{"$self->{callbacks_namespace}::post__post__all"}) {

		#
		# Execute a post__post__all
		#
		&{"$self->{callbacks_namespace}::post__post__all"}($self, $template_name);
	}

	if (!$nofinalize) {
		$self->finalize();
	}

}

#
# This sub takes whatever's passed to it and



( run in 0.354 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )