* Perrin Harkins ([EMAIL PROTECTED]) [010914 17:11]:
> > We have also heard something about OpenInteract, which is based on
> > Template Toolkit - may be it would be simplier to use it?
> 
> It does sound like a possible good choice for your purposes, since it
> combines a basic application structure with Template Toolkit integration and
> an object/relational mapping tool (SPOPS) for data management.

OpenInteract will probably do what you want, but one of its design
philosophies is to have the templates to relatively simple work and
handlers do the real data manipulation. So from the example in your
original message:

  [% data=fetch({sql=>"SELECT MessageId, Subject FROM Messages"}) %]

You might do something like

package MySite::Handler::Messages;

sub listing {
    my ( $class, $p ) = @_;
    my $R = OpenInteract::Request->instance;    
    my $message_iterator = eval { $R->message->fetch_group };
    my ( $error );
    if ( $@ ) {
        $error = "Cannot retrieve messages: $SPOPS::Error::system_msg";
    }
    return $R->template( {}, { iter => $message_iterator,
                               error_msg => $error },
                         { name => 'mypkg::message_list' } );
}

And in your template:

------------------------------

<h1>Summary of messages</h1>

[% IF NOT iter.has_next -%]

<p>Sorry, no messages to display.</p>

[% ELSE -%]

<table border="0">
[% WHILE ( message = iter.get_next ) -%]
   <tr>
     <td>[% message.subject %]</td>
     <td>[% message.from %]</td>
     [% view_url = OI.make_url( base => '/Message/show', 
                                message_id = message.id ) -%]
     <td><a href="[% view_url %]">View message</a></td>
   </tr>
[% END -%]
</table> 

[% END -%]

------------------------------

So in your handler you have the option of ordering the messages as you
wish, screening certain ones out, etc. And the template can make
simple display decisions but doesn't do much with the data besides
display it.

One last thing: I'm not sure how large your application is, but for
small applications OpenInteract is most likely overkill. The only way
I'd write something simple (e.g., a guestbook) in OI is if I already
had an OI system installed and wanted to extend it.

Hope this helps,

Chris

-- 
Chris Winters ([EMAIL PROTECTED])
Building enterprise-capable snack solutions since 1988.

Reply via email to