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