Boulder-Simple
view release on metacpan or search on metacpan
lib/Boulder/Simple.pm view on Meta::CPAN
my @vals = ref($rec->{$param}) eq 'ARRAY' ?
@{$rec->{$param}} : ( $rec->{$param} );
my $v;
foreach $v (@vals) {
print $filehandle "$escaped_param=",escape("$v"),"\n";
}
}
print $filehandle "=\n";
}
}
sub load_as_query {
my @lines = load(@_);
return undef unless @lines;
"@lines" =~ /=/ ? join("&",@lines) : join("+",@lines);
}
sub load_as_hash {
my @lines = load(@_);
return undef unless @lines;
my %hash;
foreach (@lines) {
my($key,$value)=split /=/, $_, 2;
next unless $key;
$value = unescape($value);
unless (exists($hash{$key})) {
$hash{$key} = $value;
next;
}
if (ref($hash{$key}) eq 'ARRAY') {
push(@{$hash{$key}},$value);
} else {
$hash{$key} = [ $hash{$key}, $value ];
}
}
\%hash;
}
sub load {
my($class,$filehandle) = @_;
my @lines;
if (defined($filehandle) && ($filehandle ne '')) {
while (<$filehandle>) {
chomp;
last if /^=/;
push(@lines,$_);
}
}
@lines;
}
# Borrowed from CGI so we don't have to load that package if
# we don't need to. Turns a string into a filehandle.
sub to_filehandle {
my $thingy = shift;
return undef unless $thingy;
return $thingy if UNIVERSAL::isa($thingy,'GLOB');
return $thingy if UNIVERSAL::isa($thingy,'FileHandle');
if (!ref($thingy)) {
my $caller = 1;
while (my $package = caller($caller++)) {
my($tmp) = $thingy=~/[\':]/ ? $thingy : "$package\:\:$thingy";
return $tmp if defined(fileno($tmp));
}
}
return undef;
}
1;
__END__
=begin
=head1 NAME
Boulder::Simple - a class for simple Boulder IO interaction.
DEPRECATED. Use Boulder::Util instead.
=head1 SYNOPSIS
#!/usr/bin/perl -w
use strict;
use Boulder::Simple;
my $file ='boulder.txt';
my $data = {
vocals => ['frank', 'kim'],
guitar => ['frank', 'joey'],
bass => 'kim',
drums => 'david'
};
my $fh;
open ($fh,">$file");
Boulder::Simple->save($fh,$data);
close $fh;
my $fh2;
open ($fh2,"$file");
while(my $q = Boulder::Simple->load_as_query($fh2)) {
print "$q\n";
}
close $fh2;
=head1 DESCRIPTION
Boulder::Simple is a simple lightweight class for manipulating
Boulder IO records. DEPRECATED. Use Boulder::Util instead.
Boulder IO is the native format output by the CGI package's C<save>
method. While working on a project I used that method to serialize
the state of a query for later use. That later use did not involve
a CGI request though. I wanted to avoid loading up the CGI package
just to read in the file memory and the L<Boulder> package itself
seemed like a bit much. What I wished I had was a quick way of
reading those records without incurring the overhead of either
package. Hence Boulder::Simple.
( run in 1.563 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )