Re: [Catalyst] Re: How to access current MyApp instance ?

2007-07-05 Thread Perrin Harkins

On 7/5/07, Bill Moseley <[EMAIL PROTECTED]> wrote:

Do you avoid macros because the localization hit or because of the
namespace issues?


I avoid them because it's too confusing for me and the reasoning about
which one to use is too hard for me to explain to designers.  I just
stick with PROCESS.  I'm a TT2 luddite, really.


Thousands, for sure.  A small handful can really help.  It's not so
much to do something better done in Perl, but as a way to avoid
writing the same markup over and over.  A real plus when you want to
change a common page element on the entire site sometime down the
road.


Sure, header, footer, navbar, etc.  I'd have those with any SSI or
template thing.


WRAPPERs are the biggest gem for getting out of that top-down approach
to page design that lends itself to markup duplication.


I resisted those for a long time, but I think I might try them next time.


Likewise, a few macros can help.  Abstracting out common elements is
useful in Templates as it is elsewhere in the code you write.


DRY is a nice principle, but too much focus on it leads to crazy
templates.  I've seen it happen.  I try not to worry too much about a
little duplicated markup.


Say you have a site with a large number of tables and they all should
look similar.

Each table has click-able headings and displays a page of rows with
alternating even/odd-style, and pager links (Previous 1 2 3 4 Next).


That's a pretty complicated widget with deep ties to backend
functions.  I'd probably do some special thing for that, making it a
high-level widget with code and templates separate from the rest of
the page content.

Your MACRO use sounds reasonable.  It's all about balance.  Having
seen a lot of templates that were not maintainable because of
over-DRYing, I'm pretty cautious about this kind of thing.

- Perrin

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Re: How to access current MyApp instance ?

2007-07-05 Thread Perrin Harkins

On 7/5/07, A. Pagaltzis <[EMAIL PROTECTED]> wrote:

That's what I was advising, basically, except that I would tell
people to use INCLUDE instead of PROCESS.

Else you'll be violating your own rule not to add variables to
the stash from inside a template, as soon as any of your blocks
are parametrisable.


I don't normally make blocks parameterizable.  I treat them like dumb SSI.


The question is whether this is intrinsic to templates or simply
a consequence of the extensive limitations of the TT language.


I think it's intrinsic to templates.  They lack the resources that a
real programming language has for managing complexity.  I think the
only way around the need for simple templates would be to take a
widget-based approach where you don't directly write any HTML.  The
Bivio guys made this work.  It's not for everyone though.  It takes
discipline.

My other motivation for simple templates is that I like to get other
people to write the HTML.  They have to simple enough to hand to a
stranger without elaborate explanations.

- Perrin

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Re: How to access current MyApp instance ?

2007-07-05 Thread Bill Moseley
On Thu, Jul 05, 2007 at 11:15:57AM -0400, Perrin Harkins wrote:
> For those out there who like TT2's mini-language, I've been using it
> for many years without ever encountering any of the problems described
> in this thread.  I never add any variables to the stash from inside my
> templates (temporary loop variables excluded), avoid MACRO (I only use
> PROCESS), and generally keep the templates  very, very simple.  And I
> have documentation that describes the data structure that will be in
> the stash for each page.

Do you avoid macros because the localization hit or because of the
namespace issues?  I don't normally have that many items in the stash
(or macros) so namespace collision is not a concern.

> Templates aren't normal code (even with in-line perl) and they don't
> handle complexity like real code does, so you have to control your
> impulse to turn them into thousands of little components.  It just
> gets too confusing.

Thousands, for sure.  A small handful can really help.  It's not so
much to do something better done in Perl, but as a way to avoid
writing the same markup over and over.  A real plus when you want to
change a common page element on the entire site sometime down the
road.


WRAPPERs are the biggest gem for getting out of that top-down approach
to page design that lends itself to markup duplication.  WRAPPERs can be
confusing at first, but they are not that hard to get used to.

Likewise, a few macros can help.  Abstracting out common elements is
useful in Templates as it is elsewhere in the code you write.

Say you have a site with a large number of tables and they all should
look similar.

Each table has click-able headings and displays a page of rows with
alternating even/odd-style, and pager links (Previous 1 2 3 4 Next).

Those are all display items -- belongs in the View.

How would you generate the  links that show which is the currently
sorted column and an indicator if it's sorted ascending or descending?
Obviously, that code should only be done once.


I just want to be concerned with the data that's unique for the page
I'm generating.  So, for the  example, I set up a block like this
where the table_headings_link() macro adds in all the markup for
creating the click-able headings and creates the correct
self-reference URL (as the table might already be limited by, say, a
query string).


[% BLOCK table_headings %]


[% table_heading_link( 'Name', 'name', ) %]
[% table_heading_link( 'Account', 'account', ) %]


[% table_heading_link( 'Email', 'email', ) %]



Status
[% table_heading_link( 'Active', 'active' ) %] /
[% table_heading_link( 'Admin', 'admin' ) %]


[% END %]

You could do this:


[%
PROCESS table_heading_link
label = 'Name',
sortby = 'name';

'';

PROCESS table_heading_link
label = 'Account',
sortby = 'account';
%]


But I think the macros help with readability.


In the past I've abstracted that out even more (since the  and
 is common on every page -- but that's a bit overkill.

-- 
Bill Moseley
[EMAIL PROTECTED]


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Re: How to access current MyApp instance ?

2007-07-05 Thread Perrin Harkins

On 7/4/07, Jonathan Rockway <[EMAIL PROTECTED]> wrote:

I agree that this is a terrible way to do things.  Perl has the right idea
with $sigils, so at least &functions look different from other @things.  Oh,
and you know... a lexical scope.


If you feel the need for complicated scoping rules in your templates,
you probably should be using in-line perl in them rather than a
mini-language.  There are plenty of options for that, including TT2.

For those out there who like TT2's mini-language, I've been using it
for many years without ever encountering any of the problems described
in this thread.  I never add any variables to the stash from inside my
templates (temporary loop variables excluded), avoid MACRO (I only use
PROCESS), and generally keep the templates  very, very simple.  And I
have documentation that describes the data structure that will be in
the stash for each page.

Templates aren't normal code (even with in-line perl) and they don't
handle complexity like real code does, so you have to control your
impulse to turn them into thousands of little components.  It just
gets too confusing.

- Perrin

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Re: How to access current MyApp instance ?

2007-07-04 Thread Jonathan Rockway
On Sunday 01 July 2007 02:27:17 pm A. Pagaltzis wrote:
> Of course, we’ve known since the ’70s or so how to make better
> programming languages, but ABW considers templating languages
> to be totally different from programming languages, so you get
> to be transported back to the ’60s.

I agree that this is a terrible way to do things.  Perl has the right idea 
with $sigils, so at least &functions look different from other @things.  Oh, 
and you know... a lexical scope.

I've personally been burned with this in ircxory*:

[% MACRO thing(thing) BLOCK %] 

  [% thing | html %]
[% END %]

Then:

[% WHILE (thing = things.next) %]
  [% thing(thing.name) %] [% score(thing.score) %]
[% END %]


Oops, that breaks.  

Now my variables have really icky names to work around that, but it has made 
me consider ditching TT.  Unfortunately I don't like the alternatives 
either :)  Maybe T::Declare...

* http://git.jrock.us/?p=ircxory.git;a=summary or "git clone 
git://git.jrock.us/ircxory"

Regards,
Jonathan Rockway

-- 
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;


signature.asc
Description: This is a digitally signed message part.
___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Re: How to access current MyApp instance ?

2007-07-01 Thread Bill Moseley
On Sun, Jul 01, 2007 at 09:27:17PM +0200, A. Pagaltzis wrote:
> * Bill Moseley <[EMAIL PROTECTED]> [2007-07-01 19:25]:
> > Macro?
> > 
> > [%
> > game_detail_link( Game, 'Click here' );
> > game_history_link( Game, 'View history' );
> > %]
> 
> Avoid macros like the plague.
> 
> ??? They share a namespace with variables.

Yes, right.  References to subroutines are variables.

> ??? TT2 only has global variables with dynamic scoping.

Yes, you just have a stash, eh, hash.  And shallow localization.
I kind of wish macros didn't bother with localization.

> ??? It???s extremely lenient at runtime; you can use function call
>   syntax to ???invoke??? a variable, with no complaints.

Yes, that's the design.  Or a byproduct of the design.  You can invoke
variable syntax to invoke subroutine calls, too.  [% foo %] just spits
out whatever foo is, and I don't worry about the implementation.  Is
that good or bad?  Either way, sure is handy.

> Taken together, these mean that you can have hours of fun chasing
> down stupid bugs.

Yes, when first using TT you can do that.  It's not that bad with a
little experience.  You can catch undefined errors automatically if
you want but TT ignoring them also works out to be a feature.  TT
generates perl code, and when I have a tough problem I just debug that
code.

> Of course, we???ve known since the ???70s or so how to make better
> programming languages, but ABW considers templating languages
> to be totally different from programming languages, so you get
> to be transported back to the ???60s.

Yes, we are celebrating 40 years this summer!  Only when I'm really
tripping do I believe TT's a programming language.


> Have I mentioned that I hate TT2 with a passion?

Avoid it like the plague, then. ;)

-- 
Bill Moseley
[EMAIL PROTECTED]


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/