DBIx-Simple-Class
view release on metacpan or search on metacpan
examples/lib/My/App.pm view on Meta::CPAN
{xmlns => "http://www.w3.org/1999/xhtml"},
head(
meta({'http-equiv' => "Content-Type", content => "text/html; charset=utf-8"}),
title('Example application'),
script(
{src => '//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js'}, ''
),
$/,
script(
{src => '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js'},
''
),
$/,
Link(
{ href =>
"//ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/base/jquery-ui.css",
rel => "stylesheet",
type => "text/css"
}
),
$/,
script(<<'JS')
$(function(){
$('a.button,input.submit').button();
$('table').addClass('ui-widget');
$('th,caption,legend').addClass('ui-widget-header');
$('td, input').addClass('ui-widget-content');
$('div.error').addClass('ui-state-error ui-corner-all')
$('div.info').addClass('ui-state-highlight ui-corner-all')
})
JS
,
style(<<'CSS')
form div {width:30ex}
form div input, form div legend {width:100%}
.error p,.info p {margin:1ex; font-family:sans-serif}
CSS
),
body($app->$action())
);
}
else {
print $app->q->header(
-type => 'text/html',
-status => '404 Not Found',
-charset => 'utf-8',
),
start_html(-title => 'Page Not Found'), h1('Page Not Found'), end_html();
}
}
sub initialise_db {
my $app = shift;
DBIx::Simple::Class->DEBUG(1);
my $dbix = DBIx::Simple->connect(
"dbi:SQLite:dbname=$ENV{users_HOME}/db.sqlite",
{sqlite_unicode => 1, RaiseError => 1}
) || die $DBI::errstr;
DBIx::Simple::Class->dbix($dbix);
$dbix->query(<<"TAB");
CREATE TABLE IF NOT EXISTS groups(
id INTEGER PRIMARY KEY AUTOINCREMENT,
group_name VARCHAR(12),
"foo-bar" VARCHAR(13),
data TEXT
)
TAB
$dbix->query(<<"TAB");
CREATE TABLE IF NOT EXISTS users(
id INTEGER PRIMARY KEY AUTOINCREMENT,
group_id INT default 1,
login_name VARCHAR(12) UNIQUE,
login_password VARCHAR(100),
disabled INT DEFAULT 1
)
TAB
sub My::Group::ALIASES {
{data => 'group_data', 'foo-bar' => 'foo_bar'};
}
My::Group->QUOTE_IDENTIFIERS(1);
My::User->QUOTE_IDENTIFIERS(1);
}
sub q { $_[0]->{q} ||= CGI->new() }
1;
( run in 1.073 second using v1.01-cache-2.11-cpan-39bf76dae61 )