| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Class::DBI::FromForm; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27915
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
45
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw/$VERSION @EXPORT/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
67
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use base 'Exporter'; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
559
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$VERSION = 0.04; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
@EXPORT = qw/update_from_form create_from_form/; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Class::DBI::FromForm - Update Class::DBI data using Data::FormValidator or HTML Widget |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package Film; |
|
18
|
|
|
|
|
|
|
use Class::DBI::FromForm; |
|
19
|
|
|
|
|
|
|
use base 'Class::DBI'; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $results = Data::FormValidator->check( ... ); |
|
22
|
|
|
|
|
|
|
my $film = Film->retrieve('Fahrenheit 911'); |
|
23
|
|
|
|
|
|
|
$film->update_from_form($results); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $new_film = Film->create_from_form($results); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Create and update L<Class::DBI> objects from L<Data::FormValidator> or L<HTML::Widget>. |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 METHODS |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head3 create_from_form |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Create a new object. |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub create_from_form { |
|
40
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
41
|
0
|
0
|
|
|
|
|
die "create_from_form can only be called as a class method" if ref $class; |
|
42
|
0
|
|
|
|
|
|
__PACKAGE__->_run_create( $class, @_ ); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head3 update_from_form |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Update object. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub update_from_form { |
|
52
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
53
|
0
|
0
|
|
|
|
|
die "update_from_form cannot be called as a class method" unless ref $self; |
|
54
|
0
|
|
|
|
|
|
__PACKAGE__->_run_update( $self, @_ ); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _run_create { |
|
58
|
0
|
|
|
0
|
|
|
my ( $me, $class, $results ) = @_; |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $them = bless {}, $class; |
|
61
|
0
|
|
|
|
|
|
my $cols = {}; |
|
62
|
0
|
|
|
|
|
|
foreach my $col ( $them->columns('All') ) { |
|
63
|
0
|
0
|
|
|
|
|
if($results->isa('HTML::Widget::Result')) { |
|
64
|
0
|
|
|
|
|
|
$cols->{$col} = $results->param($col); |
|
65
|
|
|
|
|
|
|
} else { |
|
66
|
0
|
|
|
|
|
|
$cols->{$col} = $results->valid($col); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
} |
|
69
|
0
|
|
|
|
|
|
return $class->create($cols); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _run_update { |
|
73
|
0
|
|
|
0
|
|
|
my ( $me, $them, $results ) = @_; |
|
74
|
0
|
|
|
|
|
|
my @cols = ( $results->isa('HTML::Widget::Result') ? |
|
75
|
|
|
|
|
|
|
$results->valid : |
|
76
|
0
|
0
|
|
|
|
|
keys %{ $results->valid } ); |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
foreach my $col ( @cols ) { |
|
79
|
0
|
0
|
|
|
|
|
if ( $them->can($col) ) { |
|
80
|
0
|
0
|
|
|
|
|
next if $col eq $them->primary_column; |
|
81
|
0
|
0
|
|
|
|
|
if($results->isa('HTML::Widget::Result')) { |
|
82
|
0
|
|
|
|
|
|
$them->$col( $results->param($col)); |
|
83
|
|
|
|
|
|
|
} else { |
|
84
|
0
|
|
|
|
|
|
$them->$col( $results->valid($col)); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
} |
|
88
|
0
|
|
|
|
|
|
$them->update; |
|
89
|
0
|
|
|
|
|
|
return 1; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 fill_widget <widget> |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This only applies to L<HTML::Widget>>. |
|
96
|
|
|
|
|
|
|
Fills the form from a CDBI object. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub fill_widget { |
|
101
|
0
|
|
|
0
|
0
|
|
my ($me ,$widget)=@_; |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
foreach my $element ( @{ $widget->{_elements} } ) { |
|
|
0
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my $name=$element->name; |
|
105
|
0
|
0
|
0
|
|
|
|
next unless $name && $me->can($name); |
|
106
|
0
|
|
|
|
|
|
$element->value($me->$name); |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L<Class::DBI>, L<Class::DBI::FromCGI>, L<Data::FormValidator> |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Sebastian Riedel, C<sri@oook.de> |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 LICENSE |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This library is free software . You can redistribute it and/or modify it under |
|
121
|
|
|
|
|
|
|
the same terms as perl itself. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |