From josh at narins.net Wed Jun 7 13:29:58 2006 From: josh at narins.net (Josh Narins) Date: Wed Jun 7 13:30:53 2006 Subject: [Petal] repeat through hash In-Reply-To: <200604201852.28461.corey_s@qwest.net> References: <200604191752.00922.corey_s@qwest.net> <200604201624.13355.corey_s@qwest.net> <39F2EE86-5D1C-496E-BE43-D8380BA20328@2xlp.com> <200604201852.28461.corey_s@qwest.net> Message-ID: <20060607122958.GA22957@narins.net> > On Thursday 20 April 2006 17:29, Jonathan Vanasco wrote: > > On Apr 20, 2006, at 7:24 PM, Corey wrote: > > > Anyone in favor? Any pitholes or details I'm missing? > > > > Well there's this: > > in Perl, Python and PHP (the TAL implementations I use ), hashes > > ( perl hashes, python dicts , php named arrays ) are unordered. > > randomly showing items from a list, IMHO, is worthless and confusing. > > > > True. And I agree that, from a presentation standpoint, randomly displaying > items from an unordered list is not always useful or sensical - however there > are certainly plenty of instances/use-cases where an ordered presentation > is not in fact necessary, or where there truly is no criteria from which to sort > by anyways. ( I'm currently writing an app in which this is the case. ) 1.a I've always wanted petal to be perl'ier, and less TAL'ish. 1.b Of course, to see just how far I'd like it to go, I'd like to see it more like:
2. Someone mentioned _other_ implementation of TAL in perl? Hrm. -Josh --nothing below this point > I have to point out though, that hashes/dicts/named-arrays are unordered > _internaly_, while arrays are merely ordered internally by subscript ( i.e., > 0 - N ) -- point being, for all intents and purposes: > > $people_array = [ > { > 'firstname' => 'Benjamin', > 'lastname' => 'Tucker' > 'id_num' => '456a7' > }, > { > 'firstname' => 'Pierre-Joseph', > 'lastname' => 'Proudhon' > 'id_num' => '765z4' > } > ]; > > ... and > > $people_hash = { > '456a7' => > { > 'firstname' => 'Benjamin', > 'lastname' => 'Tucker' > }, > '765z4' => > { > 'firstname' => 'Pierre-Joseph', > 'lastname' => 'Proudhon' > } > }; > > ... can both be said to be "unsorted", from a template user perspective. > ( assuming that $people_array wasn't _manually_ sorted by the programmer > in the order specified (i.e, first comes Tucker, then comes Proudhon) ). > > So, while looping through $people_array, the template user would always > get Tucker first, then Proudhon; and while looping through $people_hash, > the user would not know for sure which order the results would be iterated - > the difference is more or less the same: both "lists" were not filtered through > a purposed sort/order function. > > So, appologies for the digression - but I'm attempting to illustrate that the issue > of sorting is quite separate from the issue of allowing Petal's 'repeat' statement > to be implemented in a manner which allows transparent looping over hashes. > > If the feature in question is: > > #1 - conformant to TAL spec > and > #2 - implementable in Petal > but > #3 - deemed usefull > > ... then I think it may be worth considering. > > If either #1 _or_ #2 are definitely false, then there is no reason to continue. > > If #1 and #2 are true, but #3 is debatable, then I think it would come down > simply to whoever got around to actually implementing it - and people could > use it or not; but it would at least be available. > > > > to do what you want, it would just be going randomly through the hash > > > > That's ok, as it is not always necessary to loop over sorted lists -- in those > cases, I feel that being able to loop/repeat over hashes would be quite helpfull > and convienient - and could be implemented without parting from the TAL spec. > > > > i believe that in python you can map the repeat onto a generator or > > iterator - i *think* you can figure out a way mimic that it in perl > > using petal's method support > > > > ie, your repeat loop calls a function that returns the next item in > > whatever sequence, and petal stops doing that at the end > > > > This is definitely good food for thought - as I start using TAL/Petal more > and more. > > > > i tried to stab away at the petal source and try to get nested > > variable to work. i don't think its quite possible. > > > > Bummer! > > ( Cool that you tried though. I was actually going to bring that up in another > post - hoping we/someone could fix that. ) > > > > maybe some college student out there would want to do it through > > google summer of code? that would be awesome. > > > > Definitely. > > Could you summarize what makes that feature so difficult? > > > CHeers, > > Corey > > From petal-list at 2xlp.com Wed Jun 7 16:09:28 2006 From: petal-list at 2xlp.com (Jonathan Vanasco) Date: Wed Jun 7 16:09:58 2006 Subject: [Petal] repeat through hash In-Reply-To: <20060607122958.GA22957@narins.net> References: <200604191752.00922.corey_s@qwest.net> <200604201624.13355.corey_s@qwest.net> <39F2EE86-5D1C-496E-BE43-D8380BA20328@2xlp.com> <200604201852.28461.corey_s@qwest.net> <20060607122958.GA22957@narins.net> Message-ID: <7CF1C162-8AA8-432F-93D5-FA5F0CA42E25@2xlp.com> On Jun 7, 2006, at 8:29 AM, Josh Narins wrote: > 1.a > > I've always wanted petal to be perl'ier, and less TAL'ish. > > i'd suggest using another rendering engine then. one of the biggest benefits / reasons for using TAL is that its a standard cross platform thing. and you can just use functions to do what you want tal: i think the code is something like: my %Personalized= ( blah=> $var, getFunction=> \&function, getHashrefSortedOnKeyValue=> \&Path::To::function, ); print $template->render( \%Personalized ); i'm a bit wrong on passing the data to a template to render - i acutally use an abstraction class to set it all up for me... all the info is in the main Petal spec the only thing i don't like about doing that, is that perl doesn't really implement iterators/generators like Python -- i think i mentioned this before... and in python when you yeild results from an object its cleaner/less annoying to do than with perl > Someone mentioned _other_ implementation of TAL in perl? Hrm. search cpan... be warned though, they're all made because PETAL is too perlish and not strictly TAL enough in its performance. From bruno at mkdoc.com Fri Jun 16 15:31:43 2006 From: bruno at mkdoc.com (Bruno Postle) Date: Fri Jun 16 15:31:52 2006 Subject: [Petal] Petal-2.19 released Message-ID: <20060616143142.GA10811@postle.net> http://search.cpan.org/dist/Petal-2.19/ This release collects together some minor bugfixes, options and documentation. 2.19 Fri Jun 16 15:22:00 2006 - alias false: modifier as not: to match TALES spec (Jonathan Vanasco) - fix repeat/odd documentation bug and add to cookbook (Jonathan Vanasco) - pod typos (sarabob) - CACHE_ONLY option (Jonathan Vanasco) - Add Digest::MD5 dependency (aaron) - Allow passing arguments to coderefs - Encoding support for gettext mo/po files (Andrew Rodland) -- Bruno From chris at webarchitects.co.uk Wed Jun 21 09:48:14 2006 From: chris at webarchitects.co.uk (Chris Croome) Date: Wed Jun 21 10:14:33 2006 Subject: [Petal] Instead of /tmp directory? In-Reply-To: <20050816232610.GC2888@webarchitects.co.uk> References: <20050812133847.GA20147@narins.net> <20050816232610.GC2888@webarchitects.co.uk> Message-ID: <20060621084814.GB2495@webarchitects.co.uk> Hi On Wed 17-Aug-2005 at 12:26:10AM +0100, Bruno Postle wrote: > On Fri 12-Aug-2005 at 09:38 -0400, Josh Narins wrote: > > > > I was hoping you could tell me what option I could change so that > > the petal_cache and petal_debug files didn't end up in /tmp. I'd > > like to change them to /tmp/petal, if that helps (doubtful, but one > > never knows). > > Petal uses File::Spec->tmpdir() for this, so you can change the > directory for the cached templates by setting $ENV{TMPDIR}. This *used* to work for me, but it doesn't seem to any more, on Fedora Core 5 if I add this to the apache conf file: # Petal cache files PerlSetEnv TMPDIR "/var/tmp/" SetEnv TMPDIR "/var/tmp/" The cache files are still written to /tmp I can confirm that the TMPDIR env is set by creating a .shtml file with this in it:
    
  
And when the .shtml file is accessed it has this value: TMPDIR=/var/tmp/ Has anyone else found this? Any suggestions about how to address this? Perhaps Petal needs to have it's own env var for where cache and debug files are written? Chris -- Chris Croome web design http://www.webarchitects.co.uk/ web content management http://mkdoc.com/ From corey_s at qwest.net Fri Jun 23 21:21:48 2006 From: corey_s at qwest.net (Corey) Date: Sun Jun 25 02:40:43 2006 Subject: [Petal] best practices question(s) Message-ID: <200606231321.48831.corey_s@qwest.net> Yo! Say I have a fairly involved cgi app, called "foobar", and an apache document root such as the following: /var/www/localhost/: cgi-bin/ error/ htdocs/ icons/ /var/www/localhost/cgi-bin/foobar/: FooBar/ FooBar.pm foobar.pl My questions are: Where "best" to put the pe(tal) templates -- under the cgi-bin or under the htdocs? i.e: * /var/www/localhost/cgi-bin/foobar/ OR * /var/www/localhost/htdocs/foobar/ I guess because pe(tal) _is_ x/html, it really falls in a tough spot as to where best to logicaly organize it. Perhaps this is very much a purely subjective matter; so I'm just then looking for other peoples' opinions and practices, to help sway me one way or the other. Also, how about images that the templates use? In my mind images don't belong anywhere under the cgi-bin - where do you guys put your image files? As a final question - do you put your petal "view"/"controler"/"helper" modules ( i.e. my "FooBar.pm" ) in along with the cgi scripts themselves under cgi-bin, or do you put those somewhere else on the system? I appreciate the info, I'm very interested in what other folks are doing. ( I'll be moving from a simple cgi-scripts-with-modules methodology to porting all this to a more pure MVC approach using catalyst in a few months, but the app hasn't quite grown to the point where it really warrants that move just yet ) Thanks! Corey From bruno at mkdoc.com Tue Jun 27 11:27:38 2006 From: bruno at mkdoc.com (Bruno Postle) Date: Tue Jun 27 11:27:47 2006 Subject: [Petal] best practices question(s) In-Reply-To: <200606231321.48831.corey_s@qwest.net> References: <200606231321.48831.corey_s@qwest.net> Message-ID: <20060627102737.GA20871@mkdoc.com> On Fri 23-Jun-2006 at 13:21 -0700, Corey wrote: > > Where "best" to put the pe(tal) templates -- under the > cgi-bin or under the htdocs? i.e: > > * /var/www/localhost/cgi-bin/foobar/ > OR > * /var/www/localhost/htdocs/foobar/ Neither, as there is no need for remote users to access the files directly. Though I can't think of a specific security issue with doing this, I wouldn't describe it as good practice. > where do you guys put your image files? Static images need to be accessible to remote users, so these go in htdocs. > As a final question - do you put your petal "view"/"controler"/"helper" > modules ( i.e. my "FooBar.pm" ) in along with the cgi scripts > themselves under cgi-bin, or do you put those somewhere else > on the system? It depends how you intend to maintain them. Something we try to do is create them as standalone perl modules and install them the same as any CPAN module. -- Bruno From petal-list at 2xlp.com Tue Jun 27 22:49:06 2006 From: petal-list at 2xlp.com (Jonathan Vanasco) Date: Tue Jun 27 22:49:28 2006 Subject: [Petal] best practices question(s) In-Reply-To: <20060627102737.GA20871@mkdoc.com> References: <200606231321.48831.corey_s@qwest.net> <20060627102737.GA20871@mkdoc.com> Message-ID: <724D7662-2779-4E14-8149-3A24E8E4676C@2xlp.com> > On Fri 23-Jun-2006 at 13:21 -0700, Corey wrote: >> >> Where "best" to put the pe(tal) templates -- under the >> cgi-bin or under the htdocs? i.e: >> >> * /var/www/localhost/cgi-bin/foobar/ >> OR >> * /var/www/localhost/htdocs/foobar/ i'd stay away from that model completely i have things as such ( as an svn tree in /usr/local/www/sites/APPNAME ) /lib/ /lib-external/ /www/ /3ld.2ld.1ld/ lib are perlmodules for my app 'cgi-bin' lib-external are support modules www is the root for htdocs apache2 is configured to server out of www , which has domain specific files urls are mapped onto mod-perl for handling specific urls out of the lib directory cgi-bin stuff is so web1999 | - - - - - - - - - - - - - - - - - - - - | RoadSound.com / Indie-Rock.net | Collaborative Online Management And Syndication Tools | - - - - - - - - - - - - - - - - - - - - From corey_s at qwest.net Fri Jun 30 19:33:50 2006 From: corey_s at qwest.net (Corey) Date: Sat Jul 1 20:33:37 2006 Subject: [Petal] petal:define question Message-ID: <200606301133.50273.corey_s@qwest.net> I'm totally stumped here, and can use some expert knowledge from the list. Simplified explanation/example: I have a method called echo, looks like this: sub echo { my $self = shift; my $value = shift; return $value; } I stuff my object into $vcc, which gets passed to my template. Template looks like this:

---

As I hope can be seen, I expect the following: GOOBER GOOBER --- BLAH BLAH However... what I get is: GOOBER GOOBER --- BLAH GOOBER What's going on here? It doesn't matter how I arrange things, the same behavior persists: where a variable that's been reused ( even though it's been successfully redifined - as can be seen ) and passed to a method or subroutine, the method in question somehow gets stuffed with whatever the _initial_/_first_ definition of the "petal:define'd" variable was... Thanks for enlightening me! Sorry if I missed something obvious somewhere. Cheers, Corey From corey_s at qwest.net Fri Jun 30 19:57:17 2006 From: corey_s at qwest.net (Corey) Date: Sat Jul 1 20:34:18 2006 Subject: [Petal] Re: petal:define question In-Reply-To: <200606301133.50273.corey_s@qwest.net> References: <200606301133.50273.corey_s@qwest.net> Message-ID: <200606301157.17882.corey_s@qwest.net> Ok, well of course 20 minutes after sending out my question, I found the answer to my own question. I need to 'fresh' it: span petal:define="foobar string:GOOBER" />

---

...works like charm. I somehow missed that even after reading the Petal perldoc many times. ugh. Sorry for the noise. Cheers, Corey On Friday 30 June 2006 11:33, Corey wrote: > > I'm totally stumped here, and can use some expert knowledge from > the list. > > > Simplified explanation/example: > > I have a method called echo, looks like this: > > sub echo { > my $self = shift; > my $value = shift; > > return $value; > } > > I stuff my object into $vcc, which gets passed to my > template. Template looks like this: > > >

>

> >

---

> > >

>

> > > As I hope can be seen, I expect the following: > > GOOBER > GOOBER > --- > BLAH > BLAH > > > However... what I get is: > > GOOBER > GOOBER > --- > BLAH > GOOBER > > > What's going on here? > > It doesn't matter how I arrange things, the same behavior persists: where > a variable that's been reused ( even though it's been successfully redifined - > as can be seen ) and passed to a method or subroutine, the method in > question somehow gets stuffed with whatever the _initial_/_first_ definition > of the "petal:define'd" variable was... > > Thanks for enlightening me! Sorry if I missed something obvious > somewhere. > > > Cheers, > > Corey > From corey_s at qwest.net Fri Jun 30 20:13:46 2006 From: corey_s at qwest.net (Corey) Date: Sat Jul 1 20:34:55 2006 Subject: [Petal] test Message-ID: <200606301213.46305.corey_s@qwest.net> My posts seem to take a long time to hit the list. Testing. sent: friday 30, 12:13