line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::DBIC::Controller::DBIC; |
2
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Build simple views to DBIC data |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
6
|
|
|
|
|
|
|
#pod |
7
|
|
|
|
|
|
|
#pod use Mojolicious::Lite; |
8
|
|
|
|
|
|
|
#pod plugin DBIC => { schema => ... }; |
9
|
|
|
|
|
|
|
#pod get '/', { |
10
|
|
|
|
|
|
|
#pod controller => 'DBIC', |
11
|
|
|
|
|
|
|
#pod action => 'list', |
12
|
|
|
|
|
|
|
#pod resultset => 'BlogPosts', |
13
|
|
|
|
|
|
|
#pod template => 'blog/list', |
14
|
|
|
|
|
|
|
#pod }; |
15
|
|
|
|
|
|
|
#pod |
16
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
17
|
|
|
|
|
|
|
#pod |
18
|
|
|
|
|
|
|
#pod This controller allows for easy working with data from the schema. |
19
|
|
|
|
|
|
|
#pod Controllers are configured through the stash when setting up the routes. |
20
|
|
|
|
|
|
|
#pod |
21
|
|
|
|
|
|
|
#pod =head1 SEE ALSO |
22
|
|
|
|
|
|
|
#pod |
23
|
|
|
|
|
|
|
#pod L |
24
|
|
|
|
|
|
|
#pod |
25
|
|
|
|
|
|
|
#pod =cut |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
2
|
|
30877
|
use Mojo::Base 'Mojolicious::Controller'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
14
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#pod =method list |
30
|
|
|
|
|
|
|
#pod |
31
|
|
|
|
|
|
|
#pod get '/', { |
32
|
|
|
|
|
|
|
#pod controller => 'DBIC', |
33
|
|
|
|
|
|
|
#pod action => 'list', |
34
|
|
|
|
|
|
|
#pod resultset => 'BlogPosts', |
35
|
|
|
|
|
|
|
#pod template => 'blog/list', |
36
|
|
|
|
|
|
|
#pod }; |
37
|
|
|
|
|
|
|
#pod |
38
|
|
|
|
|
|
|
#pod List data in a ResultSet. Returns false if it has rendered a response, |
39
|
|
|
|
|
|
|
#pod true if dispatch can continue. |
40
|
|
|
|
|
|
|
#pod |
41
|
|
|
|
|
|
|
#pod This method uses the following stash values for configuration: |
42
|
|
|
|
|
|
|
#pod |
43
|
|
|
|
|
|
|
#pod =over |
44
|
|
|
|
|
|
|
#pod |
45
|
|
|
|
|
|
|
#pod =item resultset |
46
|
|
|
|
|
|
|
#pod |
47
|
|
|
|
|
|
|
#pod The L class to list. |
48
|
|
|
|
|
|
|
#pod |
49
|
|
|
|
|
|
|
#pod =back |
50
|
|
|
|
|
|
|
#pod |
51
|
|
|
|
|
|
|
#pod This method sets the following stash values for template rendering: |
52
|
|
|
|
|
|
|
#pod |
53
|
|
|
|
|
|
|
#pod =over |
54
|
|
|
|
|
|
|
#pod |
55
|
|
|
|
|
|
|
#pod =item resultset |
56
|
|
|
|
|
|
|
#pod |
57
|
|
|
|
|
|
|
#pod The L object containing the desired objects. |
58
|
|
|
|
|
|
|
#pod |
59
|
|
|
|
|
|
|
#pod =back |
60
|
|
|
|
|
|
|
#pod |
61
|
|
|
|
|
|
|
#pod =cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub list { |
64
|
2
|
|
|
2
|
1
|
811
|
my ( $c ) = @_; |
65
|
2
|
|
|
|
|
12
|
my $rs_class = $c->stash( 'resultset' ); |
66
|
2
|
|
|
|
|
35
|
my $rs = $c->schema->resultset( $rs_class ); |
67
|
2
|
|
|
|
|
866
|
return $c->stash( |
68
|
|
|
|
|
|
|
resultset => $rs, |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#pod =method get |
73
|
|
|
|
|
|
|
#pod |
74
|
|
|
|
|
|
|
#pod get '/blog/:id', { |
75
|
|
|
|
|
|
|
#pod controller => 'DBIC', |
76
|
|
|
|
|
|
|
#pod action => 'get', |
77
|
|
|
|
|
|
|
#pod resultset => 'BlogPosts', |
78
|
|
|
|
|
|
|
#pod template => 'blog/get', |
79
|
|
|
|
|
|
|
#pod }; |
80
|
|
|
|
|
|
|
#pod |
81
|
|
|
|
|
|
|
#pod Fetch a single result by its ID. If no result is found, renders a not |
82
|
|
|
|
|
|
|
#pod found error. Returns false if it has rendered a response, true if |
83
|
|
|
|
|
|
|
#pod dispatch can continue. |
84
|
|
|
|
|
|
|
#pod |
85
|
|
|
|
|
|
|
#pod This method uses the following stash values for configuration: |
86
|
|
|
|
|
|
|
#pod |
87
|
|
|
|
|
|
|
#pod =over |
88
|
|
|
|
|
|
|
#pod |
89
|
|
|
|
|
|
|
#pod =item resultset |
90
|
|
|
|
|
|
|
#pod |
91
|
|
|
|
|
|
|
#pod The L class to use. |
92
|
|
|
|
|
|
|
#pod |
93
|
|
|
|
|
|
|
#pod =item id |
94
|
|
|
|
|
|
|
#pod |
95
|
|
|
|
|
|
|
#pod The ID to pass to L. |
96
|
|
|
|
|
|
|
#pod |
97
|
|
|
|
|
|
|
#pod =back |
98
|
|
|
|
|
|
|
#pod |
99
|
|
|
|
|
|
|
#pod This method sets the following stash values for template rendering: |
100
|
|
|
|
|
|
|
#pod |
101
|
|
|
|
|
|
|
#pod =over |
102
|
|
|
|
|
|
|
#pod |
103
|
|
|
|
|
|
|
#pod =item row |
104
|
|
|
|
|
|
|
#pod |
105
|
|
|
|
|
|
|
#pod The L object containing the desired object. |
106
|
|
|
|
|
|
|
#pod |
107
|
|
|
|
|
|
|
#pod =back |
108
|
|
|
|
|
|
|
#pod |
109
|
|
|
|
|
|
|
#pod =cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub get { |
112
|
4
|
|
|
4
|
1
|
90507
|
my ( $c ) = @_; |
113
|
4
|
|
|
|
|
15
|
my $rs_class = $c->stash( 'resultset' ); |
114
|
4
|
|
|
|
|
50
|
my $id = $c->stash( 'id' ); |
115
|
4
|
|
|
|
|
43
|
my $rs = $c->schema->resultset( $rs_class ); |
116
|
4
|
|
|
|
|
1712
|
my $row = $rs->find( $id ); |
117
|
4
|
100
|
|
|
|
13032
|
if ( !$row ) { |
118
|
2
|
|
|
|
|
34
|
$c->reply->not_found; |
119
|
2
|
|
|
|
|
132980
|
return; |
120
|
|
|
|
|
|
|
} |
121
|
2
|
|
|
|
|
59
|
return $c->stash( |
122
|
|
|
|
|
|
|
row => $row, |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |