--- nfo/perl/libs/Data/Storage/Handler/File.pm 2003/02/11 05:15:45 1.4 +++ nfo/perl/libs/Data/Storage/Handler/File.pm 2003/02/18 19:18:50 1.5 @@ -1,9 +1,15 @@ #!/usr/bin/perl ## ------------------------------------------------------------------------ -## $Id: File.pm,v 1.4 2003/02/11 05:15:45 joko Exp $ +## $Id: File.pm,v 1.5 2003/02/18 19:18:50 joko Exp $ ## ------------------------------------------------------------------------ ## $Log: File.pm,v $ +## Revision 1.5 2003/02/18 19:18:50 joko +## + sub constructor +## + sub _stat +## + sub _exists +## +- rename key +## ## Revision 1.4 2003/02/11 05:15:45 joko ## - no Exporter any more ## @@ -24,10 +30,30 @@ use Data::Storage::Handler::File::Basic qw( s2f a2f f2s ); +sub constructor { + my $self = shift; + # patch - backward compatibility + if (!$self->{filename} && $self->{path}) { + $self->{filename} = $self->{path}; + } +} + +sub _stat { + my $self = shift; + if (-e $self->{filename}) { + $self->{_meta}->{exists} = 1; + } else { + $self->{_meta}->{exists} = 0; + } +} + sub _read { my $self = shift; - $self->{_buffer_orig} = f2s($self->{path}); - $self->{_buffer} = f2s($self->{path}); + $self->_stat(); + if ($self->exists()) { + $self->{_buffer} = f2s($self->{filename}); + } + #$self->{_buffer_orig} = f2s($self->{filename}); } sub toString { @@ -39,22 +65,22 @@ sub addSuffix { my $self = shift; my $suffix = shift; - $self->{path} .= ".$suffix"; + $self->{filename} .= ".$suffix"; } sub save { my $self = shift; if ($self->{_buffer}) { - s2f($self->{path}, $self->{_buffer}); + s2f($self->{filename}, $self->{_buffer}); } else { - print "please load $self->{path} before saving.", "\n"; + print "please load $self->{filename} before saving.", "\n"; } } sub backup { my $self = shift; my $options = shift; - my $path = $self->{path}; + my $path = $self->{filename}; $path .= '.' . $options->{suffix} if $options->{suffix}; s2f($path, $self->{_buffer_orig}); } @@ -67,5 +93,11 @@ if (eval($eval)) { return 1; } } +sub exists { + my $self = shift; + $self->_stat(); + return $self->{_meta}->{exists}; +} + 1; __END__