You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Villu Roogna <re...@gmail.com> on 2006/11/08 08:47:35 UTC

Application architecture and separating logic and design

Hello,

I have set up my EMBPERL_OBJECT_APP file as sort of MVC controller:

For example in init I have conditionals like

if(basename($req->param->uri) =~ /^index(_eng)?\.html$/) {
    Front page logic
}


In index.html file I have several Execute statements for other templates
like
Execute({imputfile => 'section_news.html'});
Execute({imputfile => 'section_poll.html'}):


Now I would like to separate logic for section_news.html and
section_poll.html components in EMBPERL_OBJECT_APP file like this

if(basename($req->param->uri) =~ /^section_news\.html$/) {
     News section logic
} elsif(basename($req->param->uri) =~ /^section_poll\.html$/) {
    News section logic
}

that would allow me to remove section_news.html and section_poll.html logic
from index.html section in EMBPERL_OBJECT_APP

So I would like also component sub requests that I make in index.html go
through my EMBPERL_OBJECT_APP file so the logic would work like this:

User requests index.html ->
- Emperl would process all sections  (section_news.html and
section_poll.html) included with Execute statements in index.html in
EMBPERL_OBJECT_APP file

User requests section_news.html directly ->
- Embperl would only process section_news.html in EMBPERL_OBJECT_APP file

The reason behind this would that I would not have to double my code for
index.html front page and for separate sections: section:_news and
section_poll.

Currently I could not get it to work since $req->param->uri gets the url
from main request not sub request. Also $req->component->sourcefile did not
work, since this parameter
did not get value until inside the actual component file.

What would be good way to implement the logic described or maybe there would
be even better ways that I now can not think of. I am open to all
suggestions.


Oh and thank you Gerald for one of the most flexible frameworks in perl :)

All the best,
Villu

RE: Application architecture and separating logic and design

Posted by Gerald Richter <ri...@ecos.de>.
Hi,

The init method of the application object is only called once per request,
so it will not fit your needs.

There are two solutions I see, the first is from your section_news.html and
section_poll.html you call the logic at the top, like

[- $epapp -> logic_for_news -]

This will allow you to call the correct method from within each html file.

This is not fully true MVC, because the display file calls the controller,
but it works.

The other possiblity is to overload the method get_recipe in the application
object. This one is intented to change parameters of the component, before
it gets executed (like recipe, syntax etc.), but you can also use it to do
your per component initialisation.

See eg/web/epwebapp.pl for an example

Gerald


> 
> I have set up my EMBPERL_OBJECT_APP file as sort of MVC controller:
> 
> For example in init I have conditionals like 
> 
> if(basename($req->param->uri) =~ /^index(_eng)?\.html$/) {
>     Front page logic
> }
> 
> 
> In index.html file I have several Execute statements for 
> other templates like
> Execute({imputfile => 'section_news.html'});
> Execute({imputfile => 'section_poll.html'}):
> 
> 
> Now I would like to separate logic for section_news.html and 
> section_poll.html components in EMBPERL_OBJECT_APP file like this 
> 
> if(basename($req->param->uri) =~ /^section_news\.html$/) {
>      News section logic
> } elsif(basename($req->param->uri) =~ /^section_poll\.html$/) {
>     News section logic
> }
> 
> that would allow me to remove section_news.html and 
> section_poll.html logic from index.html section in EMBPERL_OBJECT_APP
> 
> So I would like also component sub requests that I make in 
> index.html go through my EMBPERL_OBJECT_APP file so the logic 
> would work like this:
> 
> User requests index.html ->
> - Emperl would process all sections  (section_news.html and 
> section_poll.html) included with Execute statements in 
> index.html in EMBPERL_OBJECT_APP file
> 
> User requests section_news.html directly ->
> - Embperl would only process section_news.html in 
> EMBPERL_OBJECT_APP file 
> 
> The reason behind this would that I would not have to double 
> my code for index.html front page and for separate sections: 
> section:_news and section_poll.
> 
> Currently I could not get it to work since $req->param->uri 
> gets the url from main request not sub request. Also 
> $req->component->sourcefile did not work, since this parameter 
> did not get value until inside the actual component file. 
> 
> What would be good way to implement the logic described or 
> maybe there would be even better ways that I now can not 
> think of. I am open to all suggestions. 
> 
> 
> Oh and thank you Gerald for one of the most flexible 
> frameworks in perl :)
> 
> All the best,
> Villu
> 
> 


 
** Virus checked by BB-5000 Mailfilter ** 


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org