Skip to content
Snippets Groups Projects
Commit 8dd423fb authored by Patrick Meidl's avatar Patrick Meidl
Browse files

added autoload capabilities

parent 989f9356
No related branches found
No related tags found
No related merge requests found
......@@ -43,7 +43,8 @@ sub new {
my $caller = shift;
my $class = ref($caller) || $caller;
my ($dump_path, $cache_file) = rearrange([qw(DUMP_PATH CACHE_FILE)], @_);
my ($dump_path, $cache_file, $auto_load) =
rearrange([qw(DUMP_PATH CACHE_FILE AUTO_LOAD)], @_);
throw("You must provide a cache file name") unless ($cache_file);
......@@ -55,6 +56,14 @@ sub new {
$self->{'cache_file'} = $self->dump_path."/$cache_file";
$self->{'cache_file_name'} = $cache_file;
# automatically load serialised object from file if requested
if ($auto_load) {
if (-s $self->cache_file) {
$self->read_from_file;
$self->{'loaded'} = 1;
}
}
return $self;
}
......@@ -125,5 +134,12 @@ sub cache_file_name {
}
sub loaded {
my $self = shift;
$self->{'loaded'} = shift if (@_);
return $self->{'loaded'};
}
1;
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment