4 |
## $Id$ |
## $Id$ |
5 |
## ------------------------------------------------------------------------ |
## ------------------------------------------------------------------------ |
6 |
## $Log$ |
## $Log$ |
7 |
|
## Revision 1.5 2003/02/18 19:18:50 joko |
8 |
|
## + sub constructor |
9 |
|
## + sub _stat |
10 |
|
## + sub _exists |
11 |
|
## +- rename key |
12 |
|
## |
13 |
## Revision 1.4 2003/02/11 05:15:45 joko |
## Revision 1.4 2003/02/11 05:15:45 joko |
14 |
## - no Exporter any more |
## - no Exporter any more |
15 |
## |
## |
30 |
|
|
31 |
use Data::Storage::Handler::File::Basic qw( s2f a2f f2s ); |
use Data::Storage::Handler::File::Basic qw( s2f a2f f2s ); |
32 |
|
|
33 |
|
sub constructor { |
34 |
|
my $self = shift; |
35 |
|
# patch - backward compatibility |
36 |
|
if (!$self->{filename} && $self->{path}) { |
37 |
|
$self->{filename} = $self->{path}; |
38 |
|
} |
39 |
|
} |
40 |
|
|
41 |
|
sub _stat { |
42 |
|
my $self = shift; |
43 |
|
if (-e $self->{filename}) { |
44 |
|
$self->{_meta}->{exists} = 1; |
45 |
|
} else { |
46 |
|
$self->{_meta}->{exists} = 0; |
47 |
|
} |
48 |
|
} |
49 |
|
|
50 |
sub _read { |
sub _read { |
51 |
my $self = shift; |
my $self = shift; |
52 |
$self->{_buffer_orig} = f2s($self->{path}); |
$self->_stat(); |
53 |
$self->{_buffer} = f2s($self->{path}); |
if ($self->exists()) { |
54 |
|
$self->{_buffer} = f2s($self->{filename}); |
55 |
|
} |
56 |
|
#$self->{_buffer_orig} = f2s($self->{filename}); |
57 |
} |
} |
58 |
|
|
59 |
sub toString { |
sub toString { |
65 |
sub addSuffix { |
sub addSuffix { |
66 |
my $self = shift; |
my $self = shift; |
67 |
my $suffix = shift; |
my $suffix = shift; |
68 |
$self->{path} .= ".$suffix"; |
$self->{filename} .= ".$suffix"; |
69 |
} |
} |
70 |
|
|
71 |
sub save { |
sub save { |
72 |
my $self = shift; |
my $self = shift; |
73 |
if ($self->{_buffer}) { |
if ($self->{_buffer}) { |
74 |
s2f($self->{path}, $self->{_buffer}); |
s2f($self->{filename}, $self->{_buffer}); |
75 |
} else { |
} else { |
76 |
print "please load $self->{path} before saving.", "\n"; |
print "please load $self->{filename} before saving.", "\n"; |
77 |
} |
} |
78 |
} |
} |
79 |
|
|
80 |
sub backup { |
sub backup { |
81 |
my $self = shift; |
my $self = shift; |
82 |
my $options = shift; |
my $options = shift; |
83 |
my $path = $self->{path}; |
my $path = $self->{filename}; |
84 |
$path .= '.' . $options->{suffix} if $options->{suffix}; |
$path .= '.' . $options->{suffix} if $options->{suffix}; |
85 |
s2f($path, $self->{_buffer_orig}); |
s2f($path, $self->{_buffer_orig}); |
86 |
} |
} |
93 |
if (eval($eval)) { return 1; } |
if (eval($eval)) { return 1; } |
94 |
} |
} |
95 |
|
|
96 |
|
sub exists { |
97 |
|
my $self = shift; |
98 |
|
$self->_stat(); |
99 |
|
return $self->{_meta}->{exists}; |
100 |
|
} |
101 |
|
|
102 |
1; |
1; |
103 |
__END__ |
__END__ |