line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cookieville::Schema; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Cookieville::Schema - Controller for running actions on the schema |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=cut |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
18481
|
use Mojo::Base 'Mojolicious::Controller'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
23
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 METHODS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head2 index |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Render information about this application. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub index { |
20
|
4
|
|
|
4
|
1
|
4646
|
my $self = shift; |
21
|
|
|
|
|
|
|
|
22
|
7
|
|
|
|
|
22
|
$self->render( |
23
|
4
|
|
100
|
|
|
35
|
json => {map { $_ => $self->${\"_info_$_"} } split /,/, +($ENV{COOKIEVILLE_INFO} // 'version,source,resources')},); |
|
7
|
|
|
|
|
6
|
|
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 sources_list |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Render a list of sources. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub sources_list { |
33
|
4
|
|
|
4
|
1
|
7908
|
my $self = shift; |
34
|
4
|
|
|
|
|
49
|
my @sources = sort $self->db->sources; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$self->respond_to( |
37
|
1
|
|
|
1
|
|
471
|
csv => sub { shift->render(text => join ",", @sources); }, |
38
|
|
|
|
|
|
|
txt => sub { |
39
|
1
|
|
|
1
|
|
457
|
shift->render(text => join "", map {"$_\n"} @sources); |
|
2
|
|
|
|
|
8
|
|
40
|
|
|
|
|
|
|
}, |
41
|
2
|
|
|
2
|
|
1044
|
any => sub { shift->render(json => \@sources); }, |
42
|
4
|
|
|
|
|
5159
|
); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 source_schema |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Render the source definition. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub source_schema { |
52
|
2
|
|
|
2
|
1
|
3799
|
my $self = shift; |
53
|
2
|
|
|
|
|
5
|
my $source = eval { $self->db->source($self->stash('source')) }; |
|
2
|
|
|
|
|
46
|
|
54
|
|
|
|
|
|
|
|
55
|
2
|
100
|
|
|
|
2968
|
if ($source) { |
56
|
1
|
|
|
|
|
5
|
$self->render( |
57
|
|
|
|
|
|
|
json => { |
58
|
|
|
|
|
|
|
columns => $self->_columns_from($source), |
59
|
|
|
|
|
|
|
name => $source->name, |
60
|
|
|
|
|
|
|
primary_columns => [$source->primary_columns], |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else { |
65
|
1
|
|
|
|
|
9
|
$self->render(json => {message => 'No source by that name.'}, status => 404); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _columns_from { |
70
|
1
|
|
|
1
|
|
2
|
my ($self, $source) = @_; |
71
|
1
|
|
|
|
|
2
|
my %columns; |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
5
|
for my $name ($source->columns) { |
74
|
3
|
|
|
|
|
29
|
$columns{$name} = $source->column_info($name); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
13
|
return \%columns; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _info_resources { |
81
|
|
|
|
|
|
|
+{ |
82
|
2
|
|
|
2
|
|
30
|
schema_source_list => ["GET", "/sources"], |
83
|
|
|
|
|
|
|
schema_for_source => ["GET", "/:source/schema"], |
84
|
|
|
|
|
|
|
source_select => ["GET", "/:source/select?q=:json&limit=:int&order_by:json"], |
85
|
|
|
|
|
|
|
source_delete => ["DELETE", "/:source/:id"], |
86
|
|
|
|
|
|
|
source_patch => ["PATCH", "/:source/:id"], |
87
|
|
|
|
|
|
|
source_update_or_insert => ["PUT", "/:source"], |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _info_source { |
92
|
3
|
|
|
3
|
|
12
|
'https://github.com/jhthorsen/cookieville'; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _info_version { |
96
|
2
|
50
|
|
2
|
|
7
|
eval { Cookieville->VERSION } || 0; |
|
2
|
|
|
|
|
42
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 AUTHOR |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Jan Henning Thorsen - C |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |