| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catalyst::Model::CDBI::CRUD; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
30025
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
39
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use base 'Catalyst::Model::CDBI'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
806
|
|
|
5
|
1
|
|
|
1
|
|
585
|
use Class::DBI::AsForm; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Class::DBI::FromForm; |
|
7
|
|
|
|
|
|
|
use Class::DBI::Plugin::RetrieveAll; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Catalyst::Model::CDBI::CRUD - CRUD CDBI Model Class |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# lib/MyApp/Model/CDBI.pm |
|
18
|
|
|
|
|
|
|
package MyApp::Model::CDBI; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use base 'Catalyst::Model::CDBI::CRUD'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
__PACKAGE__->config( |
|
23
|
|
|
|
|
|
|
dsn => 'dbi:SQLite2:/tmp/myapp.db', |
|
24
|
|
|
|
|
|
|
relationships => 1 |
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
1; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# lib/MyApp.pm |
|
30
|
|
|
|
|
|
|
package MyApp; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use Catalyst 'FormValidator'; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
__PACKAGE__->config( |
|
35
|
|
|
|
|
|
|
name => 'My Application', |
|
36
|
|
|
|
|
|
|
root => '/home/joeuser/myapp/root' |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub table : Global { |
|
40
|
|
|
|
|
|
|
my ( $self, $c ) = @_; |
|
41
|
|
|
|
|
|
|
$c->form( optional => [ MyApp::Model::CDBI::Table->columns |
|
42
|
|
|
|
|
|
|
] ); #see Data::FormValidator |
|
43
|
|
|
|
|
|
|
$c->forward('MyApp::Model::CDBI::Table'); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
sub end : Private { |
|
46
|
|
|
|
|
|
|
$c->forward('MyApp::V::TT'); |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This is a subclass of C<Catalyst::Model::CDBI> with additional CRUD |
|
55
|
|
|
|
|
|
|
methods. Don't forget to copy the base templates to config->root! |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
*NOTE* This module has been deprecated. See BUGS section below! |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 METHODS |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head3 add |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Does nothing by default. |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub add { } |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head3 destroy |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Deletes a L<Class::DBI> object. |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub destroy { |
|
76
|
|
|
|
|
|
|
my ( $self, $c ) = @_; |
|
77
|
|
|
|
|
|
|
$c->stash->{item}->delete; |
|
78
|
|
|
|
|
|
|
$c->stash->{template} = 'list'; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head3 do_add |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Creates a new L<Class::DBI> object from $c->form. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub do_add { |
|
88
|
|
|
|
|
|
|
my ( $self, $c ) = @_; |
|
89
|
|
|
|
|
|
|
$self->create_from_form( $c->form ); |
|
90
|
|
|
|
|
|
|
$c->stash->{template} = 'list'; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head3 do_edit |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Updates a L<Class::DBI> object from $c->form. |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub do_edit { |
|
100
|
|
|
|
|
|
|
my ( $self, $c ) = @_; |
|
101
|
|
|
|
|
|
|
$c->stash->{item}->update_from_form( $c->form ); |
|
102
|
|
|
|
|
|
|
$c->stash->{template} = 'edit'; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head3 edit |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Does nothing by default. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub edit { } |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head3 list |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Does nothing by default. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub list { } |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head3 process |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Dispatches CRUD request to methods. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub process { |
|
128
|
|
|
|
|
|
|
my $self = shift; |
|
129
|
|
|
|
|
|
|
my $c = shift; |
|
130
|
|
|
|
|
|
|
my $method = shift || 'list'; |
|
131
|
|
|
|
|
|
|
$c->stash->{item} = $self->retrieve( $_[0] ) if defined( $_[0] ); |
|
132
|
|
|
|
|
|
|
$c->stash->{template} = $method; |
|
133
|
|
|
|
|
|
|
$c->stash->{class} = ref $self || $self; |
|
134
|
|
|
|
|
|
|
$self->$method( $c, @_ ) if $self->can($method); |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head3 view |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Does nothing by default. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub view { } |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 BUGS |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This module is no longer supported by the Catalyst developers. We keep it |
|
148
|
|
|
|
|
|
|
indexed for the sake of existing users, but highly recommend new users to |
|
149
|
|
|
|
|
|
|
look at L<Catalyst::Helper::Controller::Scaffold> |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
L<Catalyst>, L<Catalyst::Model::CDBI> |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 AUTHOR |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Sebastian Riedel, C<sri@cpan.org> |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
|
162
|
|
|
|
|
|
|
the same terms as Perl itself. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1; |