line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Controller::CRUD::DBIC; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
83
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
48
|
|
5
|
1
|
|
|
1
|
|
6
|
use base qw(Catalyst::Controller::CRUD); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
100
|
|
6
|
1
|
|
|
1
|
|
6
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
672
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.21'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Catalyst::Controller::CRUD::DBIC - Implementation for Catalyst::Controller::CRUD |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head2 MyApp/lib/MyApp.pm |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package MyApp; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Catalyst qw/-Debug I18N CRUD Static::Simple/; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
1; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head2 MyApp/lib/MyApp/Controller/User.pm |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
package MyApp::Controller::User; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use base 'Catalyst::Controller'; |
29
|
|
|
|
|
|
|
use Class::Trigger; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub setting { |
32
|
|
|
|
|
|
|
my ( $self, $c ) = @_; |
33
|
|
|
|
|
|
|
my $hash = { |
34
|
|
|
|
|
|
|
'name' => 'user', |
35
|
|
|
|
|
|
|
'type' => 'DBIC', |
36
|
|
|
|
|
|
|
'model' => 'DBIC::UserMaster', |
37
|
|
|
|
|
|
|
'primary' => 'id', |
38
|
|
|
|
|
|
|
'columns' => [qw(name phone mail)], |
39
|
|
|
|
|
|
|
'default' => '/user/list', |
40
|
|
|
|
|
|
|
'template' => { |
41
|
|
|
|
|
|
|
'prefix' => 'template/user/', |
42
|
|
|
|
|
|
|
'suffix' => '.tt' |
43
|
|
|
|
|
|
|
}, |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
return $hash; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub create : Local { |
49
|
|
|
|
|
|
|
my ( $self, $c ) = @_; |
50
|
|
|
|
|
|
|
$c->create($self); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This module implements DBIx::Class depend interfaces for Catalyst::Controller::CRUD. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
- get_model |
60
|
|
|
|
|
|
|
- get_models |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 EXPORT |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
None by default. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 METHODS |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 get_model($this,$c,$self,$id) |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This method returns model object having $id. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Triggers: |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$self->call_trigger( 'get_model_after', $c, $hash ); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub get_model { |
79
|
0
|
|
|
0
|
1
|
|
my ( $this, $c, $self, $id ) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $name = $self->setting($c)->{name}; |
82
|
0
|
|
|
|
|
|
my $primary = $self->setting($c)->{primary}; |
83
|
0
|
|
|
|
|
|
my $model; |
84
|
0
|
0
|
|
|
|
|
if ($self->can('get_model')) { |
85
|
0
|
|
|
|
|
|
$model = $self->get_model( $c, $id ); |
86
|
|
|
|
|
|
|
} else { |
87
|
0
|
|
|
|
|
|
$model = $c->model( $self->setting($c)->{model} )->find( $primary => $id ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if (defined $model) { |
91
|
0
|
|
|
|
|
|
my $hash = $model->toHashRef; |
92
|
0
|
|
|
|
|
|
$self->call_trigger( 'get_model_after', $c, $hash ); |
93
|
0
|
|
|
|
|
|
$c->stash->{ $name } = $hash; |
94
|
|
|
|
|
|
|
} else { |
95
|
0
|
|
|
|
|
|
$c->res->status(404); |
96
|
0
|
|
|
|
|
|
$c->res->body("404 Not Found\n"); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
return $model; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 get_models($this,$c,$self) |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This method returns model objects. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub get_models { |
109
|
0
|
|
|
0
|
1
|
|
my ( $this, $c, $self ) = @_; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $name = $self->setting($c)->{name}; |
112
|
0
|
|
|
|
|
|
my $primary = $self->setting($c)->{primary}; |
113
|
0
|
0
|
|
|
|
|
my $where = $c->stash->{$name}->{where} ? $c->stash->{$name}->{where} : { disable => 0 }; |
114
|
0
|
0
|
|
|
|
|
my $order = $c->stash->{$name}->{order} ? $c->stash->{$name}->{order} : { order_by => $primary }; |
115
|
0
|
|
|
|
|
|
my $it = $c->model( $self->setting($c)->{model} )->search( $where, $order ); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# pager |
118
|
0
|
0
|
|
|
|
|
if (defined $order->{rows}) { |
119
|
0
|
|
|
|
|
|
$c->stash->{$name}->{pager}->{total} = $it->pager->total_entries; |
120
|
0
|
|
|
|
|
|
$c->stash->{$name}->{pager}->{pages} = $it->pager->last_page; |
121
|
0
|
|
|
|
|
|
$c->stash->{$name}->{pager}->{current} = $it->pager->current_page; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my @result; |
125
|
0
|
|
|
|
|
|
while (my $model = $it->next) { |
126
|
0
|
|
|
|
|
|
my $hash = $model->toHashRef; |
127
|
0
|
|
|
|
|
|
$self->call_trigger( 'get_model_after', $c, $hash ); |
128
|
0
|
|
|
|
|
|
$c->stash->{ $name . '_' . $primary . 's' }->{ $hash->{$primary} } = $hash; |
129
|
0
|
|
|
|
|
|
push( @result, $hash ); |
130
|
|
|
|
|
|
|
} |
131
|
0
|
|
|
|
|
|
return \@result; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 SEE ALSO |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Catalyst::Controller::CRUD, DBIx::Class |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 AUTHOR |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Jun Shimizu, Ebayside@cpan.orgE |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Copyright (C) 2006-2007 by Jun Shimizu |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
147
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.2 or, |
148
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |