line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Controller::REST; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Mojolicious Controller for RESTful operations |
4
|
|
|
|
|
|
|
our $VERSION = '0.006'; # VERSION |
5
|
2
|
|
|
2
|
|
736880
|
use Mojo::Base 'Mojolicious::Controller'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
21
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub data { |
8
|
2
|
|
|
2
|
1
|
30290
|
my $self = shift; |
9
|
2
|
|
|
|
|
8
|
my %data = @_; |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
|
|
8
|
my $json = $self->stash('json'); |
12
|
|
|
|
|
|
|
|
13
|
2
|
100
|
|
|
|
27
|
if ( defined( $json->{data} ) ) { |
14
|
1
|
|
|
|
|
4
|
@{ $json->{data} }{ keys %data } = values %data; |
|
1
|
|
|
|
|
4
|
|
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
else { |
17
|
1
|
|
|
|
|
5
|
$json->{data} = {%data}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
128
|
$self->stash( json => $json ); |
21
|
2
|
|
|
|
|
40
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub message { |
25
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
26
|
0
|
|
|
|
|
|
my ( $message, $severity ) = @_; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
0
|
|
|
|
$severity //= 'info'; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $json = $self->stash('json'); |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
if ( defined( $json->{messages} ) ) { |
33
|
0
|
|
|
|
|
|
push( $json->{messages}, { text => $message, severity => $severity } ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
0
|
|
|
|
|
|
$json->{messages} = [ { text => $message, severity => $severity } ]; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$self->stash( json => $json ); |
40
|
0
|
|
|
|
|
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
0
|
1
|
|
sub message_warn { $_[0]->message( $_[1], 'warn' ) } |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub status { |
46
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
47
|
0
|
|
|
|
|
|
my $status = shift; |
48
|
0
|
|
|
|
|
|
$self->stash( 'status' => $status ); |
49
|
0
|
|
|
|
|
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |