You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Rob Nagler <na...@bivio.biz> on 2002/06/01 00:08:58 UTC

Re: separating C from V in MVC

Perrin Harkins writes:
> That's exactly what I'm saying, except that I don't see what your 
> "layout manager" is for.  You should just pass some data to a template 
> (or maybe to something fancier for certain types of output like Excel) 
> and then the template makes all the decisions about how to show that data.

The layout manager is an important tool, which doesn't fit in with the
template model.  It comes from widget-based GUI toolkits like Java,
Tk, etc.

Layout managers accept a declaration ('this cell is northwest', 'this
other one expands across the bottom', etc.).  They interpret the decl
at run-time.  It's like HTML, but more declarative.  Some attributes
of our Grid manager are:

  cell_nowrap - don't wrap the text in the cell
  cell_align - gens valign and align from a single compass direction
  cell_expand - this cell eats up the rest of the columns in the row
  row_control - a conditional value to control whether row is displayed
  cell_width - contains the HTML width= value (may be dynamic)

With Java's GridBag and other layout managers, you relate the cells in
some way and the layout manager "does the right thing".  Since this
particular layout manager is HTML, we relate the cells in a row-major
matrix.  Since it's Perl, it's compact.  Here's a simple example:

    Grid({
	string_font => 'page_text',
	pad => 5,
	values => [
	    [
		String(Join([
		    'Please confirm that the following data is correct '
		    .'and press the <b>Continue</b> button to ship the '
		    .'order',
		])),
	    ], [
		String('Billing Address', 'page_heading'),
	    ], [
		&$address_widget('bill_to', 1),
	    ], [
		String('Shipping Address', 'page_heading'),
	    ], [
		&$address_widget('ship_to', 2),
	    ], [
		ImageFormButton({
		    image => 'continue',
		    field => 'ok_button',
		    alt => 'Continue',
		}),
	    ],
	],
    }),

Rob



RE: separating C from V in MVC

Posted by Per Einar Ellefsen <pe...@skynet.be>.
At 21:14 01.06.2002, Jeff wrote:
> > From: Per Einar Ellefsen [mailto:per.einar@skynet.be]
> > Sent: 01 June 2002 18:10
> > To: Jeff
>
> > Well, as I see this, it isn't a problem. The layout manager takes
> > the place of the view, as it essentially decides how things should
> > be rendered. You then have two stages in your view, but the same
> > techniques apply (as the 2nd stage of the view isn't really specific
> > to any model or controller).
>
>This is my current thinking. Now that I have heard more details from
>the MVC folks on the list, I will have to sit down and spend some
>mental effort in assimilating MVC+template into what we currently
>do, and see what sort of beast emerges.

Well, as you see, MVC is more something of a way of thinking. I guess it's 
up to everyone to adapt it to their own needs. You decide what you think is 
best, but your "layout manager" idea clearly brings new light to this 
discussion.


-- 
Per Einar Ellefsen
per.einar@skynet.be



Re: separating C from V in MVC

Posted by Perrin Harkins <pe...@elem.com>.
> It is interesting to try and fit our approach into the MVC+template
> pattern

Just to clarify, it's not MVC+template; it's just MVC.  The templates
are one way of implementing views.  You could mix and match this where
appropriate, so that your Excel view is a perl module with a set of
formatting guidelines stored in a sort of style sheet, while your HTML
view is simply a template executed by a templating module.

> I see the Controller as also responsible for deciding what to do with
> the results of rendering the DOM in Excel or HTML formats - Views
> don't decide how their results should be distributed.

This is typically something you would put into the controller, since the
view shouldn't have to worry about details like HTTP headers.

- Perrin


RE: separating C from V in MVC

Posted by Jeff <ja...@aquabolt.com>.
> From: Per Einar Ellefsen [mailto:per.einar@skynet.be] 
> Sent: 01 June 2002 18:10
> To: Jeff

> Well, as I see this, it isn't a problem. The layout manager takes 
> the place of the view, as it essentially decides how things should 
> be rendered. You then have two stages in your view, but the same 
> techniques apply (as the 2nd stage of the view isn't really specific 
> to any model or controller).

It is interesting to try and fit our approach into the MVC+template
pattern, and I guess it comes down to where you draw the line. I think
that the layout manager / creation of the document object model is
not really part of a View, as a single DOM can be passed to a number 
of rendering components. I see it more as something the controller
creates and passes to all of the Views that you want to implement.

For example lets say that I want to present both a web page, and also
render an Excel report in response to a single query [the page gets
sent back to the requestor, the Excel gets saved into the db as a
blob for later download].

I would see this happening like this:
  Controller: 
    1) creates collection of Models and model meta-data
    2) creates DOM using layout hints in meta-data
    3) passes DOM to HTML View and reaps the HTML rendering
    4) passes DOM to Excel View and reaps the Excel rendering
    5) saves the Excel rendering in the DB as a blob
    6) returns the HTML view to the page requester

As you can see from this outline, the controller manages the creation
of the DOM outside either the HTML or Excel views. 

I see the Controller as also responsible for deciding what to do with 
the results of rendering the DOM in Excel or HTML formats - Views 
don't decide how their results should be distributed. In the above 
example, the Controller might decide to return the Excel object to
the client, and save the HTML view into a cache or blob etc etc.

This is my current thinking. Now that I have heard more details from
the MVC folks on the list, I will have to sit down and spend some 
mental effort in assimilating MVC+template into what we currently 
do, and see what sort of beast emerges.

Regards
Jeff


RE: separating C from V in MVC

Posted by Per Einar Ellefsen <pe...@skynet.be>.
At 15:09 01.06.2002, Jeff wrote:

> > From: Perrin Harkins [mailto:perrin@elem.com]
> > Sent: 01 June 2002 00:17
> > To: Rob Nagler
> > Cc: modperl@perl.apache.org
>
> > The same template?  How does the layout manager help with that?
> > Does it modify the template?  It would make more sense to me if
> > this were a sort of abstraction to factor out common layout
> > ideas from multiple templates.
>
>The layout manager is more complex than a static template. It takes
>a collection of data and meta-data and creates a document tree that
>is not a specific rendering flavour - the DOM might subsequently
>be rendered in NS4.0 HTML, IE5.01+ HTML, Excel, PDF etc. without
>requiring (every page) x (every format) x (every option) templates.

Well, as I see this, it isn't a problem. The layout manager takes the place 
of the view, as it essentially decides how things should be rendered. You 
then have two stages in your view, but the same techniques apply (as the 
2nd stage of the view isn't really specific to any model or controller).

-- 
Per Einar Ellefsen
per.einar@skynet.be



Re: separating C from V in MVC

Posted by "Ken Y. Clark" <kc...@logsoft.com>.
On Mon, 3 Jun 2002, Rob Nagler wrote:

> Date: Mon, 3 Jun 2002 08:09:12 -0600
> From: Rob Nagler <na...@bivio.biz>
> To: modperl@perl.apache.org
> Subject: Re: separating C from V in MVC
>
> Perrin Harkins writes:
> > You can actually do that pretty comfortably with Template Toolkit.  You
> > could use a filter for example, which might look like this:
> >
> > [% FILTER font('my_first_name_font') %]
> > ... some text, possibly with other template directives in it...
> > [% END %]
>
> One of the reasons Perl is popular is its idioms.  Having to say
> something in three lines is not as idiomatic as one line.  It takes a
> lot of discipline to use it everywhere.  In other words, I don't think
> the above is more comfortable than:
>
>     String(['User.first_name'], 'my_first_name_font');
>
> Note also the accessor for User.first_name in Template Toolkit is
> probably nontrivial.
>
> Rob

Not to see this discussion devolve into Yet Another Template War, but
there's more than one way to do filters in Template Toolkit:

    [% User.first_name | my_filter %]

Add to the handy "pipe" syntax the number of built-in filters (esp.
the "html" and "uri" ones), and you get a large amount of convenience
because you don't have to pre-format your data before passing it to a
template (which seems to more strongly couple to the "C" to the "V").

    It's just my opinion, baby, I may be right or wrong.
        -- Robert Johnson

ky


Re: separating C from V in MVC

Posted by Andy Wardley <ab...@andywardley.com>.
On Thu, Jun 06, 2002 at 08:15:24PM -0600, Rob Nagler wrote:
> The issue here is not whether TT is a bad approach, but rather why the
> syntax is not Perl.  

One reason is that I like to have minimal syntax in the templates.  One
argument often used is that non-programmer find it easier to say foo.bar
than $foo->{ bar }.  But I think the more compelling argument is that
even experienced programmers find it easier to write.  It's just less
syntax.  I don't mind syntax in my Perl programs, it serves an important
purpose there.  But in my templates, I prefer to have everything as 
simple as possible.

Another reason is that foo.bar deliberately abstracts the difference
between $foo->{ bar } and $foo->bar().  You can change the underlying
implementation of a data structure and you don't need to update your
templates.

A third reason is that by abandoning strict Perl syntax I can be much
more flexible in providing a domain specific language tailored to the 
task of generating and manipulating content.  

A


Re: separating C from V in MVC

Posted by Chris <ch...@prather.org>.
::realizes this may be going a bit futher a field ... but tries to maintain 
topicality::

> Chris writes:
>> Perl handels Regex's better than C, this is one of the reasons people
>> use  Perl.
> 
> I disagree.  Perl's Regex processor is written in C.  The difference is
> that it has outgrown Henry Spencer's regexp library.

Mmm semantic differences I yield the floor seneator, but I wish it to go on 
the record that Regex's are built into the main syntax of the Perl 
language, and are fully supported by the culture. While you must 
specifically link to and consiously add in Regex's in C. You can build a 
Hash, Queue and Stack in C as well, but that doesn't mean that they aren't 
generally simpler to use in Perl because they're built right into the 
language.
 
>> It makes (some) hard things easy and (some) impossible things 
>> hard ... within it's domain. XSLT is no different. Use the appropriate
>> tool  (or Toolkit) for the problem.
> 
> Agreed.  Perl is good at text manipulation.  It is imiho superior to
> XSLT in all spaces which XSLT claims to solve.  Once you have an XML
> parse tree in Perl, it's trivial to write a translator to any format
> more correctly than XSLT.  My favorite example is XML to CSV.  Every
> example I've seen in XSLT is cumbersome and wrong.  You'd think it
> wouldn't be hard, but try it. ;-)
 
Well XSLT wasn't really designed (and shouldn't have been) to output plain 
text. Despite what the W3C says. It's designed to tranlsate between XML 
Vocabularies. I'll explain in a bit why I feel that XSLT is better suited 
for this than Perl.

>> existance beyond the Towers of Hanoi problem. But I haven't seen it
>> solved  in TeX either (::know's there's gotta be a link for this::).
> 
> I'm sure Randall wrote a TeX to TT translator to generate his TT
> version of ToH. ;-)

Merlyn any comments here? Other Powers-That-Be? I could see this as a 
JAPH ... only for size N problems it would take N^2 years to print.

>> Rob, is what you are suggesting that one should not use a turing
>> complete  language for visual markup or that simply the language
>> should be the best  match for the solution? I'm just looking for
>> clarity on your position.
> 
> The question really surrounds "little languages".  Perl is ideally
> suited to creating them.  There's no reason to invent a new syntax ([%
> %]) or semantics for standard structures.  I think you should write
> classes in Perl that map to some interface which defines the language.

This is where I think we have a disagreement. In usability circles there is 
an idea that different things should be ... well ... different. If one 
button turns on the radio ... it shouldn't look anything like the button 
that launches the missles. 

This is why I find XSLT well suited for XML->XML transformations because it 
is visually/ideologically well suited to it's primary domain. If I'm 
dealing with the angle brackets and the tree structure ... then I'm 
thinking about the angle brackets and the tree structure ... eventually I'm 
zenning in the whole Angle Brackety Tree Structury-ness of the world. (I 
have a degree in english I know exactly how awful that sentance was.) 

It may be true that Perl can do it quicker and faster ... but for me the 
advantage to visually distinguishing the logically different parts helps 
future maintainability.

C and Perl are distinctly different because the domains they are best 
suited (and designed) for are distinctly different. Nobody wishes Perl's 
syntax were more like that of C, Java, or Cobol. If they do they should 
probably be writing C, Java or Cobol. (Inline::Cobol anyone?) 

In MVC if each letter were written in it's own language it would be very 
easy to maintain the seperation. If it's generally impractical to use three 
distinct languages* one should keep as much visual distinction between the 
three as possible.


*Generally people already do use three langauges though with the Template 
Language (HTML|ASP|TT|XSLT), the Controller Language (Perl) and the Model 
Language (SQL).

> It's pretty much gotten to the point where nobody gets fired for
> choosing Java.  I've lost many contract bids because I didn't say Java
> was the right solution.  I haven't lost a single customer who let us
> solve the problem for them.
 
People don't approach a contractor and tell them what tools to build a 
house with. Why do they insist on doing it with programmers?


-Chris

-- 
"[A] Genuinely skillful use of obscenities is uniformly absent on the 
Internet." -Karl Kleinpaste 


Re: separating C from V in MVC

Posted by Matt Sergeant <ma...@sergeant.org>.
On Fri, 2002-06-07 at 03:15, Rob Nagler wrote:
> Agreed.  Perl is good at text manipulation.  It is imiho superior to
> XSLT in all spaces which XSLT claims to solve.  Once you have an XML
> parse tree in Perl, it's trivial to write a translator to any format
> more correctly than XSLT.  My favorite example is XML to CSV.  Every
> example I've seen in XSLT is cumbersome and wrong.  You'd think it
> wouldn't be hard, but try it. ;-)

XSLT is an XML to XML transformation tool. Seems fairly obvious to me
it's not going to do XML to CSV very well. For that you use SAX.

I disagree with you in all uses of transforming an XML tree into another
XML tree.

Right tool for the job, as always.

Matt.

Re: separating C from V in MVC

Posted by Ilya Martynov <il...@martynov.org>.
>>>>> On Thu, 6 Jun 2002 20:15:24 -0600, Rob Nagler <na...@bivio.biz> said:

>> (http://sourceforge.net/projects/poop/).

RN> Great, another mailing list. :-)  Thanks.

It is not just mailing list. Don't miss
http://poop.sourceforge.net/. It has nice review of most Perl OO
persistence modules.

-- 
Ilya Martynov (http://martynov.org/)

Re: separating C from V in MVC

Posted by Rob Nagler <na...@bivio.biz>.
Andy Wardley writes:
> Yep, I agree.

Now we are getting somewhere. :-)

The issue here is not whether TT is a bad approach, but rather why the
syntax is not Perl.  It doesn't have to be, but you would save
yourself a lot of code and debugging.  In addition, there is more
opportunity for reuse if you can just say:

use Bla::Bla;

And, reuse test infrastructure, syntax-directed editors, etc.

Chris writes:
> Perl handels Regex's better than C, this is one of the reasons people use 
> Perl.

I disagree.  Perl's Regex processor is written in C.  The difference
is that it has outgrown Henry Spencer's regexp library.

> It makes (some) hard things easy and (some) impossible things 
> hard ... within it's domain. XSLT is no different. Use the appropriate tool 
> (or Toolkit) for the problem.

Agreed.  Perl is good at text manipulation.  It is imiho superior to
XSLT in all spaces which XSLT claims to solve.  Once you have an XML
parse tree in Perl, it's trivial to write a translator to any format
more correctly than XSLT.  My favorite example is XML to CSV.  Every
example I've seen in XSLT is cumbersome and wrong.  You'd think it
wouldn't be hard, but try it. ;-)

> existance beyond the Towers of Hanoi problem. But I haven't seen it solved 
> in TeX either (::know's there's gotta be a link for this::).

I'm sure Randall wrote a TeX to TT translator to generate his TT
version of ToH. ;-)

> Rob, is what you are suggesting that one should not use a turing complete 
> language for visual markup or that simply the language should be the best 
> match for the solution? I'm just looking for clarity on your position.

The question really surrounds "little languages".  Perl is ideally
suited to creating them.  There's no reason to invent a new syntax ([% %])
or semantics for standard structures.  I think you should write
classes in Perl that map to some interface which defines the language.

Here's another example, trimmed from our Integer.t:

Bivio::Test->unit([
    'Bivio::Type::Integer' => [
    	get_min => -999999999,
	get_precision => 9,
	can_be_negative => 1,
	from_literal => [
	    ['9'] => [9],
	    ['x'] => [undef, Bivio::TypeError->INTEGER],
	    [undef] => [undef],
	],
    ],
]);

What does this do?  It "compiles" the list of tests and then executes
them.  It makes for very dense unit tests.  Perl's powerful
introspection mechanisms allow you to do this.

> benefit I have gained thus far from Perrin's eToys article (that and using 
> it to sell mod_perl to my superiors as a better solution than Java "eToys 
> delt with 10x these many customers ... I think our system can handle the 
> load").

It's pretty much gotten to the point where nobody gets fired for
choosing Java.  I've lost many contract bids because I didn't say Java
was the right solution.  I haven't lost a single customer who let us
solve the problem for them.

Perrin Harkins writes:
> In the companies I've worked for, it seems that political pressures 
> cause an HTML re-design every few months.

Weinberg strikes again: It's always the people problem...

> I also notice that bivio.com has a relatively clean and simple design. 
> If it were up to me, all "application" sites would have this kind of 
> simple design, but more often than not I seem to end up with designers 
> who are determined to take their interface cues from H R Giger prints.

Giger is awesome.  We need to work him into bivio.

A significant difference between our worlds may be that we're selling
a web-delivered application.  I'm guessing that your businesses were
more focused on selling products via the Web.

> (http://sourceforge.net/projects/poop/).

Great, another mailing list. :-)  Thanks.

Rob



Re: separating C from V in MVC

Posted by Andy Wardley <ab...@andywardley.com>.
On Thu, Jun 06, 2002 at 12:02:47AM -0600, Rob Nagler wrote:
> These are the reserve words of TT:
[...]
> Looks an awful lot like the same keywords in any general-purpose
> programming language.

Yep, I agree.  You can use it like a programming language and it 
gives you more than enough rope to hang yourself, or at least
get tangled around your feet and trip you up :-)

However, the way that I (mostly) use it, and the way that is encouraged
in the documentation, is to use it like a programming language only with
respect to presentation issues, not application issues.

For example, using a FOREACH to calculate some sum of values is probably
a Bad Thing, but using it to iterate over a data set and generate a 
table is a Good Thing.  It a presentation loop, not a programming loop.

Same goes for conditionals, and so on.  Even defining the equivalent
of functions or macros.  If it's something that generates a presentation
element and doesn't have any side effect on the application processing
or underlying model then I generally think it's OK.  Of course, it all 
depends on how you defined "presentation" and "programming".

But anyway, I'm not defending TT against HTML::Template or any other 
module because they admirably serve different purposes to different 
people at different times.

TT is most definately not an enforced pure template language.  You 
can use it that way if you like, but you can also use it as a quick,
dirty and butt-ugly hacking tool.  I construe that to be a good 
feature of a general purpose templating solution that TT aspires 
to be.  But I also readily admit that too much freedom to Do the 
Wrong Thing can be a weakness in particular environments.

That's why we have different modules.  Sometimes you need a hammer,
sometimes you need a saw, sometimes you need a socket set.  Sometimes
you use a wrench to bang in a nail because you can't find your hammer.
That's a useful feature of a wrench, even if it's not what it was 
designed to do.

> I think the rule is: if you can solve Towers of Hanoi in the language,
> its general purpose enough.  

Indeed.  And TT was designed to be general purpose enough to solve
the Towers of Hanoi.  I personally don't use it like that when I'm
building web sites, preferring to adopt a much more rigorous coding
standard, but there are also plenty of times when I do for small hacks.

> To solve this problem, we added a letter.  bOP is MVCF, where F stands
> for Facade.  

Yep, I'm doing something that's roughly similar.  Rather than have a
facade which presents a collection of backend objects, I'm building 
what is, I suppose, a composite built from a collection of backend
objects.  The way our data is structured seems to favour this approach
to my current way of thinking, but I will give the facade option some
more thought now that you've mentioned it.

But I think the concept is the same.  You have some object or data
structure which represents the collection of all the different 
components that combine to form one particular configuration of a 
site.  This is our site model, a separate entity from our MVC,
similar to your F.

> There are some basic design rules.  Eliminating redundancy is one of
> them.

Eliminating redundancy is another.  :-)

> I don't see how it is an "Aspect" (in the capital A sense).  

Only really in the sense that it's an orthogonal dimension in our
data space.  A degree of freedom, if you like.  Something that
cuts across a system but needs to be defined in one place (or 
plane).

> I suspect you'll find AOP won't be in heavy use in five years except
> for debugging features.  The magic of OO is hard enough to understand,
> and AOP is really magical.  AOP also doesn't solve very many
> problems.

I agree, but I found it useful in the way that it helped me to identify
and put a name on a common problem.  Once the lightbulb went on in my
head and I said "Oh, this is like the problem described in AOP" then 
it gave me a direction to tackle it.

> Why is there so little discussion of the M in MVC?  It's far from a
> trivial problem.

Indeed.

A




Re: separating C from V in MVC

Posted by Chris <ch...@prather.org>.
::really hesitates to step into this ... but like a train wreck ... he 
simply can't resist::

>> It's like asking why XML has different syntax and semantics from Perl.
> 
> Well, if you read the XSLT spec and then look at an XSLT program,
> you'll see a lot of verbosity and a lot of general purpose constructs
> like variables, conditionals, and loops.  I haven't done much with
> XSLT, but I do know you can get it in an infinite loop.  That seems
> pretty general purpose to me.
 
Well aside from the fact that XSLT is Turing complete (And thus 
theoretically as "powerful" as Perl or C or Java) the syntax structure of 
XSLT (because it is a derivitive of XML) makes it difficult to do some 
things (try writing a version of sed in XSLT). This I think was the 
original point. 

Perl handels Regex's better than C, this is one of the reasons people use 
Perl. It makes (some) hard things easy and (some) impossible things 
hard ... within it's domain. XSLT is no different. Use the appropriate tool 
(or Toolkit) for the problem.

> I think the rule is: if you can solve Towers of Hanoi in the language,
> its general purpose enough.  True formatting languages, such as,
> Scribe do not contain general-purpose constructs, so you couldn't
>solve the Towers of Hanoi.  HTML is another good example (ignoring
><script>).

I do want to point out for clarity and posterity that HTML and XSLT are 
siblings ... in that they are both applications of XML (or SGML). HTML is 
not Turing Complete while XSLT. Turing completeness has a mathmatic 
existance beyond the Towers of Hanoi problem. But I haven't seen it solved 
in TeX either (::know's there's gotta be a link for this::).

Rob, is what you are suggesting that one should not use a turing complete 
language for visual markup or that simply the language should be the best 
match for the solution? I'm just looking for clarity on your position.

> Why is there so little discussion of the M in MVC?  It's far from a
> trivial problem.

As I am currently mostly writing M and C and would be interested in some 
thoughts on the issues surrounding M. Like what issues have other people 
come across and how have other's dealt with them? This is the biggest 
benefit I have gained thus far from Perrin's eToys article (that and using 
it to sell mod_perl to my superiors as a better solution than Java "eToys 
delt with 10x these many customers ... I think our system can handle the 
load").

-Chris

-- 
"[A] Genuinely skillful use of obscenities is uniformly absent on the 
Internet." -Karl Kleinpaste 


RE: separating C from V in MVC

Posted by Rob Nagler <na...@bivio.biz>.
Jeff AA writes:
> Sounds interesting, can you briefly describe the MVCF parts, and what
> their responsibilities are?

http://www.bivio.biz/hm/why-bOP contains a decent explanation of how
we think about MVC.  There's also a talk with notes:
http://www.bivio.biz/hm/csci7818-bop-intro/intro

> Have you split the View into View + Facade?

Views and the Controller request values from the Facade configured for
the incoming request or command line function.  Models don't really
need to talk to the Facade, since Models should be purely internal and
the Facade is about user interface elements.  Models do manipulate the
HTTP form values (which are not UI elements imo) and query strings
(which are part of the UI, but we don't map query keys via the Facade).

A couple of people have mentioned the concept of a "container".  We
call this concept Attributes:
http://petshop.bivio.biz/src?s=Bivio::Collection::Attributes

MVC components are derived from attributes.  A Task has attributes
(name, number, permissions, items to execute, next).  A View has
attributes (parent, variables).  Widgets are configured with
attributes (cell_bgcolor, string_font, etc.).  Models have attributes
(fields).  A Request has attributes (path_info, port, auth_user, etc.).

Attributes proved to be a significant breakthrough in the
simplification of the interfaces.  The views and widgets don't know
about models for the most part.  They can just as easily format the
incoming server name from the request and the user's name from a
model.  And you can flow seamlessly between them, e.g.

    ['auth_user', 'name']

This widget value is the name attribute from the model identified by
the request's auth_user attribute.

Facade components are bit different, because their values are often
hierarchical and grouped, e.g. you want to group the namespace of the
"alt" tags for icons separately from other in spaces:
    $fc->group(Image_alt => [
	dot => '',
	goback => 'Back',
	continue => 'Continue',
    ]);

or you want to group a bunch of symbolic font names to a single font
specification:

    $fc->group([qw(
        strong
        bold
        table_row_title
    )] => ['bold']);

You also want to be able to manipulate these values in clones and
children of facades.  The Attributes class is a simple one to one
mapping..

However, FacadeComponents do support the WidgetValueSource interface
which means Font values can be accessed by Widgets just like other MVC
components.

> What are the differences between your MVCF and the MVP pattern?

I didn't know what the MVP pattern was.  I don't think the MVP pattern
is applicable to Web interfaces.  GUIs are fundamentally different
from HTTP.  HTTP is stateless, screen-oriented, and client-server.

One of the reasons why Perl is so well suited to the Web is that you
don't need asynchrony (threads) and you do need to manipulate lots of
strings.  The Web is a "transformational" system.  GUIs are
interactive systems.

> > URLs are part of your user interface, not your controller.
> I think I like this, though the w3 might not 8-)

The W3C is dreaming if they think there ever going to get rid of
people typing in Web addresses.

Even if they somehow magically get rid of them, people will still
bookmark them.  This means you need multiple URL mappings to the same
operation for backwards compatibility.  We have rearranged our site URLs
several times, but we kept the old mappings.  The URLs for the entire
site are contained in a single file.  A Task can have multiple
mappings, but always has a single primary URL.

> I find that the mix of business object e.g. Bank Account and
> presentation objects, e.g. Table can lead to confusion - are your Table
> objects just a way of organising data, or do they contain presentation
> style hints -e.g. dynamic width indication etc?

Table is a Widget.  BankAccount is a Model.

> Do you have something similar to a Bank Account object with some primary
> properties and containing a collection of current Transaction
> objects?

There are no transaction objects.  You can push transaction resources
on the request and if the Task completes successfully, they will be
committed.

> Or do you focus on the presentation style objects - Tables, nested
> Tables, Lists etc?

We do the whole thing.  Config, tracing, alerts, OR mapping, command
line abstraction, etc.  It's the same thing you having just about
every modern OLTP system.  We looked back pretty far to get where we
are now. :-)

> I looked over your site and code, compact and impressive - probably a
> stupid question, but are there any higher-level overviews of your
> approach / framework?

There isn't more documentation except for the classes themselves.  The
best way is to download bOP and start twiddling with it.

Thanks, btw.  Our goal is compactness, but not in the sendmail.cf
sense. :-)  It's certainly not everybody's cup of tea.  For a microview
of the declarative style, checkout:
http://petshop.bivio.biz/src?s=Bivio::XML::DocBook
which dovetails with the XML discussion. ;-)

Rob



RE: separating C from V in MVC

Posted by Jeff AA <ja...@aquabolt.com>.
> From: Rob Nagler [mailto:nagler@bivio.biz] 
> Sent: 10 June 2002 20:41

> ... a Facade is the front face of the web site which includes colors,
> text, URLs, etc.  All the other MVC components talk to the currently
> selected Facade when they need these values.

> The controller calls Bivio::UI::Task->parse_uri, which strips the
> "*<facade>" from the URL (if there) and sets the facade before parsing
> the rest of the URL.  The default Facade is www.bivio.biz, which is
> why we don't need a rewrite.

> The links are generated by the Facade component Bivio::UI::Task.

Sounds interesting, can you briefly describe the MVCF parts, and what
their responsibilities are? Have you split the View into View + Facade?
What are the differences between your MVCF and the MVP pattern?

> This allows the Facade to pick its own URLs.  
...
> URLs are part of your user interface, not your controller.

I think I like this, though the w3 might not 8-)


> We rarely change the controller except to add new function.  
> Query and form values are parsed by the Models after they are 
> translated to key/value format by the controller.  

I definitely like this - small number of relatively generic Controllers
seems to me to be a desirable goal of an MVC arch.

> abstracted the concept of paging and drill down in our ListModel and 
> Table classes.  

I find that the mix of business object e.g. Bank Account and
presentation objects, e.g. Table can lead to confusion - are your Table
objects just a way of organising data, or do they contain presentation
style hints -e.g. dynamic width indication etc? 

Do you have something similar to a Bank Account object with some primary
properties and containing a collection of current Transaction objects?
Or do you focus on the presentation style objects - Tables, nested
Tables, Lists etc?

I looked over your site and code, compact and impressive - probably a
stupid question, but are there any higher-level overviews of your
approach / framework?

TIA
Jeff



Re: separating C from V in MVC

Posted by Rob Nagler <na...@bivio.biz>.
Ray Zimmerman writes:
> (1) What are you using to display the nice syntax-colored Perl source 
> at http://petshop.bivio.biz/ ?

We fix up the output from perl2html with our SourceCode widget:

http://petshop.bivio.biz/src?s=Bivio::UI::HTML::Widget::SourceCode

The pod looks better when formatted as "#" comments.  (Yes, we know
there is a but with the first #.  :-)  We also add links to other
classes and views, since perl2html doesn't do this for you.

> (2) Are you using the term Facade in the same sense as in Design 
> Patterns p. 185?

No, a Facade is the front face of the web site which includes colors,
text, URLs, etc.  All the other MVC components talk to the currently
selected Facade when they need these values.

We map Facades in the front-end, e.g. petshop.bivio.biz and
www.bivio.biz are two Facades in the same server:

<VirtualHost *>
    ServerName www.bivio.biz
    <Location />
        SetHandler perl-script
        PerlHandler Bivio::Agent::HTTP::Dispatcher
    </Location>
</VirtualHost>
<VirtualHost *>
    ServerName petshop.bivio.biz
    RewriteRule ^(.*) /*petshop$1 [L,PT]
    <Location />
        SetHandler perl-script
        PerlHandler Bivio::Agent::HTTP::Dispatcher
    </Location>
</VirtualHost>

The controller calls Bivio::UI::Task->parse_uri, which strips the
"*<facade>" from the URL (if there) and sets the facade before parsing
the rest of the URL.  The default Facade is www.bivio.biz, which is
why we don't need a rewrite.

> It seems that some of it 
> is data that is used strictly by the View (colors, fonts) and other 
> parts (URL mapping) are used by the View (for generating links) and 
> Controller (for calling the View or doing a redirect).

The links are generated by the Facade component Bivio::UI::Task.
Redirects are issued by the controller or sometimes the models.  In
all cases, we identify Tasks, not URLs.  This allows the Facade to
pick its own URLs.  It means an URL can be anything, and you don't
have to have ".tt", ".asp", etc. suffixes or put then in a particular
directory, e.g. "cgi-bin" or WebObjects+Foo+Bar.  URLs are part of
your user interface, not your controller.

Typically, you might put all icons in a special directory, i.e. we use
/i/, and then have a special mapping on your front-end servers that
avoids hitting your mod_perl servers.

One comment on Perrin's statement:
> In an MVC system, you would definitely need to edit the controller any 
> time you change the input side of the user interface.  You may or may 
> not need to change the model and view as well.

We rarely change the controller except to add new function.  Query and
form values are parsed by the Models after they are translated to
key/value format by the controller.  Only when HTTP changes do we need
to change the controller.

We've also abstracted the concept of paging and drill down in our
ListModel and Table classes.  We haven't had a need to change that
abstraction for some time.  There are only so many user input patterns
you need for even the most complex applications.

Rob



requesting feedback on MVC implementation

Posted by Ray Zimmerman <rz...@cornell.edu>.
All this MVC discussion has been very helpful. There are obviously 
many ways to do MVC web apps and I'd love to get a bit of feedback on 
the approach we are currently planning for ours before we jump into 
coding. Our app is a platform for running econ experiments, each of 
which is structured a bit like a multi-player game.

We already have a pretty well developed Model containing the 
application logic, and for the web UI we're planning to use Mason for 
a number of reasons which I won't get into here. The only reason I 
mention it is that our approach does use Mason specific features like 
autohandlers/dhandlers.

The directory structure looks something like ...

/C
     /autohandler
     /login
	/register_action
	/login_action
     /E
         /Game1
             /autohandler
             /submit_decision_action
             /display_results_action
         /Game2
             /autohandler
             /submit_decision_action
             /display_results_action
/V
     /autohandler
     /login
     /E
         /Game1
             /autohandler
             /decision_submission_view
             /results_view
         /Game2
             /autohandler
             /decision_submission_view
             /results_view

... where the stuff under /C makes up the Controller(s) and the stuff 
under /V the Views. The C components and corresponding autohandlers 
are pure Perl (no HTML output) and the V components and autohandlers 
are simple templates with minimal code (presentation-related only).

URLs would always point to some action component under /C which would 
then call the appropriate view component under /V using the new 
sub-request mechanism in Mason 1.1. This would allow us to use 
autohandlers as a directory based inheritance mechanism for sharing 
Controller code. And we can also use autohandlers as a directory 
based inheritance for templates for wrapping page content.

So a Controller would consist of an action component and all of its 
autohandlers, and a View would consist of the view component and its 
autohandlers.

In order to avoid hard coding paths & URLs, we would use something 
like the action table Chris Winters mentioned. This would be a Perl 
object with action key to component path mappings, as well as view 
name to component path mappings. We'd probably put this action table 
as well as some of the font/color type of data together into some 
UIConfig class, similar to what Rob Nagler is doing with his Facade. 
The appropriate sub-class of UIConfig to use for a given request 
would be specified in the autohandlers under /C, with /C/autohandler 
providing a default, which could be overridden by 
/C/E/Game<n>/autohandler.

One nice feature of this architecture is that it should allow us to 
easily create a new Game3 which inherits all actions and views from 
Game2. Overriding an action or view could be done by creating a new 
UIConfig sub-class which inherits from the one used by Game2 and 
overrides the corresponding entry in the action table.

I'm sure there are details that I haven't thought about yet, but any 
comments on this structure?

Tear it apart!   :-)

-- 
  Ray Zimmerman  / e-mail: rz10@cornell.edu / 428-B Phillips Hall
   Sr Research  /   phone: (607) 255-9645  /  Cornell University
    Associate  /      FAX: (815) 377-3932 /   Ithaca, NY  14853

Re: separating C from V in MVC

Posted by James A Duncan <jd...@fotango.com>.
On Tuesday, June 11, 2002, at 01:37 PM, Chris Winters wrote:

> On Mon, 2002-06-10 at 13:29, Ray Zimmerman wrote:
>> So how is everybody else handling URL mapping? Do others group this
>> kind of data together with fonts, colors, etc?  And where do you
>> define it?
>
> A single mod_perl handler catches all requests, looks up the URL in the
> action table and dispatches the request to the appropriate handler. That
> handler is free to pass on the request to other actions as well, since
> every part of the system is able to lookup actions based on a key.

Currently OpenFrame does something similar.  We have a slot which 
dispatches to an application based on the URL.  However, I think for 
future versions applications will be 'slots', and they can just do 
something or nothing depending on the URL, which allows multiple 
applications to run on the same request, which fixes my 'how the heck do 
I make subrequests work' nightmare.

We're also going to provide a 'forced' mvc style Application type in the 
next version[0] which will be a container that has a model, a view, and 
a controller.  The data that each of the MVC elements provides will 
simply be passed from one to the other inside the container.

As what may be a departure from the norm, in OpenFrame templates, or a 
templating system is *not* the view part of MVC.  Templates simply 
decide where to place the data on the screen  - the view class does all 
the formatting and prep work.

Regards,
James.

[0] of course this is the next version that has been being written for 
the last 3 months and not gotten anywhere.  Sooner or later I will get 
around to turning thought into code, and then all will be right and good 
in the world[1].

[1] or at least in my world


Re: separating C from V in MVC

Posted by Chris Winters <ch...@cwinters.com>.
On Mon, 2002-06-10 at 13:29, Ray Zimmerman wrote:
> So how is everybody else handling URL mapping? Do others group this 
> kind of data together with fonts, colors, etc?  And where do you 
> define it?

As Perrin mentioned, OpenInteract does this by allowing individual
packages (distributable applications) to define the handlers they
support. A package does this by defining actions which at server startup
get collected into a data structure called the action table.

A single mod_perl handler catches all requests, looks up the URL in the
action table and dispatches the request to the appropriate handler. That
handler is free to pass on the request to other actions as well, since
every part of the system is able to lookup actions based on a key.

Entries in the action table can also be used as components --
displayable items that don't stand by themselves but contribute to a
full page. Examples include boxes, common search forms, dependent object
listings, etc.

Currently, here's what an action looks like, as found in the 'base_user'
package distibuted with OpenInteract:

$action = {
    'user'    => {
        'class'    => 'OpenInteract::Handler::User',
        'security' => 'no',
    },
    'newuser' => {
        'class'    => 'OpenInteract::Handler::NewUser',
        'error'    => [ 'OpenInteract::Error::User' ],
        'security' => 'no',
    },
};

All information is available through a lookup to the action table.

One of the modifications I'm working on now will allow you to add more
information to the action and have it available in an object that is
instantiated by the dispatcher which then tells the object to run
itself.

Chris
 
-- 
Chris Winters (chris@cwinters.com)
Building enterprise-capable snack solutions since 1988.


Re: separating C from V in MVC

Posted by Ron Pero <rp...@boone.net>.
At 01:01 PM 06/11/02 -0400, John Siracusa wrote:
>On 6/11/02 12:46 PM, Perrin Harkins wrote:
>> John Hurst wrote:
>>> Still, I don't think that replacing this:
>>> 
>>> <Location /search>
>>>    SetHandler  perl-script
>>>    PerlHandler Controller::Search
>>> </Location>
>>> 
>>> with this:
>>> 
>>> [% Ctrl.Search() %]
>>> 
>>> makes Controller::Search any less a controller.
>> 
>> You're right.  It just looks kind of odd to me, invoking a template for
>> something that is not a display-related task.  It looks like the way
>> people typically do MVC in Mason or Embperl, with a first template that
>> doesn't do anything but invoke a module to take over the processing.
>
>...but it has several advantages.  I particularly appreciate being able to
>add to or change parameters or behaviors before passing things off to the
>controller, for example.  I can have several "variants" of the same
>controller living at different URLs, all pointing back to a single
>controller object.

This is how CGI::Application works, but instead of calling a template page,
it calls a script. The script is tiny -- defines a "run mode", and perhaps
parameters -- then calls the main script that does the heavy lifting, which
in turn instantiates standard modules that provide standard functionality.

I was intrigued by it, because at the time I was using a different approach
with shopping software: each link or form action called the same script,
which would figure out what needed to be done. Kind of like the tail wags
the dog instead of the other way around.

This is outside of MVC, but is nonetheless intriguing. I'm wondering if, in
another 2-3 years, after the authors of the several Perl application
frameworks have had more time to refine their designs, there will be
convergence of issues like this.

Am I wrong, or is this field of web applications a developing field for
which there is no textbook principles of how to do it? Perl has enabled
several people to take different approaches to it, whereas Microsoft's ASP
is just one approach, PHP is just one approach, and I don't know if Java
has multiple approaches or what. Will the various Perl approaches converge
toward a common set of principles, and/or reveal as yet undiscerned
patterns and architectures? Or maybe I'm imagining too much here...

Ron

>
>Don't think of it as "invoking a template."  Just think off it as an
>inverted dispatch mechanism: the actions camp out at their locations, as
>opposed to having their locations (in the httpd.conf) pointing at the
>controller modules.  Or something... :)
>
>-John
>
>

Re: separating C from V in MVC

Posted by Gerald Richter <ri...@ecos.de>.
> Gerald Richter wrote:
> > Embperl 2.0 can invoke such a controller (it's called application object
> > there) after it has setup it's request parameters (GET/POST data,
session
> > data, etc.) and before any templates are get a chance to run.
>
> That sounds like a good addition to Embperl.  Can you give a URL for the
> documentation on how to use this?
>

http://search.cpan.org/doc/GRICHTER/Embperl-2.0b7/Embperl/Object.pm contains
a short paragraph about it (search for EMBPERL_OBJECT_APP ) and inside the
Embperl distribution is an example application  (see eg/web).

I am currently working on improveing the docs for Embperl 2.0, since a lot
of nice new features are rarly documented right now

Gerald


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------



Re: separating C from V in MVC

Posted by Perrin Harkins <pe...@elem.com>.
Gerald Richter wrote:
> Embperl 2.0 can invoke such a controller (it's called application object
> there) after it has setup it's request parameters (GET/POST data, session
> data, etc.) and before any templates are get a chance to run.

That sounds like a good addition to Embperl.  Can you give a URL for the 
documentation on how to use this?

- Perrin


Re: separating C from V in MVC

Posted by Gerald Richter <ri...@ecos.de>.
> >
> > [% Ctrl.Search() %]
> >
> > makes Controller::Search any less a controller.
>
> You're right.  It just looks kind of odd to me, invoking a template for
> something that is not a display-related task.  It looks like the way
> people typically do MVC in Mason or Embperl, with a first template that
> doesn't do anything but invoke a module to take over the processing.
>

Embperl 2.0 can invoke such a controller (it's called application object
there) after it has setup it's request parameters (GET/POST data, session
data, etc.) and before any templates are get a chance to run. So this
application object is able to do the necessary processing and give back
parameters to Embperl so the right templates will be displayed, according to
the result of the controllers processing.

This approach has the benefit that Embperl does the tasks that need to be
done for every request, so you don't have to care about it and can
concentrate on the real controller functions. Additionaly it implements an
object orientated approach, so you can get addtional benefits by spliting up
your controllers functionality in different application objects, which
inherit from each other. (same inherence schema can be used for templates)

Gerald


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------




Re: separating C from V in MVC

Posted by Valerio_Valdez Paolini <pa...@students.cs.unibo.it>.
On Tue, 11 Jun 2002, John Siracusa wrote:

> > You're right.  It just looks kind of odd to me, invoking a template for
> > something that is not a display-related task.  It looks like the way
> > people typically do MVC in Mason or Embperl, with a first template that
> > doesn't do anything but invoke a module to take over the processing.
>
> ...but it has several advantages.  I particularly appreciate being able to
> add to or change parameters or behaviors before passing things off to the
> controller, for example.  I can have several "variants" of the same
> controller living at different URLs, all pointing back to a single
> controller object.

I think that it is also more manageable by people who doesn't want to
understand configurations; designers who worked with me found this
approach handy.

> Don't think of it as "invoking a template."  Just think off it as an
> inverted dispatch mechanism: the actions camp out at their locations, as
> opposed to having their locations (in the httpd.conf) pointing at the
> controller modules.  Or something... :)

And it is a sort of grid layout, mentioned by someone in a previous
message; but it still remains an impure approach :(

Ciao, Valerio



 Valerio Paolini, <http://130.136.3.200/~paolini>
--------------------------------------------------
 what is open-source about? Learn, and then give back



Re: separating C from V in MVC

Posted by John Siracusa <si...@mindspring.com>.
On 6/11/02 12:46 PM, Perrin Harkins wrote:
> John Hurst wrote:
>> Still, I don't think that replacing this:
>> 
>> <Location /search>
>>    SetHandler  perl-script
>>    PerlHandler Controller::Search
>> </Location>
>> 
>> with this:
>> 
>> [% Ctrl.Search() %]
>> 
>> makes Controller::Search any less a controller.
> 
> You're right.  It just looks kind of odd to me, invoking a template for
> something that is not a display-related task.  It looks like the way
> people typically do MVC in Mason or Embperl, with a first template that
> doesn't do anything but invoke a module to take over the processing.

...but it has several advantages.  I particularly appreciate being able to
add to or change parameters or behaviors before passing things off to the
controller, for example.  I can have several "variants" of the same
controller living at different URLs, all pointing back to a single
controller object.

Don't think of it as "invoking a template."  Just think off it as an
inverted dispatch mechanism: the actions camp out at their locations, as
opposed to having their locations (in the httpd.conf) pointing at the
controller modules.  Or something... :)

-John


Re: separating C from V in MVC

Posted by Perrin Harkins <pe...@elem.com>.
John Hurst wrote:
> Still, I don't think that replacing this:
> 
> <Location /search>
>    SetHandler  perl-script
>    PerlHandler Controller::Search
> </Location>
> 
> with this:
> 
> [% Ctrl.Search() %]
> 
> makes Controller::Search any less a controller.

You're right.  It just looks kind of odd to me, invoking a template for 
something that is not a display-related task.  It looks like the way 
people typically do MVC in Mason or Embperl, with a first template that 
doesn't do anything but invoke a module to take over the processing.

> Obviously, the stand-alone dynamic pages are not MVC at all. They exist
> because there are often 'glue' pages that don't warrant the comlexity of MVC
> (those that don't need M and have very simple VC needs).

I agree that there is often a need for some quick and dirty internal-use 
pages (admin or reporting usually) that don't require the extra baggage.

- Perrin


Re: separating C from V in MVC

Posted by John Hurst <jh...@avicatech.com>.
Perrin Harkins wrote:
> 
> On Mon, 10 Jun 2002, I wrote:
> >
>>In the filesystem. Directly requested .tt files are all sent to a
>>default template handler:
> 
> Those are both interesting and may be the most appropriate solution for
> the problems you're working on, but I wouldn't call either of them MVC.
>   You are going straight to a view (template) and letting it drive all
> the decisions.  In an MVC application, you would go to a controller that
> would do some work and then decide which view to show.

I have three kinds of templates:

  controller entry stubs - called directly to invoke a controller
  view pages - called by controllers to display results
  stand-alone dynamic pages - called directly, may not invoke controller

I would agree with you if my entry stubs did more than call up the controller,
but those templates are simple one-liners that do nothing else. Once the
controller has been called it takes over, processing request data, calling
models, selecting views, etc. The only influence a stub template has on the
view is that of defining the URL that the controller inherits (plus optional
parameters as shown in my earlier message).

Yes, a developer could make a mess of things by trying to put more stuff into
a controller entry stub. We all seem to agree that any scheme can be polluted
by poor discipline, and the arrangement I have described is as prone to abuse
as any other. Still, I don't think that replacing this:

<Location /search>
   SetHandler  perl-script
   PerlHandler Controller::Search
</Location>

with this:

[% Ctrl.Search() %]

makes Controller::Search any less a controller.

I could enforce the separation of controller entry stubs from stand-alone
templates and view templates by using additional file extensions and handlers,
but no one has abused the system as it is so I'm erring on the side of my own
laziness. Using the entry stub templates is handy because I don't need to mangle
the server configuration to make controllers available from other locations
(which means I can stay at the pub while others toil away).

Obviously, the stand-alone dynamic pages are not MVC at all. They exist
because there are often 'glue' pages that don't warrant the comlexity of MVC
(those that don't need M and have very simple VC needs). It is much more
convenient to code such pages in the same environment as the MVC stuff (that
is, using the same globally defined variables, macros, etc.).


-jh

Re: separating C from V in MVC

Posted by Valerio_Valdez Paolini <pa...@students.cs.unibo.it>.
On Mon, 10 Jun 2002, Perrin Harkins wrote:

> Those are both interesting and may be the most appropriate solution for
> the problems you're working on, but I wouldn't call either of them MVC.
>   You are going straight to a view (template) and letting it drive all
> the decisions.  In an MVC application, you would go to a controller that
> would do some work and then decide which view to show.

You are right, I know this problem, but think at components as second level
controllers, where i can work with Model and View. The ugly thing is having
html, which belongs to View, in two places with Controller in the middle.
The main focus here is to be friendly with ui people, shifting reusability
towards them.

Thank you for your comment!

Ciao, Valerio


 Valerio Paolini, <http://130.136.3.200/~paolini>
--------------------------------------------------
 what is open-source about? Learn, and then give back


Re: separating C from V in MVC

Posted by Perrin Harkins <pe...@elem.com>.
Valerio_Valdez Paolini wrote:
> On Mon, 10 Jun 2002, John Hurst wrote:
> 
> 
>>In the filesystem. Directly requested .tt files are all sent to a
>>default template handler:
...
> I used html pages with augmented tags parsed by a standard handler:

Those are both interesting and may be the most appropriate solution for 
the problems you're working on, but I wouldn't call either of them MVC. 
  You are going straight to a view (template) and letting it drive all 
the decisions.  In an MVC application, you would go to a controller that 
would do some work and then decide which view to show.

- Perrin


Re: separating C from V in MVC

Posted by Valerio_Valdez Paolini <pa...@students.cs.unibo.it>.
> Ray Zimmerman wrote:
> So how is everybody else handling URL mapping?

On Mon, 10 Jun 2002, John Hurst wrote:

> In the filesystem. Directly requested .tt files are all sent to a
> default template handler:
[...]
> % cat admin/proj-edit.tt
> [% Ctrl.DBEdit.run(ObjectType => 'Project') %]

I used html pages with augmented tags parsed by a standard handler:

<img src="some.gif" function="Class::method" arg="foo" kbit>

this way i can instantiate classes, named components, and call
their methods. Programmers write classes wich in turn call templates.
Designer can control 1) graphic layout by moving 'images' (and other
tags of course) 2) view details modifying templates.

There are other high level tools:

	<img get="variable" kbit>
	<img set="variable" value="..." kbit>
	<img placeholder="name" kbit>
	<img include="<URI>" filter="..." kbit>

functions can use variables and fill placeholders. Every component
can interact with the handler, receiving context infos (possibly
including session data) and answering with some content plus HTTP
codes, which seem to me quite explanatory.

If someone wants to know more, please ask. This framework works in
few dinamic sites here in Italy and is very handy to use, especially
during periodic reorganization of the site (structure, design).

Thank you for the excellent OT!

	Ciao, Valerio



 Valerio Paolini, <http://130.136.3.200/~paolini>
--------------------------------------------------
 what is open-source about? Learn, and then give back


Re: separating C from V in MVC

Posted by John Hurst <jh...@avicatech.com>.
> Ray Zimmerman wrote:
> So how is everybody else handling URL mapping?

In the filesystem. Directly requested .tt files are all sent to a
default template handler:

<Location /tt_engine>
 SetHandler perl-script
 PerlHandler UAL::TTEngine
</Location>

AddType text/tt .tt
Action text/tt /tt_engine>

The default template handler provides a list of controllers via the
Stash, allowing the layout people to place a link to a controller
anywhere. Controllers may be re-used with modified behavior:

% cat admin/proj-edit.tt
[% Ctrl.DBEdit.run(ObjectType => 'Project') %]

% cat admin/task-edit.tt
[% Ctrl.DBEdit.run(ObjectType => 'Task') %]

% cat admin/usermanager.tt
[% Ctrl.UserManager.run() %]

% cat admin/mailclient.tt
[% Ctrl.MailClient.run() %]

% cat user/mailclient.tt
[% Ctrl.MailClient.run(AllowPOP3 => 0, AllowIMAP => 0, AllowMIME => 0) %]




-jh

Re: separating C from V in MVC

Posted by Perrin Harkins <pe...@elem.com>.
Ray Zimmerman wrote:
> So how is everybody else handling URL mapping?

In httpd.conf:

<Location /search>
   SetHandler  perl-script
   PerlHandler Controller::Search
</Location>

<Location /cart>
   SetHandler  perl-script
   PerlHandler Controller::ShoppingCart
</Location>

Most applications only have a handful of controllers, so this works fine.

You could also look at the way OpenInteract does it, which allows you to 
gather all the related stuff including this configuration into a single 
package that you can install in one shot.

- Perrin


Re: separating C from V in MVC

Posted by Ray Zimmerman <rz...@cornell.edu>.
At 12:02 AM -0600 6/6/02, Rob Nagler wrote:
>To solve this problem, we added a letter.  bOP is MVCF, where F stands
>for Facade.  A Facade allows you to control icons, files, colors,
>fonts, text, and tasks.  You can add other components, but we usually
>use text as a catch all, e.g. numeric formats.  Facades can inherit
>from other facades and can be cloned from other facades.  We use this
>to support different skins and co-brands.

<snip>

>A Facade is the first thing set in a request.  You then know what
>tasks are available and what URLs map to them.  Take a look at:
>http://petshop.bivio.biz/src?s=Bivio::PetShop::Facade::PetShop
>All the URLs for the site are contained in this file.  Anybody
>rendering a URL, does it through Bivio::UI::Task.

Two specifically for Rob ...

(1) What are you using to display the nice syntax-colored Perl source 
at http://petshop.bivio.biz/ ?


(2) Are you using the term Facade in the same sense as in Design 
Patterns p. 185?  If not, could you define what a facade is in terms 
of its role?  I'm planning an MVC-type architecture for my web-app 
and am looking for a place to put the kinds of data you have in your 
Facade - URL mappings, colors, fonts, etc. It seems that some of it 
is data that is used strictly by the View (colors, fonts) and other 
parts (URL mapping) are used by the View (for generating links) and 
Controller (for calling the View or doing a redirect).

... and one for everybody ...

So how is everybody else handling URL mapping? Do others group this 
kind of data together with fonts, colors, etc?  And where do you 
define it?

Very much appreciating all the MVC discussion ...

-- 
  Ray Zimmerman  / e-mail: rz10@cornell.edu / 428-B Phillips Hall
   Sr Research  /   phone: (607) 255-9645  /  Cornell University
    Associate  /      FAX: (815) 377-3932 /   Ithaca, NY  14853

Re: separating C from V in MVC

Posted by Perrin Harkins <pe...@elem.com>.
Rob Nagler wrote:
> I think this is where our experience diverges.  I have hired designers
> before and every time we had to recode the HTML and the JavaScript
> anyway.  My approach is to apply the Once And Only Once principle,
> which simplifies design changes (discussed more below).

Yes, this looks like a case where different work environments lead to 
different design goals.  Your goal is noble (apply programming concepts 
of organization to HTML generation) while mine is... not so noble.

In the companies I've worked for, it seems that political pressures 
cause an HTML re-design every few months.  In between there are 
designers tapping me on the shoulder every 5 minutes to ask if I can 
"just push that part over to the left a little".  Since HTML was never 
intended for that kind of complex layout (I've fought and lost the "this 
is not PDF" battle many times), these sort of requests inevitably ended 
in cross-browser frustrations and hours of wasted time.

My strong desire to say "why don't you do it yourself?" led me to write 
my first templating engine.  (Thankfully, there's no need to do that 
anymore with so many good ones available.)  I found that the designers 
fell for this ruse every time, imagining that I was empowering them or 
something.  By the time they realized that I had shifted half of my work 
(the boring half!) onto them, they were too addicted to their ability to 
make instant changes for them to get out.  The templates usually ended 
up with a bit more repetition than I would have liked, but I considered 
that a small price to pay for the overall improved speed of development. 
  The smarter designers will learn concepts like OAOO quickly when they 
see that it's in their best interest to do so.

I also notice that bivio.com has a relatively clean and simple design. 
If it were up to me, all "application" sites would have this kind of 
simple design, but more often than not I seem to end up with designers 
who are determined to take their interface cues from H R Giger prints.

> What's interesting about this discussion to me is that I think the
> Model piece is the most complex part of bOP.  It has taken as a long
> time to stabilize our FormModel class, for example.  The SQL
> abstraction is limited and not as portable as we would like.
> 
> Why is there so little discussion of the M in MVC?  It's far from a
> trivial problem.

There's a ton of discussion about mapping objects to relational 
databases.  It's on the Perl Object-Oriented Persistence list 
(http://sourceforge.net/projects/poop/).

- Perrin


Re: separating C from V in MVC

Posted by Rob Nagler <na...@bivio.biz>.
Andy Wardley writes:
> Because Perl is a general purpose programming language.  TT implements
> a general purpose presentation language.  A different kettle of fish
> altogether.

These are the reserve words of TT:

    GET CALL SET DEFAULT INSERT INCLUDE PROCESS WRAPPER 
    IF UNLESS ELSE ELSIF FOR FOREACH WHILE SWITCH CASE
    USE PLUGIN FILTER MACRO PERL RAWPERL BLOCK META
    TRY THROW CATCH FINAL NEXT LAST BREAK RETURN STOP 
    CLEAR TO STEP AND OR NOT MOD DIV END

Looks an awful lot like the same keywords in any general-purpose
programming language.

> It's like asking why XML has different syntax and semantics from
> Perl.

Well, if you read the XSLT spec and then look at an XSLT program,
you'll see a lot of verbosity and a lot of general purpose constructs
like variables, conditionals, and loops.  I haven't done much with
XSLT, but I do know you can get it in an infinite loop.  That seems
pretty general purpose to me.

I think the rule is: if you can solve Towers of Hanoi in the language,
its general purpose enough.  True formatting languages, such as,
Scribe do not contain general-purpose constructs, so you couldn't
solve the Towers of Hanoi.  HTML is another good example (ignoring
<script>).

> I find it easier to have a little language which is tailored to the task
> at hand.

Let's separate syntax from semantics.  You can use Perl syntax very
easily without adopting the semantics for the "little language"
constructs.  For example, here's a bOP configuration file:

{
    'Bivio::Ext::DBI' => {
	database => 'petdb',
	user => 'petuser',
	password => 'petpass',
	connection => 'Bivio::SQL::Connection::Postgres',
    },
    'Bivio::IO::ClassLoader' => {
	delegates => {
	    'Bivio::Agent::TaskId' => 'Bivio::PetShop::Agent::TaskId',
	    'Bivio::Agent::HTTP::Cookie' =>
		'Bivio::Delegate::PersistentCookie',
	    'Bivio::UI::HTML::FormErrors' =>
		'Bivio::PetShop::UI::FormErrors',
	    'Bivio::TypeError' => 'Bivio::PetShop::TypeError',
	    'Bivio::Auth::Support' => 'Bivio::Delegate::SimpleAuthSupport',
	},
	maps => {
	    Model => ['Bivio::PetShop::Model', 'Bivio::Biz::Model'],
	    Type => [ 'Bivio::PetShop::Type', 'Bivio::Type'],
	    HTMLWidget => ['Bivio::PetShop::Widget',
		'Bivio::UI::HTML::Widget', 'Bivio::UI::Widget'],
	    Facade => ['Bivio::PetShop::Facade'],
	    Action => ['Bivio::PetShop::Action', 'Bivio::Biz::Action'],
	    TestLanguage => ['Bivio::PetShop::Test'],
	},
    },
    'Bivio::UI::Facade' => {
	default => 'PetShop',
    },
    'Bivio::UI::Text' => {
	http_host => 'petshop.bivio.biz',
	mail_host => 'bivio.biz',
    },
};

You could use XML, Lisp, or some other syntax for this.  Since the
implementation of the configuration parser is in Perl, we use eval as
the config parser.  When I program in Lisp, I use Lisp syntax for
config and eval for the parser again.  The syntax is different, but
the semantics probably are the same.

Perrin Harkins writes:
> The thing that worries me about a widget approach is that I would have 
> the same problem I had with CGI.pm's HTML widgets way back: the 
> designers can't change the HTML easilly.  Getting perl developers out of 
> the HTML business is my main reason for using templating.

I think this is where our experience diverges.  I have hired designers
before and every time we had to recode the HTML and the JavaScript
anyway.  My approach is to apply the Once And Only Once principle,
which simplifies design changes (discussed more below).

Andy Wardley writes:
> This is abstraction.  Not to be confused with MVC which is one particular
> architecture well suited to GUI applications.  Blindly applying MVC without
> understanding the real issues (abstraction of front/back ends, separation of 
> concerns, don't repeat yourself, etc.) is likely to build a system which is 
> highly fragmented.  Maintenance becomes harder because everything is split 
> up into many different pieces and it becomes difficult to see the wood for 
> the trees.

If you apply Once And Only Once extemely, you'll find that MVC is a
nice fit for just about any information system.

> Despite our best intentions, this web site doesn't neatly fall into 
> clearly defined chunks of model, application and view.  Well, actually,
> those parts do split down quite nicely.  But then you look at localisation,
> for example, and we find there is localisation required in the data backend, 
> localisation required in the applications and localisation required in the 
> templates.  Thus, localisation is an aspect which cuts across the system.
> By building a strict MVC we've fragmented localisation and have to trawl
> through hundreds of different files to localise the site.

To solve this problem, we added a letter.  bOP is MVCF, where F stands
for Facade.  A Facade allows you to control icons, files, colors,
fonts, text, and tasks.  You can add other components, but we usually
use text as a catch all, e.g. numeric formats.  Facades can inherit
from other facades and can be cloned from other facades.  We use this
to support different skins and co-brands.

> Another example is that different countries running their localised versions
> of this web site will want to change the URLs.  Where the english version
> uses /product/shirt/red.html, the french version should instead be 
> /produit/chemise/rouge.html, for example.

A Facade is the first thing set in a request.  You then know what
tasks are available and what URLs map to them.  Take a look at:
http://petshop.bivio.biz/src?s=Bivio::PetShop::Facade::PetShop
All the URLs for the site are contained in this file.  Anybody
rendering a URL, does it through Bivio::UI::Task.
 
> to model in your system.  Nowhere in MVC or any other Design Pattern does
> it tell you to define all your URLs in one place in case you ever need to 
> change them en masse.  You have to think of that all by yourself.

I don't much buy into Design Patterns (in capitals).  We call it MVC
so that other people can understand what we are talking about.
Unfortunately, the meaning of MVC (especially C) is up to individual
(bad ;-) taste.

There are some basic design rules.  Eliminating redundancy is one of
them.  Another one is "pre-optimization is the root of all evil".
You have to know these things if you're going to build complex systems.

> Each of these elements can be "subclassed" to change one particular 
> aspect of the site.  A simple bit of code weaves the 12 different aspects
> together into one coherent data model which is the definitive reference
> model for everything in the site.

I don't see how it is an "Aspect" (in the capital A sense).  It seems
like a service module, which you had better use to maintain the Once
And Only Once principle.  It takes discipline to use abstractions
properly.  What I find is that unless you have designers who
understand OAOO, you are going to have the same problems with your
aspect infrastructure as with anything else.

My experience maintaining Web applications is that it doesn't take
very many people if you apply OAOO consistently.  We don't have any
designers on staff.  We hire them to help with a redesign, and then
code the ideas ourselves.  The implementation of their ideas takes
just a few days for the most complex changes.

> In five years time, I'll probably be saying "Aspect Oriented Programming 
> isn't the answer by itself..."  :-)

I suspect you'll find AOP won't be in heavy use in five years except
for debugging features.  The magic of OO is hard enough to understand,
and AOP is really magical.  AOP also doesn't solve very many
problems.

What's interesting about this discussion to me is that I think the
Model piece is the most complex part of bOP.  It has taken as a long
time to stabilize our FormModel class, for example.  The SQL
abstraction is limited and not as portable as we would like.

Why is there so little discussion of the M in MVC?  It's far from a
trivial problem.

Rob



Re: separating C from V in MVC

Posted by Andy Wardley <ab...@andywardley.com>.
On Mon, Jun 03, 2002 at 09:49:59PM -0600, Rob Nagler wrote:
> Another concern I have about Template Toolkit (and other template
> languages) is that it has its own syntax and semantics for data and
> control structures distinct from Perl.  Why isn't Perl good enough?

Because Perl is a general purpose programming language.  TT implements
a general purpose presentation language.  A different kettle of fish
altogether.  

It's like asking why XML has different syntax and semantics from Perl.

> This is what Template Toolkit has become imo, and so the
> argument about template languages being "easier than Perl" is
> specious.  Rather, they become harder, because you have to think in
> two languages instead of one.

Perhaps, but I personally don't have any trouble switching between 
numerous different domain specific languages.  In the last hour, for
example, I've been using these: 

  Perl
  Perl regular expressions
  SQL
  XML 
  Javascript
  Template Toolkit

I find it easier to have a little language which is tailored to the task
at hand.  The problem comes when you try and grow your little language
into a general purpose programming language.  I've tried to resist that
temptation in TT, but I readily admit that feature creep is a common
trait in such systems.


A


Re: separating C from V in MVC

Posted by John Siracusa <si...@mindspring.com>.
On 6/4/02 12:32 PM, Perrin Harkins wrote:
> The thing that worries me about a widget approach is that I would have
> the same problem I had with CGI.pm's HTML widgets way back: the
> designers can't change the HTML easilly.  Getting perl developers out of
> the HTML business is my main reason for using templating.

My approach uses an intentionally limited subset of Mason as my "templating"
language.  It looks something like this:

* Model: Regular Perl classes and objects.

* Controller: Regular Perl classes and objects, trivially wrapped in Mason
components to control access location (i.e. URL), object caching, and so on.

* View: Mason components that receive "widget"-like objects as well as
simple strings and other params.

To try to solve the "designers don't know Perl" problem, I just constrain
the API usage of the widget objects for designers.  Example:

    <tr>
    <td><% $form->field('name')->html_label %></td>
    <td><% $form->field('name')->html_field %></td>
    </tr>

As concerned as I initially was by this syntax, the fact is that 99% of all
view objects have a series of exactly the same calls.  Designers have no
clue what they do internally, but the fact is that the only part that really
changes is the field name.  And there are very few, simple method names to
know: html_field, html_label, html_error, etc.  In the simplest case,
there's even a few places where this works:

    <% $form->field('name')->html %>

And handles the label (if any), field, and field-tied error message all in
one block.  I guess the moral is that comfort != understanding.  Designers
can get comfortable with even "ugly" syntax like the above very quickly
since it is repeated so often.

Yes, this means that all the nuts and bolts of what gets printed by those
calls is handled by the controller object (which produces the widgets,
populating them according to the data form the model objects), and therefore
the programmer.  But IMO this is as it should be.  The programmer flags
which form fields are "required", what HTML surrounds "error messages"
(usually just <span class="error">) and so on.  The designers change the
contents of the style sheets, make the graphics, and arrange the widgets on
the page.

And in a pinch, the programmer does have the full range of Mason features
available.  IMO, it's not much harder for designers to learn some small
subset of a larger syntax (like Mason/Perl-Widget-API) than it is for them
to learn an equal size subset (or entirety) of a "little language" like
template toolkit.

-John


Re: separating C from V in MVC

Posted by Perrin Harkins <pe...@elem.com>.
Rob Nagler wrote:
> The way I understand how plugins work is that they are arbitrary
> classes.  But how do you share behavior?

I probably wouldn't use a plugin for something that needed to output 
HTML, because that would prevent the designers from editing it.  A macro 
(basically a mini-template) could be broken down into smaller shared 
templates, but there is a practical limit to that approach.

> FILTER does not shared behavior, but is a pipe mechanism.

Yes.  I think it would be a good way to do the FONT trick you mentioned 
though.

> There is no protocol for communicating between these various
> components except well-known global variables.

That's correct.  A template can call macros which are parameterized 
(e.g. a macro for making large text headlines which accepts the text as 
a parameter), but that's not exactly the same thing.  If you find that 
you really need to have stateful widgets that share data beyond whatever 
model data was passed to the view, then templating is probably not an 
appropriate solution.

> For example,
> if a Link is not executable by the current user, it won't render as a
> link (and possibly be completely blank depending on the circumstance
> and configuration).

That's easy to do, but not easy to share between multiple templates with 
different appearances.

> Another concern I have about Template Toolkit (and other template
> languages) is that it has its own syntax and semantics for data and
> control structures distinct from Perl.  Why isn't Perl good enough?

The syntax for accessing complex data structures in perl is non-trivial 
and possibly too confusing for designers.

Here's the perl version:
foreach my $account ( @{$model_data->{'user'}->{'accounts'}} ) {

and in TT:
[% FOREACH account = user.accounts %]
or with localized loop variables, like HTML::Template:
[% FOREACH user.accounts %]

> My experience with "little languages" is that they take on a life of
> their own

That can happen, and I've seen some people do appalling things with 
templating tools, but these people tend to be programmers working by 
themselves with no separate designer.  The place where these tools 
really pay off is when you're working with a separate design group.  My 
experience has been that designers have no trouble grasping the basic 
ideas of templating, and don't feel the need to try and wedge in stuff 
that doesn't belong there.

The thing that worries me about a widget approach is that I would have 
the same problem I had with CGI.pm's HTML widgets way back: the 
designers can't change the HTML easilly.  Getting perl developers out of 
the HTML business is my main reason for using templating.

- Perrin


Re: separating C from V in MVC

Posted by Rob Nagler <na...@bivio.biz>.
Perrin Harkins writes:
> I just didn't put in any fancy HTML in my example.  I could have put in 
> table tags right there, or made a macro if that table gets repeated a 
> lot.  Looks to me like they work the same.  In TT, I would probably use 
> macros or small templates (possibly defined in this same template file 
> at the top) for little repeating chunks, and filters or plugins for 
> things with more brains, like the String widget that decides whether or 
> not it needs to print FONT tags.

The way I understand how plugins work is that they are arbitrary
classes.  But how do you share behavior?

I couldn't find any protocol for sharing behavior in Template Toolkit.
FILTER does not shared behavior, but is a pipe mechanism.  PLUGIN can
only communicate through $context (global variables).  WRAPPER is
another form of FILTER.  INCLUDE, PROCESS, MACRO, and BLOCK are simple
textual substitution.  PERL is the same as a inline PLUGIN.

There is no protocol for communicating between these various
components except well-known global variables.  Yes, you could invent
a protocol, but it wouldn't be compatible with somebody else's
protocol.

Widgets can inherit behavior from other widgets.  For example, the
Enum widget is a subclass of String.  Enum overrides the render()
method, because it provides interesting behavior on enumerated types
in certain cases.  If the interesting behavior is not applicable, it
defers to String by calling $self->SUPER::render(@_).

We use inheritance quite a bit.  For example, CheckboxGrid and
RadioGrid inherit from Grid.  We have a ControlBase widget which
supplies the structure for boolean-controlled widgets.  For example,
if a Link is not executable by the current user, it won't render as a
link (and possibly be completely blank depending on the circumstance
and configuration).

Another concern I have about Template Toolkit (and other template
languages) is that it has its own syntax and semantics for data and
control structures distinct from Perl.  Why isn't Perl good enough?

The bOP view language implementation is about 100 lines of Perl (no
XS), and gives you all the power of Perl.  The Widget interface
contains three methods (new, initialize, and render), which provides
extensibility through Perl classes.  Variables are provided through
the WidgetValueSource which has two methods.  Finally, for "macros"
there are ViewShortcuts which are Perl subroutines collected in a
class (which usually inherits from other classes).  All of this is
plain old Perl.
 
My experience with "little languages" is that they take on a life of
their own, viz. Apache's configuration language and mod_rewrite.  They
become more and more complex until they become yet another programming
language.  This is what Template Toolkit has become imo, and so the
argument about template languages being "easier than Perl" is
specious.  Rather, they become harder, because you have to think in
two languages instead of one.

Just my $.02 or so... :-)

Rob



Re: separating C from V in MVC

Posted by Perrin Harkins <pe...@elem.com>.
Rob Nagler wrote:
> [Skirting on the edge of YATW. :-]

I certainly don't mean to have a templating war.  I'm just trying to 
figure out what the difference is between these approaches and if 
there's something I've been missing that I should consider adding to 
future applications.

> Here's your expanded example in widgets:
> 
>     String(Prose(<<'EOF'), 'basic_info_font');
>     Hello String(['Model.User', 'first_name']);!<br>
>     If(['Model.AccountList', '->get_result_set_size'],
> 	Join([
> 	    "You have these accounts:<br>",
> 	    Table('Model.AccountList', [
> 		'name',
> 		'balance',
> 	    ]),
> 	]),
>     );
>     EOF

If your String widget can accept other widgets recursively like this, 
then our examples are equivalent.  I thought it was limited to a simple 
value.

> Unless I
> missing something, the template example won't align properly in HTML.
> This is a significant semantic difference between FOREACH and
> Table.

I just didn't put in any fancy HTML in my example.  I could have put in 
table tags right there, or made a macro if that table gets repeated a 
lot.  Looks to me like they work the same.  In TT, I would probably use 
macros or small templates (possibly defined in this same template file 
at the top) for little repeating chunks, and filters or plugins for 
things with more brains, like the String widget that decides whether or 
not it needs to print FONT tags.

- Perrin


Re: separating C from V in MVC

Posted by Rob Nagler <na...@bivio.biz>.
Perrin Harkins writes:
> The advantage is that my example can contain other templating code:
> 
> [% FILTER font('basic_info_font') %]
>    Hello [% User.first_name %]!<BR>
>    [% IF User.accounts %]
>       You have these accounts:<BR>
>       [% FOREACH User.accounts %]
>         [% name %]: [% balance %]<BR>
>       [% END %]
>    [% END %]
> [% END %]
> 
> Unless I'm missing something about your example, the FILTER concept 
> seems more powerful.

[Skirting on the edge of YATW. :-]

I think they are equivalent as far as "power".  I go back to why
people use Perl, because it makes the easy jobs easy and the hard jobs
possible.  All programming languages are Turing Complete, but we don't
like programming Turing Machines.

Here's your expanded example in widgets:

    String(Prose(<<'EOF'), 'basic_info_font');
    Hello String(['Model.User', 'first_name']);!<br>
    If(['Model.AccountList', '->get_result_set_size'],
	Join([
	    "You have these accounts:<br>",
	    Table('Model.AccountList', [
		'name',
		'balance',
	    ]),
	]),
    );
    EOF

The Table widget will print a table with headings defined by the
Facade (our term for skin).  The widgets for name and balance are
looked up dynamically.  balance will be right adjusted.  Unless I
missing something, the template example won't align properly in HTML.
This is a significant semantic difference between FOREACH and
Table.

Would you expand on the example so that name and balance are columnar?

Rob



Re: separating C from V in MVC

Posted by Perrin Harkins <pe...@elem.com>.
Rob Nagler wrote:
> Perrin Harkins writes:
> 
>>You can actually do that pretty comfortably with Template Toolkit.  You
>>could use a filter for example, which might look like this:
>>
>>[% FILTER font('my_first_name_font') %]
>>... some text, possibly with other template directives in it...
>>[% END %]
> 
> 
> One of the reasons Perl is popular is its idioms.  Having to say
> something in three lines is not as idiomatic as one line.  It takes a
> lot of discipline to use it everywhere.  In other words, I don't think
> the above is more comfortable than:
> 
>     String(['User.first_name'], 'my_first_name_font');

The advantage is that my example can contain other templating code:

[% FILTER font('basic_info_font') %]
   Hello [% User.first_name %]!<BR>
   [% IF User.accounts %]
      You have these accounts:<BR>
      [% FOREACH User.accounts %]
        [% name %]: [% balance %]<BR>
      [% END %]
   [% END %]
[% END %]

Unless I'm missing something about your example, the FILTER concept 
seems more powerful.  It is perfectly possible to simply add a plugin to 
TT to make it look like yor example though:

[% String(User.first_name, 'my_first_name_font') %]

> Note also the accessor for User.first_name in Template Toolkit is
> probably nontrivial.

Assuming it's just $User->first_name() and you passed in $User as part 
of your data to the view, there's no additional work.

- Perrin


Re: separating C from V in MVC

Posted by Andy Wardley <ab...@andywardley.com>.
On Mon, Jun 03, 2002 at 08:09:12AM -0600, Rob Nagler wrote:
> > [% FILTER font('my_first_name_font') %]
> > ... some text, possibly with other template directives in it...
> > [% END %]
> 
> One of the reasons Perl is popular is its idioms.  Having to say
> something in three lines is not as idiomatic as one line.  It takes a
> lot of discipline to use it everywhere.  In other words, I don't think
> the above is more comfortable than:
> 
>     String(['User.first_name'], 'my_first_name_font');

So write it that way:

  [% String(user.first_name, my_first_name_font) %]

Just define the 'String' template variable to be a reference to your
'String' sub.

I do agree with what you're saying, however.  Perl is good, so don't
try and replace it with a markup language.


A


Re: separating C from V in MVC

Posted by Rob Nagler <na...@bivio.biz>.
Perrin Harkins writes:
> You can actually do that pretty comfortably with Template Toolkit.  You
> could use a filter for example, which might look like this:
> 
> [% FILTER font('my_first_name_font') %]
> ... some text, possibly with other template directives in it...
> [% END %]

One of the reasons Perl is popular is its idioms.  Having to say
something in three lines is not as idiomatic as one line.  It takes a
lot of discipline to use it everywhere.  In other words, I don't think
the above is more comfortable than:

    String(['User.first_name'], 'my_first_name_font');

Note also the accessor for User.first_name in Template Toolkit is
probably nontrivial.

Rob



Re: separating C from V in MVC

Posted by Perrin Harkins <pe...@elem.com>.
> A String widget/template allows you to control the rendering of all
> fonts dynamically.  If the String widget/template sees the incoming
> request is from IE5+, it doesn't render the font if the font is the
> same as the default font.  The Style widget/template renders the
> default font in a style if the browser is IE5+.  This avoids the
> stylesheet bugs in all other browsers and gives 90% of your users who
> are running IE5+ a much lighter weight page.
>
> It's cumbersome to do wrap all text in string templates, because the
> calling mechanism is verbose.  Most template languages I've looked at
> only support named parameters.
>
> Widgets can have named parameters, e.g.
>
>     String({
>         value => ['User.first_name'],
> string_font => 'my_first_name_font',
>     });
>
> but it is much more convenient to use positional notation:
>
>     String(['User.first_name'], 'my_first_name_font');

You can actually do that pretty comfortably with Template Toolkit.  You
could use a filter for example, which might look like this:

[% FILTER font('my_first_name_font') %]
... some text, possibly with other template directives in it...
[% END %]

The filter is a module which would get to post-process the output of the
contained block.

I believe the taglibs in AxKit could be used in a similar way.

- Perrin


Re: separating C from V in MVC

Posted by Stas Bekman <st...@stason.org>.
I think it'll be great to present the current discussion as a tutorial,
so others can make a better use of the ideas thrown here, rather digging 
in archives. This could be a great addition to our growing tutorials 
section for the new site we are working on:

http://perl.apache.org/release/docs/tutorials/index.html

Any takers?

While we are at it, if you are interested in writing tutorials on all 
kinds of topics related to mod_perl but don't fit into modperl docs 
(dbi, sql, caching, high availability, cool tricks, world domination, 
etc.) let us know at the docs-dev mailing list (or contact me) and we 
will help you with the details.

Thanks!
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: separating C from V in MVC

Posted by Rob Nagler <na...@bivio.biz>.
Perrin Harkins writes:
> The same template?  How does the layout manager help with that?  Does it 
> modify the template?  It would make more sense to me if this were a sort 
> of abstraction to factor out common layout ideas from multiple
> templates.

I think we're miscommunicating.  I'm talking widgets, and you're
talking templates.

A layout manager is a bit of a red herring in mod_perl.  I was simply
trying to explain how they came to be and why they make sense.  In
GUIs, the layout manager is responsible for placement when the window
is resized.  In mod_perl, it plays a lesser role, because the browser
does most of the work (thank goodness).

Templates and widgets are pretty much the same thing (see discussion
at end).  It's how you use them that makes a difference.  We have a
String widget.  You could just as well make a string template.  It's
not natural in template languages to wrap every piece of text in a
string template, however.

A String widget/template allows you to control the rendering of all
fonts dynamically.  If the String widget/template sees the incoming
request is from IE5+, it doesn't render the font if the font is the
same as the default font.  The Style widget/template renders the
default font in a style if the browser is IE5+.  This avoids the
stylesheet bugs in all other browsers and gives 90% of your users who
are running IE5+ a much lighter weight page.

It's cumbersome to do wrap all text in string templates, because the
calling mechanism is verbose.  Most template languages I've looked at
only support named parameters.

Widgets can have named parameters, e.g.

    String({
        value => ['User.first_name'],
	string_font => 'my_first_name_font',
    });

but it is much more convenient to use positional notation:

    String(['User.first_name'], 'my_first_name_font');

The way I like to think of this is that HTML corresponds to machine
language.  Templates correspond to assembly language.  Widgets
correspond to structured programming.  You can program everything in
assembly language, it's just more cumbersome.  This is why people
invented macro assemblers, but there is still a significant difference
between building a system in C or Macro-11.

This is why a layout manager is a natural concept to me.  It's a
widget which does something with the results of other widgets.  What's
cool about HTML is that you can do this "post draw", i.e., after the
widget renders a child, it can look at the result to determine its
next action.  For example, the String widget can escape the output of
its child.  I haven't seen this in template languages and rarely in
GUI toolkits.

Rob



RE: separating C from V in MVC

Posted by Jeff <ja...@aquabolt.com>.
> From: Perrin Harkins [mailto:perrin@elem.com] 
> Sent: 01 June 2002 00:17
> To: Rob Nagler
> Cc: modperl@perl.apache.org

> The same template?  How does the layout manager help with that?  
> Does it modify the template?  It would make more sense to me if 
> this were a sort of abstraction to factor out common layout 
> ideas from multiple templates.

The layout manager is more complex than a static template. It takes 
a collection of data and meta-data and creates a document tree that 
is not a specific rendering flavour - the DOM might subsequently
be rendered in NS4.0 HTML, IE5.01+ HTML, Excel, PDF etc. without 
requiring (every page) x (every format) x (every option) templates.

> ...
> That doesn't require a layout manager though.  Simple templating is 
> fine for that, i.e. two different templates (views).

In most circumstances it is ok to have templates that are 
specific to one output flavour, possible with some simple alts.

But what if I have 40 pages that I want to render in: IE5+HTML, 
NS4-HTML, Excel, HP-PCL5 and PDF - and I also want SIMPLE views 
of each page. This would result in 40 x 5 x 2 = 400 templates. 
For every change in a basic page, I have to keep 9 other templates 
in other languages in step.

If the number of output formats and page variants is not trivial, 
it might make more sense to have an active component that creates 
the document tree, and passes it to simple components that know how 
to render a DOM in the desired output format.

All in all, I think the MVC+template approach described is fine for
most of the type of dynamic sites currently available on the web.

But I work for a small ASP and we have to manage rapidly changing 
complex dynamic sites and complex user reporting requirements, with
minimal work. We don't have any HTML specialists, but rather a few 
very good technical generalists. I think that for us a meta-data 
layout driven approach will be more effective. 

We do however plan to borrow all the good ideas we can find from any 
other model, including MVC+template. Our planned move to mod_perl is
mostly due to the benefits we have seen from out Perl data processing
and reporting - hence the desire to join both the web and DP infra at
the hip.

Regards
Jeff



Re: separating C from V in MVC

Posted by Perrin Harkins <pe...@elem.com>.
Rob Nagler wrote:
> Let's say, though, that you want the same template to render
> in a WAP, Opera, Konqueror, IE, NS, etc.  The implementation of Grid
> handles this for you.  For example, our code automatically renders
> style sheets for IE5+, but no other browsers.  (This isn't in Grid,
> but you get what I mean, I hope.)

The same template?  How does the layout manager help with that?  Does it 
modify the template?  It would make more sense to me if this were a sort 
of abstraction to factor out common layout ideas from multiple templates.

> However, sometimes you have dense tables where you allow wrapping and
> other sparse tables where you don't.  We have a really wide table for
> admins which allows them to see all EC info at a glance.  It has to
> wrap all cells or it wouldn't fit on some screens.  When the customer
> sees the payment reason, on their subscription page, it doesn't wrap.
> Two views of the same data.

That doesn't require a layout manager though.  Simple templating is fine 
for that, i.e. two different templates (views).

- Perrin


RE: separating C from V in MVC

Posted by Jeff <je...@bircholme.com>.
> From: Rob Nagler [mailto:nagler@bivio.biz] 
> Sent: 31 May 2002 23:48

> Models can only express meta info about the data, not the context 
> in which the data is rendered.  Some info, like placement, is 
> conditional on the grouping which is chosen by the view.  A layout 
> manager abstracts placement using meta data supplied by the model 
> and context supplied by the view.

This is an interesting comment. We have so far tried [successfully]
to keep our document object models completely independent of the
rendering component, which means the same DOM can be passed to an
Excel/PDF/etc component for rendering.

The challenge of course is that it is much easy to render complex 
things in HTML than for example Excel which imposes a global tablular
view where a column can only have one width for a page. Excel does
however support multiple pages, but HTML doesn't [frames?]. Whilst
one can rely on scroll-bars for HTML, PDF rendering requires the 
component to decide on wrapping or truncating to fit page widths.

We relied heavily on the layout analysis that the W3 did for CSS and
HTML when desiging our DOM class, and so HTML rendering is easy. As
Rob  mentions in one of his emails, the HTML rendering component
does not actually have to calculate final layout, as this is done 
by the browser. Final layouts do have to be managed by some of our
other rendering components - the PDF rendering component has to
understand all flow, wrap, alignment, trunctation etc layout info.

Your comment seems to hint that maybe the DOM should take into 
account the target rendering flavour eg craft a complex DOM for 
HTML but a simple DOM for Excel. We chose to make our rendering 
components all accept complex DOMs and then make their own 
decisions on to best render them taking into account limitations 
of the target format. I don't know if this was the right decision,
but it has met our requirements for fast reporting development 
times for over a year now, and I am hoping to take it into the
HTML world.


I somehow feel that the MVC and MVC+template patterns described so 
far in the discussions go a long way towards, but do not quite
reach our desired level of reusable infra. Templating is an 
interesting variant, but actually solves a different problem.

Perhaps we are wanting too much! I can certainly see that the MVC+
template approach is simpler, and this is the strongest point in 
its favour.


Regards

Jeff


Re: separating C from V in MVC

Posted by Rob Nagler <na...@bivio.biz>.
Perrin Harkins writes:
> Can't all of that be expressed in an HTML template?

Sort of.  Let's say, though, that you want the same template to render
in a WAP, Opera, Konqueror, IE, NS, etc.  The implementation of Grid
handles this for you.  For example, our code automatically renders
style sheets for IE5+, but no other browsers.  (This isn't in Grid,
but you get what I mean, I hope.)

> It seems like the 
> template should know enough about what kind of data it's displaying to 
> know how to arrange the tables.  After all, it's not a template for a 
> generic table; it's a template for a table that displays specific data 
> with a structure that is pre-determined.

Absolutely, along with field labels, icon alts, etc.  You want this
switchable depending on the "skin" you are using.

However, sometimes you have dense tables where you allow wrapping and
other sparse tables where you don't.  We have a really wide table for
admins which allows them to see all EC info at a glance.  It has to
wrap all cells or it wouldn't fit on some screens.  When the customer
sees the payment reason, on their subscription page, it doesn't wrap.
Two views of the same data.

> Usually when I see people doing this kind of thing it's because they 
> haven't expressed all the necessary information in their model.

Models can only express meta info about the data, not the context in
which the data is rendered.  Some info, like placement, is conditional
on the grouping which is chosen by the view.  A layout manager
abstracts placement using meta data supplied by the model and context
supplied by the view.

Rob



Re: separating C from V in MVC

Posted by Perrin Harkins <pe...@elem.com>.
Rob Nagler wrote:
> Layout managers accept a declaration ('this cell is northwest', 'this
> other one expands across the bottom', etc.).  They interpret the decl
> at run-time.  It's like HTML, but more declarative.  Some attributes
> of our Grid manager are:
> 
>   cell_nowrap - don't wrap the text in the cell
>   cell_align - gens valign and align from a single compass direction
>   cell_expand - this cell eats up the rest of the columns in the row
>   row_control - a conditional value to control whether row is displayed
>   cell_width - contains the HTML width= value (may be dynamic)

Can't all of that be expressed in an HTML template?  It seems like the 
template should know enough about what kind of data it's displaying to 
know how to arrange the tables.  After all, it's not a template for a 
generic table; it's a template for a table that displays specific data 
with a structure that is pre-determined.

Usually when I see people doing this kind of thing it's because they 
haven't expressed all the necessary information in their model.  For 
example, if you have a rule that says people's names don't get wrapped, 
then you need to know which pieces of data are names.  If that isn't 
obvious from your data structure (i.e. person.name is always a name) 
then you add some flag to your data structure like is_name, so that the 
model can tell the view that this is a name.  Then the view gets to 
decide what special treatment to give that data.

Maybe there's a certain class of problems where the sort of layout hints 
you're talking about are needed and I've just never had to deal with it.

- Perrin