QWizard::Storage::CGIParam - Stores data in CGI variables


QWizard documentation Contained in the QWizard distribution.

Index


Code Index:

NAME

Top

QWizard::Storage::CGIParam - Stores data in CGI variables

SYNOPSIS

Top

  my $st = new QWizard::Storage::CGIParam();
  $st->set('var', 'value');
  $st->get('var');

DESCRIPTION

Top

Stores data passed to it inside of CGI parameters.

AUTHOR

Top

Wes Hardaker, hardaker@users.sourceforge.net

SEE ALSO

Top

perl(1)

Net-Policy: http://net-policy.sourceforge.net/


QWizard documentation Contained in the QWizard distribution.

package QWizard::Storage::CGIParam;

use strict;
use QWizard::Storage::Base;
our @ISA = qw(QWizard::Storage::Base);

our $VERSION = '3.15';
use CGI;

our %cached_params = ();

sub new {
    my $class = shift;
    bless {}, $class;
}

sub maybe_create_cgi {
    my $self = shift;
    if (!exists($self->{'cgi'})) {
	# we do this here late binding as possible for various reasons
	$self->{'cgi'} = new CGI;
    }
}

sub get {
    my ($self, $it) = @_;
    $self->maybe_create_cgi();
    return $cached_params{$it} if (exists($cached_params{$it}));
    return $self->{'cgi'}->param($it);
}

sub set {
    my ($self, $it, $val) = @_;
    $self->maybe_create_cgi();
    return $self->{'cgi'}->param($it, $val);
}

sub get_all {
    my ($self) = @_;
    my %ret;
    my @names = $self->{'cgi'}->param;
    map { $ret{$_} = $self->{'cgi'}->param($_) } @names;
    return \%ret;
}

sub reset {
    my ($self) = @_;
    $self->maybe_create_cgi();
    $self->{'cgi'}->delete_all();
    %cached_params = (); 
}

1;