Created
October 28, 2010 09:42
-
-
Save blabos-zz/651023 to your computer and use it in GitHub Desktop.
Teste como Mojo e SQLite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use 5.010; | |
use strict; | |
use warnings; | |
package Model; | |
use ORLite { | |
'file' => 'bars.db', | |
'create' => sub { | |
my $dbh = shift; | |
$dbh->do(" | |
create table ponto ( | |
mat text not null, | |
hora integer not null, | |
primary key (mat, hora) | |
); | |
"); | |
}, | |
}; | |
package main; | |
use Mojolicious::Lite; | |
get '/' => sub { | |
my $self = shift; | |
$self->stash('msg' => ''); | |
} => 'index'; | |
post '/' => sub { | |
my $self = shift; | |
my $mat = $self->param('mat'); | |
my $hora = time; | |
my $rec = Model::Ponto->create( | |
'mat' => $mat, | |
'hora' => $hora, | |
); | |
if ($rec) { | |
$self->stash( | |
'msg' => "inserido($rec->{'mat'}, $rec->{'hora'})"); | |
} | |
} => 'index'; | |
shagadelic; | |
__DATA__ | |
@@ index.html.ep | |
<html> | |
<head><title>Ponto</title></head> | |
<body> | |
<form action="/" method="post"> | |
Matrícula:<input type="text" name="mat" /> | |
<input type="submit" /> | |
</form> | |
<p><%= $msg %></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment