package App; use strict; use base 'Module'; use Data::Dumper; use Carp; sub start { my $self = shift; # Initialize the application $self->init(); # Endless loop for the application while(1) { # Display the list of entries my $f = $self->dispTemplate('showGuests.tpl', entries => $self->{entries}, curpage => $self->{curpage}, admin => $self->{admin} ); # Keep track of the current action my $action = $f->{action} || ''; # Keep track of the current page number $self->{curpage} = $f->{curpage} || $self->{curpage}; # Anyone can add a comment or try to administrate if ($action eq 'Add Comment') { $self->addComment } elsif ($action eq 'Administrate') { $self->admin } # Only admins can change settings, and edit/delete entries if ($self->{admin}) { if ($action eq 'Settings') { $self->adminSettings } elsif ($f->{remove}) { $self->removeEntry($f->{remove}) } elsif ($f->{edit}) { $self->editEntry($f->{edit}) } } } } sub init { my $self = shift; # We should only initialize once $self->nocache('init'); $self->{curpage} = 1; $self->loadSettings; } sub loadSettings { my $self = shift; my $VAR1; do 'conf.txt'; $self->{conf} = $VAR1; do 'entries.txt'; $self->{entries} = $VAR1; } sub saveSettings { my $self = shift; open(OUT, '>conf.txt') or die "Error opening conf.txt: $!\n"; print OUT Dumper($self->{conf}); open(OUT, '>entries.txt') or die "Error opening entries.txt: $!\n"; print OUT Dumper($self->{entries}); } sub addComment { my $self = shift; my $action; do { my $f = $self->dispTemplate('addComment.tpl'); $action = $f->{action} || ''; if ($action eq 'Add Comment') { my $entry; foreach my $var (qw( name comment )) { $entry->{$var} = $f->{$var}; } push @{$self->{entries}}, $entry; $self->saveSettings; $action = 'Exit'; } } until ($action eq 'Exit'); } END { $::s->param('App', $::a); $::s->close(); } 1;