752b70912c512136dba103698bff9c5ac070bce4
[MojoFacets.git] / lib / MojoFacets / Changes.pm
1 package MojoFacets::Changes;
2
3 use strict;
4 use warnings;
5
6 use base 'Mojolicious::Controller';
7
8 use Storable;
9
10 sub index {
11         my $self = shift;
12
13         my $max = $self->param('max') || 10;
14
15         my $changes;
16         foreach my $path ( sort { $b cmp $a } glob '/tmp/changes/*' ) {
17                 if ( $path =~ m{/((\d+\.\d+)\.data\.(.+))$} ) {
18                         push @$changes, { uid => $1, t => $2, action => $3 };
19                         last if $#$changes >= $max;
20                 } else {
21                         warn "ignore: $path\n";
22                 }
23         }
24
25         # Render template "changes/index.html.ep" with message
26         $self->render(message => 'Latest Changes', changes => $changes );
27 }
28
29
30 sub view {
31         my $self = shift;
32         my $uid = $self->param('uid');
33         $self->render( change => retrieve( "/tmp/changes/$uid" ), uid => $uid );
34 }
35
36 1;