/[Frey]/trunk/lib/Frey/Storage.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/Storage.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 224 - (show annotations)
Sat Nov 1 00:58:24 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 1130 byte(s)
role to implement mkbasepath
1 package Frey::Storage;
2 use Moose::Role;
3
4 with 'Frey::Path';
5
6 #use YAML::Syck; # XXX doesn't play nice with Continuity
7 use YAML qw/LoadFile DumpFile/;
8
9 =head2 store
10
11 $o->store( 'filename.yml', $data );
12
13 =cut
14
15 has 'storage_timestamp' => (
16 is => 'rw',
17 isa => 'HashRef[Int]',
18 default => sub { {} },
19 );
20
21 sub store {
22 my $self = shift;
23 my ( $filename, $data ) = @_;
24 $filename .= '.yml';
25 $self->mkbasepath( $filename );
26 DumpFile( $filename, $data );
27 }
28
29 =head2 load
30
31 $data = $o->load( 'filename.yml' );
32
33 =cut
34
35 sub load {
36 my ( $self, $filename ) = @_;
37 $filename .= '.yml';
38 return if ! -e $filename;
39 $self->storage_timestamp->{ $filename } = _path_time( $filename );
40 LoadFile( $filename );
41 }
42
43 =head2 reload
44
45 Reload file if on-disk copy have changed
46
47 my $new_data = $o->reload( 'filename.yml' );
48
49 =cut
50
51 sub _path_time {
52 (stat( $_[0] ))[9]; # mtime
53 }
54
55 sub reload {
56 my ( $self, $filename ) = @_;
57 my $path = $filename . '.yml';
58 return if defined $self->storage_timestamp->{ $path } && $self->storage_timestamp->{ $path } == _path_time( $path );
59 warn "# reload $filename" if $self->debug;
60 $self->load( $filename );
61 }
62
63 1;

  ViewVC Help
Powered by ViewVC 1.1.26