[PATCH] Class::DBI::FromForm

[prev] [thread] [next] [Date index for 2005/06/20]

From: Drew Taylor
Subject: [PATCH] Class::DBI::FromForm
Date: 17:47 on 20 Jun 2005
------=_Part_2316_8455792.1119289673971
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Sorry if this is a bit OT, but FromForm does use ClassDBI... And I know sri=
=20
is on this list. (Hi sri - Catalyst rocks!)

At $work we use accessor_name() to changer the usual accessor/mutator to=20
'get_foo' and 'set_foo'. This patch makes FromForm.pm
<http://FromForm.pm>much more flexible about wacky schemes like ours.
create_from_form() doesn't
have a problem because it's just creating a hashref.

There's also a potential bug in _run_update() if you have multiple column=
=20
primary keys, but I don't use any tables so I don't have the tuits to do a=
=20
proper patch.

diff -u FromForm.pm.orig FromForm.pm <http://FromForm.pm>;
--- FromForm.pm.orig Mon Jun 20 13:41:22 2005
+++ FromForm.pm <http://FromForm.pm>; Mon Jun 20 13:40:53 2005
@@ -67,10 +67,10 @@
sub _run_update {
my ( $me, $them, $results ) =3D @_;
foreach my $col ( keys %{ $results->valid } ) {
- if ( $them->can($col) ) {
+ if ( $them->find_column($col) ) {
next if $col eq $them->primary_column;
my $val =3D $results->valid($col);
- $them->$col($val);
+ $them->set($col, $val);
}
}

Drew
--=20
----------------------------------------------------------------
Drew Taylor * Web development & consulting
Email: drew@xxxxxxxxxx.xxx * Site implementation & hosting
Web : www.drewtaylor.com <http://www.drewtaylor.com>; *=20
perl/mod_perl/DBI/mysql/postgres
----------------------------------------------------------------

------=_Part_2316_8455792.1119289673971
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Sorry if this is a bit OT, but FromForm does use ClassDBI... And I know sri=
 is on this list. (Hi sri - Catalyst rocks!)<br>
<br>
At $work we use accessor_name() to changer the usual accessor/mutator
to 'get_foo' and 'set_foo'. This patch makes <a href=3D"http://FromForm.pm"=
>FromForm.pm</a> much more
flexible about wacky schemes like ours. create_from_form() doesn't have
a problem because it's just creating a hashref.<br>
<br>
There's also a potential bug in _run_update() if you have multiple
column primary keys, but I don't use any tables so I don't have the
tuits to do a proper patch.<br>
<br>
diff -u FromForm.pm.orig <a href=3D"http://FromForm.pm">FromForm.pm</a><br>;
--- FromForm.pm.orig&nbsp;&nbsp;&nbsp; Mon Jun 20 13:41:22 2005<br>
+++ <a href=3D"http://FromForm.pm">FromForm.pm</a>; Mon Jun 20 13:40:53 2005=
<br>
@@ -67,10 +67,10 @@<br>
&nbsp;sub _run_update {<br>
&nbsp;&nbsp;&nbsp;&nbsp; my ( $me, $them, $results ) =3D @_;<br>
&nbsp;&nbsp;&nbsp;&nbsp; foreach my $col ( keys %{ $results-&gt;valid } ) {=
<br>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( $them-&gt;can($col) ) {<br=
>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( $them-&gt;find_column($col=
) ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ne=
xt if $col eq $them-&gt;primary_column;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my=
 $val =3D $results-&gt;valid($col);<br>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $them-&=
gt;$col($val);<br>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $them-&=
gt;set($col, $val);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>Drew<br>-- <br>--------------------------------------------------------=
--------<br>
Drew
Taylor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;
*&nbsp;&nbsp;Web development &amp; consulting<br> Email: <a href=3D"mailto:=
drew@xxxxxxxxxx.xxx">drew@xxxxxxxxxx.xxx</a>&nbsp;&nbsp;*&nbsp;&nbsp;Site i=
mplementation &amp; hosting<br> Web&nbsp;&nbsp;: <a href=3D"http://www.drew=
taylor.com">www.drewtaylor.com</a>&nbsp;&nbsp; *&nbsp;&nbsp;perl/mod_perl/D=
BI/mysql/postgres
<br> ----------------------------------------------------------------

------=_Part_2316_8455792.1119289673971--

[PATCH] Class::DBI::FromForm
Drew Taylor 17:47 on 20 Jun 2005

Generated at 16:36 on 28 Jul 2005 by mariachi v0.52