my $json = $c->stash('json');
unless ( defined $json->{data} ) {
$json->{data} = {};
$c->stash( 'json' => $json );
=head1 MOJOLICIOUS HOOKS
This module installs an before_render application hook, which gurantees JSON output.
Refer L<Mojolicious::Controller::REST> documentation for output format.
Hook installati
y %data = @_;
my $json = $self->stash('json');
if ( defined( $json->{data} ) ) {
@{ $json->{data} }{ keys %data } = values %data;
}
else {
$json->{data} = {%data};
json => $json );
return $self;
}
sub message {
my $self = shift;
my ( $message, $severity ) = @_;
$severity //= 'info';
my $json = $self->stash('json');
if ( defined( $json
$json->{messages}}, { text => $message, severity => $severity } );
}
else {
$json->{messages} = [ { text => $message, severity => $severity } ];
}
$self->stash( json => $json