On Sun, 25 Jan 2004, Cees Hek wrote:
> > Did you know you can do the same thing in just a few lines of Perl
> > code? And those lines will be a lot easier to debug and maintain
> > later (see reference to my cursing colleague for proof!).
>
> You can get the data in a few lines of code, but you can't wrap it in an
> object in just a few lines of code.
Sure you can! I do it all the time. Something like:
while ($row = $sth->fetchrow_arrayref()) {
my $obj = bless({}, $pkg);
@suppressed = @$row;
Now $obj is an object in $pkg, with an attribute for each item in
@fields (which is also used to build the SELECT). And since we use
Class::MethodMaker to build accessors this really is just a few lines
of code total.
> So effectively what you are doing is creating an object that abstracts
> the interface to the database, by wrapping your data in a custom object
> specifically written for this data. This way your controller and view
> objects don't need to know DBI or SQL, they interact directly with your
> abstraction modules.
Exactly. There's no SQL in the CGI::Application controller classes.
The only modules that know about the database are the model classes.
> The goal here is the same, but the means are different. You need to
> write a custom class for every data object you need. Class::DBI just
> generalizes this job for you (with some limitations as happens with
> every attempt at generalization).
Right. The question is, does it do a good enough job to be worth the
added complexity. My judgement, based on building many projects
without it and watching one built with it from the sidelines, is no.
-sam
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.