[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GT] Storable
Hi everybody,
I did a lot of various backtesting in the last weeks. I had two
problems: The files in which I saves the portfolio consume a lot of
space and they are not human-readable; this makes debugging and
processing by external programs harder and I don#t know if I can read
the files after a change in the Storable-module.
I therefore extended the Storable.pm by adding an interface to
XML::Dumper. By compressing the xml-files the size of file is 30% of
the original one and I can read and modify them.
The patch is just for your personal information; I think we should
not include it in GT because it is one more module that the user has
to provide and the code is'nt nice at all...
CU, Olf
---
Visit my world: http://www.olfsworld.de
--- GT/Serializer/Storable.pm Sun Oct 6 17:39:27 2002
+++ ../GT/Serializer/Storable.pm Thu Jan 29 17:16:47 2004
@@ -10,6 +10,9 @@
@ISA = qw(GT::Serializer);
use GT::Serializer;
+use GT::Conf;
+use XML::Dumper;
+use Compress::Zlib;
use Storable;
=head1 GT::Serializer::Storable
@@ -20,12 +23,48 @@
sub default_store {
my ($self, $file, $object) = @_;
- store $object, $file;
+
+ GT::Conf::default("Storable", "xmlasdf.gz");
+ $self->{'type'} = GT::Conf::get("Storable");
+ $self->{'dump'} = new XML::Dumper if ($self->{'type'} =~ "xml.gz");
+
+ if ($self->{'type'} =~ /^xml$/) {
+ $self->{'dump'}->pl2xml( $object, $file );
+ } elsif ($self->{'type'} =~ /xml\.gz/) {
+ my $xml = $self->{'dump'}->pl2xml( $object );
+ open OUT, ">$file" or warn "Could not write to file $file";
+ my $buffer = Compress::Zlib::memGzip( $xml );
+ print OUT $buffer;
+ close OUT;
+ } else {
+ store $object, $file;
+ }
}
sub default_load {
my ($self, $file) = @_;
- return retrieve $file;
+
+ GT::Conf::default("Storable", "xml.gz");
+ $self->{'type'} = GT::Conf::get("Storable");
+ $self->{'dump'} = new XML::Dumper if ($self->{'type'} =~ "xml.gz");
+
+ my $ret;
+ if ($self->{'type'} =~ /xml/) {
+ $ret = $self->{'dump'}->xml2pl( $file );
+ } elsif ($self->{'type'} =~ /xml\.gz/) {
+ my $buffer ;
+ my $subbuffer ;
+ my $gz = gzopen($file, "rb")
+ or warn "Cannot open $file: $gzerrno\n" ;
+ $buffer .= $subbuffer while $gz->gzread($buffer) > 0 ;
+ warn "Error reading from $file: $gzerrno" . ($gzerrno+0) . "\n"
+ if $gzerrno != Z_STREAM_END ;
+ $gz->gzclose() ;
+ $ret = $self->{'dump'}->xml2pl( $buffer );
+ } else {
+ $ret = retrieve $file;
+ }
+ return $ret;
}
=head2