NAME
CGI::Pure::Save - Common Gateway Interface Class for loading/saving object in file.
SYNOPSIS
use CGI::Pure::Save;
my $cgi = CGI::Pure::Save->new(%parameters);
$cgi->save($fh);
$cgi->load($fh);
METHODS
new(%parameters)
-
Constructor
cgi_pure
CGI::Pure object.
load($fh)
-
Load parameters from file. Return undef.
save($fh)
-
Save parameters to file. Return undef.
ERRORS
new():
CGI::Pure object doesn't define.
From Class::Utils::set_params():
Unknown parameter '%s'.
load()
Invalid filehandle.
save()
Invalid filehandle.
EXAMPLE1
use strict;
use warnings;
use CGI::Pure;
use CGI::Pure::Save;
use File::Temp qw(tempfile);
use Perl6::Slurp qw(slurp);
# Temporary file.
my ($tempfile_fh, $tempfile) = tempfile();
# Query string.
my $query_string = 'par1=val1;par1=val2;par2=value';
# CGI::Pure Object.
my $cgi = CGI::Pure->new(
'init' => $query_string,
);
# CGI::Pure::Save object.
my $save = CGI::Pure::Save->new(
'cgi_pure' => $cgi,
);
# Save.
$save->save($tempfile_fh);
close $tempfile_fh;
# Print file.
print slurp($tempfile);
# Clean temp file.
unlink $tempfile;
# Output:
# par1=val1
# par1=val2
# par2=value
# =
EXAMPLE2
use strict;
use warnings;
use CGI::Pure;
use CGI::Pure::Save;
use IO::Barf qw(barf);
use File::Temp qw(tempfile);
use File::Slurp qw(write_file);
# Temporary file.
my ($tempfile_fh, $tempfile) = tempfile();
# CGI::Pure data.
my $cgi_pure_data = <<'END';
par1=val1
par1=val2
par2=value
=
END
# Create file.
barf($tempfile_fh, $cgi_pure_data);
close $tempfile_fh;
# CGI::Pure Object.
my $cgi = CGI::Pure->new;
# CGI::Pure::Save object.
my $save = CGI::Pure::Save->new(
'cgi_pure' => $cgi,
);
# Load.
open $tempfile_fh, '<', $tempfile;
$save->load($tempfile_fh);
close $tempfile_fh;
# Print out.
foreach my $param_key ($cgi->param) {
print "Param '$param_key': ".join(' ', $cgi->param($param_key))."\n";
}
# Clean temp file.
unlink $tempfile;
# Output:
# Param 'par1': val1 val2
# Param 'par2': value
DEPENDENCIES
Class::Utils, English, Error::Pure, Readonly, URI::Escape.
SEE ALSO
- CGI::Pure
-
Common Gateway Interface Class.
- CGI::Pure::Fast
-
Fast Common Gateway Interface Class for CGI::Pure.
AUTHOR
Michal Josef Špaček mailto:skim@cpan.org
LICENSE AND COPYRIGHT
© 2004-2021 Michal Josef Špaček
BSD 2-Clause License
VERSION
0.09