[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [cgiapp] Good practices: how many run modes in an app


Hi Jeff -- 

> Af few weeks ago, I asked a question about a snazzy way to do a fill
> in form in one line
> 
> return 
> $self->fill_form($self->tt_process({}),$self->dbh->selectrow_h
> ashref("SELECT
> * from menus WHERE id = ?",{},$id));
> 
> Since this uses dbh directly, in Krang to do something similar does
> that mean you would make a method in a Krang module that was simply a
> wrapper to this call ? I guess the advantage to that would be that
> many other places could call this method with common results, instead
> of having to change many sql statements and risking errrors.


We wouldn't create a wrapper to that call, as it includes a template
which would violate encapsulation the other way (object modules
shouldn't imply presentation).  What we have in Krang is a very
high-level representation of our data which provides a "find()" method,
which returns objects:


  # Imaginary run-mode to display story titles
  sub show_stories {
    my $self = shift;

    # Find all published stories, sort by title
    my @stories = Krang::Story->find( published => 1,
                                      order_by => 'title' );
    my $html = "<html>\n";
    $html .= "<ol>\n";

    # List each story title
    foreach my $s (@stories) {
      $html .= "<li>". $s->title() ."</li>\n";
    }

    $html .= "</ol>\n";
    my $html = "</html>\n";

    return $html;
  }

These story objects ($s) have methods including new() and save().  The
find() method takes a bunch of parameters, from which SQL is generated
and issued against the database.

TTYL,

-Jesse-


--
 
Jesse Erlbaum
The Erlbaum Group
suppressed
Phone: 212-684-6161
Fax: 212-684-6226
 

---------------------------------------------------------------------
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.