CGI-Application-Demo-Basic
view release on metacpan or search on metacpan
lib/CGI/Application/Demo/Basic.pm view on Meta::CPAN
{
require "$file.pm";
$cdbi_class -> import;
};
die "CGI::Application::Demo::Basic::setup_db_interface: Couldn't require class: $cdbi_class: $@" if ($@);
}
push @$classes, $cdbi_class;
}
}
elsif (ref($parameter) =~ /^Class::DBI::Loader/)
{
push @$classes, $_ for $parameter -> classes;
}
else
{
my($ref) = ref($parameter);
die "CGI::Application::Demo::Basic::setup_db_interface: Invalid parameter\nParameter must either be an array reference of Class::DBI classes or a Class::DBI::Loader object\nYou gave me a $ref object.";
}
$self -> param(cgi_app_demo_classes => $classes);
my($tables) = {};
for my $cdbi_class (@{$self -> param('cgi_app_demo_classes')})
{
my($table) = $cdbi_class -> table;
$$tables{$table} = $cdbi_class;
}
$self -> param(cgi_app_demo_tables => $tables);
} # End of setup_db_interface.
# -----------------------------------------------
sub start
{
my($self) = shift;
my($config) = $self -> param('config');
my($submit) = $self -> query -> param('submit') || '';
my($template) = $self -> load_tmpl($$config{'tmpl_name'});
my($content) = $self -> build_basic_pane($submit) . $self -> build_options_pane($submit);
$template -> param(content => $content);
$template -> param(css_url => $self -> param('css_url') );
$template -> param(rm => $self -> query -> param('rm') );
$template -> param(sid => $self -> session -> id);
$template -> param(title => $self -> param('title') );
$template -> param(url => $self -> query -> url . $self -> query -> path_info);
return $template -> output;
} # End of start.
# -----------------------------------------------
sub update_options
{
my($self) = @_;
my(@key) = keys %{${$self -> param('key')}{'option'} };
$self -> log -> info('Called update_options');
my($value, $default, $minimum, $maximum);
for (@key)
{
$default = ${$self -> param('key')}{'option'}{$_}{'default'};
$minimum = ${$self -> param('key')}{'option'}{$_}{'minimum'};
$maximum = ${$self -> param('key')}{'option'}{$_}{'maximum'};
$value = $self -> query -> param($_);
$value = $default if (! defined($value) || ($value < $minimum) || ($value > $maximum) );
$self -> param($_ => $value);
$self -> session -> param($_ => $value);
}
return $self -> start;
} # End of update_options.
# -----------------------------------------------
1;
__END__
=head1 NAME
C<CGI::Application::Demo::Basic> - A vehicle to showcase C<CGI::Application>
=head1 Synopsis
basic.cgi:
#!/usr/bin/perl
use strict;
use warnings;
use CGI::Application::Demo::Basic;
# -----------------------------------------------
delete @ENV{'BASH_ENV', 'CDPATH', 'ENV', 'IFS', 'PATH', 'SHELL'}; # For security.
CGI::Application::Demo::Basic -> new -> run;
=head1 Description
C<CGI::Application::Demo::Basic> showcases C<CGI::Application>-based applications, via these components:
=over 4
=item o A set of 7 CGI instance scripts
=item o A set of 4 text configuration files
( run in 0.659 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )