Skip to content

Instantly share code, notes, and snippets.

@blabos-zz
Created October 28, 2010 09:42
Show Gist options
  • Save blabos-zz/651023 to your computer and use it in GitHub Desktop.
Save blabos-zz/651023 to your computer and use it in GitHub Desktop.
Teste como Mojo e SQLite
#!/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&iacute;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