rmat );
$s->respond_to(
html => sub { $s->render_pm },
json => sub { $s->render( json => $s->render_json ) },
css => sub { $s->render_static_file },
js => sub {
ly->not_found;
}
sub render_html {
my $c = shift;
# needed for recursive calls (html -> json as an example)
my $query = $c->req->params->to_hash;
while ( my ( $k, $v ) = each %$query
$k => $v );
}
return { template => class_to_path( ref($c) ) =~ s/\.pm//r };
}
sub render_json {
my $c = shift;
return {};
}
sub render_static_file {
my $c = shift;
# optiona
lcome to Mojo::Leds framework based on Mojolicious!' );
$c->SUPER::render_html;
}
sub render_json {
my $c = shift;
}
1;
@@ static
<!DOCTYPE html>
<html>
<head>
<title>Welcome to Mojo:
tes;
$r->get('/version')->to(
cb => sub {
shift->render(
json => {
class => $class,
version => $version
tus')->to(
cb => sub {
my $s = shift;
$s->render(
json => {
app_name => $app_name,
server => {
};
return $rows;
};
my $root_with_format =
$r->get( '/' => [ format => [ 'json', 'html', 'txt' ] ] );
$root_with_format->get( '/routes/:verbose' => { verbose => '' } )->to
ror( 'Element duplicated', 409 )
unless ( $rec->in_storage );
return $rec;
}
sub _rec2json() {
my $c = shift;
my $rec = shift || $c->stash( $c->_class_name . '::record' );
re
ec);
# annullo tutti i campi
$rec->$_(undef) foreach ( grep !/^${pk}$/, keys %{ $c->_rec2json } );
while ( my ( $k, $v ) = each %$set ) {
$rec->$k($v);
}
$rec->update;
$c->_rec2json($_);
}
if ($rc) {
$recs = { count => $rec->pager->total_entries, recs => $recs };
}
return $recs;
}
sub _listupdate {
my $c = shift;
my $json = shift
return $c->_raise_error( 'Element duplicated', 409 );
}
return $rec;
}
sub _rec2json() {
my $c = shift;
my $rec = shift || $c->stash( $c->_class_name . '::record' );
re
}
return $recs;
}
sub _listupdate {
my $c = shift;
my $json = shift;
my @recs;
foreach my $item (@$json) {
if ( exists $item->{ $c->pk } ) {
$c->app->log-
use Mojo::Base 'Mojo::Leds::Page';
use Mojo::Util qw(decamelize class_to_path);
use Mojo::JSON qw(decode_json);
has table => sub {
return decamelize(
( split( /\//, class_to_path( ref sh
3 ) if $c->ro;
my $rec = $c->_json_from_body;
return unless ($rec);
$rec = $c->_create($rec);
return unless ($rec);
$c->render_json( $c->_rec2json($rec) );
}
sub delete {
my $
n $c->_raise_error( 'Element not found', 404 ) unless $rec;
$c->_delete($rec);
$c->render_json( undef, 204 );
}
sub list {
my $c = shift;
my $query = $c->param('query');
retur