PEF::Front - Perl Web Framework based on PSGI protocol.
PEF::Front framework implemets MVC model in a non-standard way. Main goals are:
* Speed
* Explicit model method description
* Better job separation
* Less code duplication
* Convenience
Typical MVC application UI is designed from Conrollers: they define data provided for View. This framework allows to write HTML makets/templates first. Template automatically installs its Controller. Controller functions are distributed between AJAX, Submit/Get actions and Templates.
This design allows better job separation. Often, a programmer who writes Model methods, is a different man than who writes HTML template. Suppose, you have a working application and suddenly you need to duplicate some information block from one page to many others, what to do in a typical MVC framework? You have to find a way how to provide all needed data to all affected Controllers and change all affected templates. This is job for for at least two different people. With this framework is only HTML-man needed, who can define one including block on all affected templates.
[% news = "get all news".model(limit => 3) %]
<section class="news">
[% FOREACH n IN news.news %]
[% IF loop.index != 2 %]
<article class="arc_news">
[% ELSE %]
<article class="arc_news arc_none">
[% END %]
<h3>[% n.title %]</h3>
<p>[% n.body %]</p>
<div class="button">Next<div class="sm">></div></div>
</article>
[% END %]
</section>
HTML-man puts his template (news.html) in some defined directory, it automatically installs /appNews Controller+View. He uses "get all news" model method to get maximum 3 news and generate HTML text from this. Easy.
Somewhere in application this "get all news" model method defined in GetAllNews.yaml file something like this:
params:
ip:
regex: ^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$
value: defaults.ip
limit:
regex: ^([123456789]\d*)$
optional: true
max-size: 3
default: 5
offset:
regex: ^(0|[123456789]\d*)$
optional: true
default: 0
max-size: 10
model: News::get_all_news
allowed_source: [submit, ajax, template]
And finally, in some defined place is App::Local::News perl module with method get_all_news:
package App::Local::News;
sub get_all_news {
my ($msg, $def) = @_;
return {
result => "OK",
news => [{title => 'once upon a time', body => 'Es war einmal...'}]
};
}
* Automatic Controller installation
* Explicit model methods description with input validation
* Fast and versatile template engine Template::Alloy
* Allowed model methods are accessible from any template
* Better job separation
* Less code duplication