/[cvs]/nfo/perl/libs/Data/Storage/Handler/File.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Storage/Handler/File.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by joko, Tue Feb 11 05:15:45 2003 UTC revision 1.5 by joko, Tue Feb 18 19:18:50 2003 UTC
# Line 4  Line 4 
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  ##  ##
# Line 24  use base qw( DesignPattern::Object ); Line 30  use base qw( DesignPattern::Object );
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 {
# Line 39  sub toString { Line 65  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  }  }
# Line 67  sub matches { Line 93  sub matches {
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__

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed