From sf@flacks.net Wed Dec 1 22:59:31 2004 From: sf@flacks.net (Simon Flack) Date: Wed, 1 Dec 2004 22:59:31 +0000 Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <41AC81B1.6020109@glassbrian.com> References: <415C2E08.70605@morcor.com> <419D0161.9090207@glassbrian.com> <41A8FADC.8050306@glassbrian.com> <41A90792.1040409@acm.org> <41A92CD9.20905@glassbrian.com> <20041128131712.M62036@flacks.net> <41AC81B1.6020109@glassbrian.com> Message-ID: <20041201222530.M89600@flacks.net> On Tue, 30 Nov 2004 09:20:33 -0500, Brian Glass wrote > Simon Flack wrote: > > >Forgive me if I'm barking up the wrong tree here, but isn't this a > >Class::DBI::AsForm issue? I seem to remember suggestions that setting the > >Essentials columns appropriately in your CDBI classes would give significant > >performance improvements. Have you tried that, and if so, did it help? > > > >I was also under the impression that the default templates were just examples: > > http://lists.netthink.co.uk/pipermail/maypole/2004-November/000975.html > > > >I'd like to see them stay that way and not over-complicate them. If there is a > >demand for drop-in templates, I suggest creating Maypole separate "theme packs". > > > >--simonflk > > > > Yes it is (an AsForm issue that is). The suggestion to set Essential > columns does indeed help performance - and quite a bit too. But it's > still not enough. When you get back a result set of 3000 rows and > proceed to convert that all to Class::DBI objects and then turn > right around and convert them all to HTML::Element objects, and then > convert them all to HTML it tends to slow things down a bit. Yes, I imagine that would have an impact on performance! > Going straight from a simple array to HTML in a template is much > quicker. It makes the difference between a very sluggish application > and a very snappy application. > > And something still needs to be done about the $classmetadata->{cgi} > auto-creation. I have it commented out in my version of > Maypole::View::Base. If you have any significant ammount of real > data it causes extreme slowness. Agreed, but it depends on your data. I think the problem is that CDBI::AsForm->to_cgi (which is what populates classmetadata.cgi) creates the HTML for all the columns (disregarding Essentials). I suppose that's a pretty sensible default since it makes it very easy to get started with Maypole. You just need an easy way of tuning it/turning it off without resorting to sublassing the model. After all, in M::V::TT at least, you can still do this: [% object.to_field('column', 'select').as_HTML %] > I was nearly at the point of giving up on Maypole and going straight > to Class::DBI and HTML::Mason and then I tried these two tweaks and > all is well. I'm actually surprised that nobody else has had these > performance problems. Is anyone else out there using large amounts > of real-world data in thier apps? > > No biggie on the factory templates. I don't really use them much > anyway so I don't care, but it might be nice for beginners to see... > > I think it might be nice to have a thread with real-life examples of > successful Maypole applications. I started using my Maypole app in a > real-life setting on Sunday. I'm developing a church management > system and we're doing child registration with photo ID cards and > the like. We've got over 300 kids per Sunday so we need something > that can match up kids with parents (there are 3465 people in our > database) in a secure way. The app will be GPL and I'll be setting > it up on sourceforge sometime in the next couple months. The > application will take photos using any webcam (either an IP camera > or using camsource), print a plastic ID card (using a custum perl > Zebra printer driver), read the barcode on the card (using a > keyboard wedge barcode scanner), print stickers (DYMO printers) to > put on the kids, and keep track of attendance. We're using firefox > as the browser and will be setting up kiosks based on LTSP with ELO > touch screens for people to sign in at and scan thier cards. It all > runs from a Dell Inspirion 1100 laptop since it has to be > portable... And it's all Maypole driven. > > Anyone else? (might want to start a new thread) > > _______________________________________________ > maypole mailing list > maypole@lists.netthink.co.uk > http://lists.netthink.co.uk/listinfo/maypole --simonflk From sf@flacks.net Wed Dec 1 23:27:19 2004 From: sf@flacks.net (Simon Flack) Date: Wed, 1 Dec 2004 23:27:19 +0000 Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <20041130192700.54116.qmail@web52101.mail.yahoo.com> References: <41AC81B1.6020109@glassbrian.com> <20041130192700.54116.qmail@web52101.mail.yahoo.com> Message-ID: <20041201230008.M22867@flacks.net> On Tue, 30 Nov 2004 11:27:00 -0800 (PST), Peter Speltz wrote > --- Brian Glass wrote: > > > Simon Flack wrote: > > > > >Forgive me if I'm barking up the wrong tree here, but isn't this a > > >Class::DBI::AsForm issue? I seem to remember suggestions that setting the > > >Essentials columns appropriately in your CDBI classes would give significant > > >performance improvements. Have you tried that, and if so, did it help? > > > > > >I was also under the impression that the default templates were just > > examples: > > > http://lists.netthink.co.uk/pipermail/maypole/2004-November/000975.html > > > > > >I'd like to see them stay that way and not over-complicate them. If there is > > a > > >demand for drop-in templates, I suggest creating Maypole separate "theme > > packs". > > > > > >--simonflk > > > > > > > Yes it is (an AsForm issue that is). The suggestion to set Essential > > columns does indeed help performance - and quite a bit too. But it's > > still not enough. When you get back a result set of 3000 rows and > > proceed to convert that all to Class::DBI objects and then turn right > > around and convert them all to HTML::Element objects, and then convert > > them all to HTML it tends to slow things down a bit. > > > > I started a mapole wiki cookbook page where hopefully we can cook up > good solutions to AsForm issues. Maybe it'd be better off in CDBI > wiki eventually but more maypole users seem to be concerned with it. > For starters i just outlined problems we are having. > > http://maypole.perl.org/?ImprovedAsForm That's very useful. FWIW, I'm planning on spending some time on CDBI::Plugin::Type soon after the next Maypole release. In the meantime, patches are welcome. Actually, I may upload a new version soon just to update the contact information. I can't speak for CDBI::AsForm since that's now maintained by someone else. I think Tony Bowden has taken over. It's probably worth sending a courtesy email that points to that wiki page/this thread in case he misses it. --simonflk From Dave.Howorth@acm.org Thu Dec 2 01:27:13 2004 From: Dave.Howorth@acm.org (Dave Howorth) Date: Thu, 02 Dec 2004 01:27:13 +0000 Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <20041201222530.M89600@flacks.net> References: <415C2E08.70605@morcor.com> <419D0161.9090207@glassbrian.com> <41A8FADC.8050306@glassbrian.com> <41A90792.1040409@acm.org> <41A92CD9.20905@glassbrian.com> <20041128131712.M62036@flacks.net> <41AC81B1.6020109@glassbrian.com> <20041201222530.M89600@flacks.net> Message-ID: <41AE6F71.606@acm.org> >> And something still needs to be done about the >> $classmetadata->{cgi} auto-creation. I have it commented out in my >> version of Maypole::View::Base. If you have any significant ammount >> of real data it causes extreme slowness. > > Agreed, but it depends on your data. I think the problem is that > CDBI::AsForm->to_cgi (which is what populates classmetadata.cgi) > creates the HTML for all the columns (disregarding Essentials). I > suppose that's a pretty sensible default since it makes it very easy > to get started with Maypole. You just need an easy way of tuning > it/turning it off without resorting to sublassing the model. After > all, in M::V::TT at least, you can still do this: > > [% object.to_field('column', 'select').as_HTML %] I was confused for a minute here, until I realized there are two separate topics under discussion. The first one is the classmetadata and I think you're both agreed that it would be nice to have a means to turn it off. Somehow making it evaluate lazily would be another option. Ironic perhaps, but turning it into an object is my first thought :) But the second topic is Brian's original problem, of the slow select generation, and it's the to_field method (or rather its _to_select helper) that causes his problem. So I don't think that calling it by hand in the template is a solution! It seems to me that it would be good for Brian's code to live inside _to_select. Cheers, Dave From ranger@befunk.com Thu Dec 2 04:09:42 2004 From: ranger@befunk.com (Benjamin Reed) Date: Wed, 01 Dec 2004 23:09:42 -0500 Subject: [Maypole] content-type forced to text/html Message-ID: <41AE9586.1050703@befunk.com> I've started setting up a simple site using maypole, but I'm running into an annoying rendering issue in firefox because anything under the control of maypole gets sent as "text/html", even if it's just passing through serving a .css file to apache proper. Is there a way to tell maypole to server it's own stuff as text/html, but for anything else to *not* set the content-type, and let apache figure it out? -- Benjamin Reed, a.k.a. Ranger Rick ranger@befunk.com / http://ranger.befunk.com/ A computer scientist is someone who, when told to 'Go to Hell', sees the 'go to', rather than the destination, as harmful. From sri@oook.de Thu Dec 2 08:04:37 2004 From: sri@oook.de (Sebastian Riedel) Date: Thu, 02 Dec 2004 09:04:37 +0100 Subject: [Maypole] content-type forced to text/html In-Reply-To: <41AE9586.1050703@befunk.com> References: <41AE9586.1050703@befunk.com> Message-ID: <1101974677.4705.7.camel@localhost> Benjamin Reed: > I've started setting up a simple site using maypole, but I'm running > into an annoying rendering issue in firefox because anything under the > control of maypole gets sent as "text/html", even if it's just passing > through serving a .css file to apache proper. > > Is there a way to tell maypole to server it's own stuff as text/html, > but for anything else to *not* set the content-type, and let apache > figure it out? > No it's not that simple, when Maypole sends you a css file it's handling it like a normal TT2 template, it doesn't know it isn't. You can put something like this in your additional_data() $r->content_type('text/css') if $r->template =~ /\.css$/; or this in your css file. ;) [% request.content_type('text/css') %] sebastian From dhoworth@mrc-lmb.cam.ac.uk Thu Dec 2 10:15:56 2004 From: dhoworth@mrc-lmb.cam.ac.uk (Dave Howorth) Date: Thu, 02 Dec 2004 10:15:56 +0000 Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <41AE6F71.606@acm.org> References: <415C2E08.70605@morcor.com> <419D0161.9090207@glassbrian.com> <41A8FADC.8050306@glassbrian.com> <41A90792.1040409@acm.org> <41A92CD9.20905@glassbrian.com> <20041128131712.M62036@flacks.net> <41AC81B1.6020109@glassbrian.com> <20041201222530.M89600@flacks.net> <41AE6F71.606@acm.org> Message-ID: <41AEEB5C.8040609@mrc-lmb.cam.ac.uk> I wrote: > The first one is the classmetadata and I think you're both agreed that > it would be nice to have a means to turn it off. Somehow making it > evaluate lazily would be another option. Ironic perhaps, but turning it > into an object is my first thought :) 'It' is very ambiguous. 'It' was obviously late at night. 'It' is classmetadata.cgi :) Sorry, Dave From dhoworth@mrc-lmb.cam.ac.uk Thu Dec 2 10:20:05 2004 From: dhoworth@mrc-lmb.cam.ac.uk (Dave Howorth) Date: Thu, 02 Dec 2004 10:20:05 +0000 Subject: [Maypole] content-type forced to text/html In-Reply-To: <1101974677.4705.7.camel@localhost> References: <41AE9586.1050703@befunk.com> <1101974677.4705.7.camel@localhost> Message-ID: <41AEEC55.2090401@mrc-lmb.cam.ac.uk> Sebastian Riedel wrote: > Benjamin Reed: >>I've started setting up a simple site using maypole, but I'm running >>into an annoying rendering issue in firefox because anything under the >>control of maypole gets sent as "text/html", even if it's just passing >>through serving a .css file to apache proper. >> >>Is there a way to tell maypole to server it's own stuff as text/html, >>but for anything else to *not* set the content-type, and let apache >>figure it out? > > No it's not that simple, when Maypole sends you a css file it's handling > it like a normal TT2 template, it doesn't know it isn't. > > You can put something like this in your additional_data() > > $r->content_type('text/css') if $r->template =~ /\.css$/; > > or this in your css file. ;) > > [% request.content_type('text/css') %] Another alternative is just to make the reference to the css file an absolute URL so the request for it never goes through Maypole at all. Cheers, Dave From sf@flacks.net Thu Dec 2 12:27:27 2004 From: sf@flacks.net (Simon Flack) Date: Thu, 02 Dec 2004 12:27:27 +0000 Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <41AE6F71.606@acm.org> References: <415C2E08.70605@morcor.com> <419D0161.9090207@glassbrian.com> <41A8FADC.8050306@glassbrian.com> <41A90792.1040409@acm.org> <41A92CD9.20905@glassbrian.com> <20041128131712.M62036@flacks.net> <41AC81B1.6020109@glassbrian.com> <20041201222530.M89600@flacks.net> <41AE6F71.606@acm.org> Message-ID: <41AF0A2F.40306@flacks.net> Dave Howorth wrote: >>> And something still needs to be done about the >>> $classmetadata->{cgi} auto-creation. I have it commented out in my >>> version of Maypole::View::Base. If you have any significant ammount >>> of real data it causes extreme slowness. >> >> >> Agreed, but it depends on your data. I think the problem is that >> CDBI::AsForm->to_cgi (which is what populates classmetadata.cgi) >> creates the HTML for all the columns (disregarding Essentials). I >> suppose that's a pretty sensible default since it makes it very easy >> to get started with Maypole. You just need an easy way of tuning >> it/turning it off without resorting to sublassing the model. After >> all, in M::V::TT at least, you can still do this: >> >> [% object.to_field('column', 'select').as_HTML %] > > > I was confused for a minute here, until I realized there are two > separate topics under discussion. Separate, but related. > The first one is the classmetadata and I think you're both agreed that > it would be nice to have a means to turn it off. Somehow making it > evaluate lazily would be another option. Ironic perhaps, but turning it > into an object is my first thought :) > > But the second topic is Brian's original problem, of the slow select > generation, and it's the to_field method (or rather its _to_select > helper) that causes his problem. So I don't think that calling it by > hand in the template is a solution! It seems to me that it would be good > for Brian's code to live inside _to_select. My point was really, that if you can turn off classmetadata.cgi then you can still call to_field() on the columns which don't require large lookups. I'm not sure that Brian's code needs to be in _to_select, because the ->retrieve_all() should only populate the Essentials columns. OTOH, someone mentioned earlier that the Essentials may not map directly to what you want in the AsForm lookups. Class::DBI::TempEssential may be a solution to that though. --simonflk From sf@flacks.net Thu Dec 2 12:29:41 2004 From: sf@flacks.net (Simon Flack) Date: Thu, 02 Dec 2004 12:29:41 +0000 Subject: [Maypole] content-type forced to text/html In-Reply-To: <41AEEC55.2090401@mrc-lmb.cam.ac.uk> References: <41AE9586.1050703@befunk.com> <1101974677.4705.7.camel@localhost> <41AEEC55.2090401@mrc-lmb.cam.ac.uk> Message-ID: <41AF0AB5.90706@flacks.net> Dave Howorth wrote: > Sebastian Riedel wrote: > >> Benjamin Reed: >> >>> I've started setting up a simple site using maypole, but I'm running >>> into an annoying rendering issue in firefox because anything under >>> the control of maypole gets sent as "text/html", even if it's just >>> passing through serving a .css file to apache proper. >>> >>> Is there a way to tell maypole to server it's own stuff as text/html, >>> but for anything else to *not* set the content-type, and let apache >>> figure it out? >> >> >> No it's not that simple, when Maypole sends you a css file it's handling >> it like a normal TT2 template, it doesn't know it isn't. >> >> You can put something like this in your additional_data() >> >> $r->content_type('text/css') if $r->template =~ /\.css$/; >> >> or this in your css file. ;) >> >> [% request.content_type('text/css') %] > > > Another alternative is just to make the reference to the css file an > absolute URL so the request for it never goes through Maypole at all. Another option I've been mulling over is to add File::Type or File::MMagic to the list of dependencies, and auto-detect the mime type. --simonflk From simon@simon-cozens.org Thu Dec 2 12:32:04 2004 From: simon@simon-cozens.org (Simon Cozens) Date: Thu, 2 Dec 2004 12:32:04 +0000 Subject: [Maypole] content-type forced to text/html In-Reply-To: <41AF0AB5.90706@flacks.net> References: <41AE9586.1050703@befunk.com> <1101974677.4705.7.camel@localhost> <41AEEC55.2090401@mrc-lmb.cam.ac.uk> <41AF0AB5.90706@flacks.net> Message-ID: <20041202123204.GA25387@alibi.simon-cozens.org> Simon Flack: > Another option I've been mulling over is to add File::Type or > File::MMagic to the list of dependencies, and auto-detect the mime type. This is worth doing for things which have to be processed by Maypole, but it's better (also) to use a handler which DECLINEs those files which don't need to be processed. -- 0x5: Thou shalt not decrease entropy 0x6: Thou shalt not connect PWR to GND 0x7: Thou shalt not sex toads 0x8: Thou shalt not exceed the speed of light - 0x10 Commandments, Our Lady Of The All-Night Tool From peterspeltz@yahoo.com Thu Dec 2 19:21:02 2004 From: peterspeltz@yahoo.com (Peter Speltz) Date: Thu, 2 Dec 2004 11:21:02 -0800 (PST) Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <41AE6F71.606@acm.org> Message-ID: <20041202192102.41951.qmail@web52103.mail.yahoo.com> > > But the second topic is Brian's original problem, of the slow select > generation, and it's the to_field method (or rather its _to_select > helper) that causes his problem. So I don't think that calling it by > hand in the template is a solution! It seems to me that it would be good > for Brian's code to live inside _to_select. > It, putting this in _to_select, is desireable but It is tricky because the text for the option is the stringify of the object so you need the object to get that EXCEPT if this is set via "columns(Stringify" I believe. So, it seems there has to be a little more communication between AsForm and the model class to let _to_select know do this the efficient way ONLY IF the stringify value is set via a sub. Does this sound about right? My idea is to make a sql_select_box_data via set_sql that would return id and columns you want in string to appear in the select box. Then if (@select_box_cols = $class->select_box_cols || $class->columns('Stringify') ) { # Do it efficient way, no object creation my $sth = $class->sql_select_box_data; # Someone fill in here } else { # current inefficient way } ===== pjs __________________________________ Do you Yahoo!? Take Yahoo! Mail with you! Get it on your mobile phone. http://mobile.yahoo.com/maildemo From peterspeltz@yahoo.com Thu Dec 2 19:22:50 2004 From: peterspeltz@yahoo.com (Peter Speltz) Date: Thu, 2 Dec 2004 11:22:50 -0800 (PST) Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <41AEEB5C.8040609@mrc-lmb.cam.ac.uk> Message-ID: <20041202192250.58206.qmail@web52110.mail.yahoo.com> First i replied just to sender, then replied to wrong list, now replying to correct list. Sorry bout the duplicates. --- Dave Howorth wrote: > I wrote: > > The first one is the classmetadata and I think you're both agreed that > > it would be nice to have a means to turn it off. Somehow making it > > evaluate lazily would be another option. Ironic perhaps, but turning it > > into an object is my first thought :) > > 'It' is very ambiguous. 'It' was obviously late at night. 'It' is > classmetadata.cgi :) > > Sorry, Dave > I was thinking in the view::base where "IT" is created of doing something like this: . . . cgi => $r->template_args{classmetadata_cgi} || { $class->to_cgi } . . . Then the model's sub can make them if it wants or set it to "1" to get none or do nothing and get them. > > _______________________________________________ > maypole mailing list > maypole@lists.netthink.co.uk > http://lists.netthink.co.uk/listinfo/maypole > ===== pjs __________________________________ Do you Yahoo!? Take Yahoo! Mail with you! Get it on your mobile phone. http://mobile.yahoo.com/maildemo From sethg@ropine.com Thu Dec 2 20:20:12 2004 From: sethg@ropine.com (Seth Gordon) Date: Thu, 02 Dec 2004 15:20:12 -0500 Subject: [Maypole] the subtleties of many-to-many stringification Message-ID: <41AF78FC.5030500@ropine.com> Work on my Maypolized library database is continuing apace, but I'm confused by a certain detail. My database has a "titles" table, an "authors" table, and a "title_author_rel" table linking the two: CREATE TABLE title_author_rel ( title_id integer, author_id integer, relationship character(6) DEFAULT 'by'::bpchar -- 'by', 'ed.', 'trans.', etc. ); I set up the relationship in my application package... package JeevesLibrary; #... JeevesLibrary::TitleAuthorRel->has_a(title_id => 'JeevesLibrary::Titles'); JeevesLibrary::TitleAuthorRel->has_a(author_id => 'JeevesLibrary::Authors'); JeevesLibrary::Titles->has_many(authors => [ JeevesLibrary::TitleAuthorRel => author_id ]); JeevesLibrary::Authors->has_many(titles => [ JeevesLibrary::TitleAuthorRel => title_id ]); ...and everything Just Worked, except for one small detail: the "authors" list on the ...library/titles/view/#### page just has the authors' names, and not the relationships. I can make the list show relationships by changing the many-to-many relationship and defining how to stringify title_author_rel: package JeevesLibrary; #... JeevesLibrary::Titles->has_many(authors => 'JeevesLibrary::TitleAuthorRel'); # ... # ... package JeevesLibrary::TitleAuthorRel; #... sub stringify_self { my $self = shift; return $self->relationship . ' ' . $self->author_id; } This makes the names in the authors list show up a "by Smith" instead of just "Smith", but then the links take me to a title_author_rel/view/### page instead of an author_view/### page. I tried adding a view method to JeevesLibrary::TitleAuthorRel that would look up the appropriate author object and swap it in (an object switcheroo rather than the template switcheroo), but When I try to add a "sub view :Exported {}" method to one of my model packages, my module gets a compilation error: Couldn't require JeevesLibrary - Invalid CODE attribute: Exported at /home/sethg/bin/JeevesLibrary.pm line 106 Well, *that*'s damn strange. I worked around this by overriding the process method in JeevesLibrary::TitleAuthorRel: sub process { my ($class, $r) = @_; my $method = $r->action; return if $r->{template}; $r->{template} = $method; $r->objects( [] ); my $tar = $class->retrieve($r->{args}->[0]); if ($tar) { my $author = $tar->author_id; $r->objects( [$author] ) if $author; } $r->model_class('JeevesLibrary::Authors'); $r->{template_args}{title} = ' author / ' . $r->config->application_name; JeevesLibrary::Authors->$method($r, $author, @{ $r->{args} } ); } This seems to work, but I am still wondering (a) why I can't add :Exported methods, dammit (b) if there is a more elegant way to do the same thing -- // seth gordon // sethg@ropine.com // http://dynamic.ropine.com/yo/ // From peterspeltz@yahoo.com Thu Dec 2 20:47:18 2004 From: peterspeltz@yahoo.com (Peter Speltz) Date: Thu, 2 Dec 2004 12:47:18 -0800 (PST) Subject: [Maypole] the subtleties of many-to-many stringification In-Reply-To: <41AF78FC.5030500@ropine.com> Message-ID: <20041202204718.92887.qmail@web52108.mail.yahoo.com> --- Seth Gordon wrote: > Work on my Maypolized library database is continuing apace, but I'm > confused by a certain detail. > > My database has a "titles" table, an "authors" table, and a > "title_author_rel" table linking the two: > > CREATE TABLE title_author_rel ( > title_id integer, > author_id integer, > relationship character(6) DEFAULT 'by'::bpchar > -- 'by', 'ed.', 'trans.', etc. > ); > > I set up the relationship in my application package... > > package JeevesLibrary; > #... > JeevesLibrary::TitleAuthorRel->has_a(title_id => 'JeevesLibrary::Titles'); > JeevesLibrary::TitleAuthorRel->has_a(author_id => 'JeevesLibrary::Authors'); > > JeevesLibrary::Titles->has_many(authors => > [ JeevesLibrary::TitleAuthorRel => author_id ]); > JeevesLibrary::Authors->has_many(titles => > [ JeevesLibrary::TitleAuthorRel => title_id ]); > > > ...and everything Just Worked, except for one small detail: the > "authors" list on the ...library/titles/view/#### page just has the > authors' names, and not the relationships. > Isn't this what you want since you looking at the title already? > I can make the list show relationships by changing the many-to-many > relationship and defining how to stringify title_author_rel: > > package JeevesLibrary; > #... > JeevesLibrary::Titles->has_many(authors => 'JeevesLibrary::TitleAuthorRel'); > # ... > # ... > package JeevesLibrary::TitleAuthorRel; > #... > sub stringify_self { > my $self = shift; > return $self->relationship . ' ' . $self->author_id; > } > > This makes the names in the authors list show up a "by Smith" instead of > just "Smith", but then the links take me to a title_author_rel/view/### > page instead of an author_view/### page. > > I tried adding a view method to JeevesLibrary::TitleAuthorRel that would > look up the appropriate author object and swap it in (an object > switcheroo rather than the template switcheroo), but > When I try to add a "sub view :Exported {}" method to one of my model > packages, my module gets a compilation error: > > Couldn't require JeevesLibrary - Invalid CODE attribute: Exported at > /home/sethg/bin/JeevesLibrary.pm line 106 > > Well, *that*'s damn strange. > > I worked around this by overriding the process method in > JeevesLibrary::TitleAuthorRel: > > sub process { > my ($class, $r) = @_; > my $method = $r->action; > return if $r->{template}; > $r->{template} = $method; > $r->objects( [] ); > my $tar = $class->retrieve($r->{args}->[0]); > if ($tar) { > my $author = $tar->author_id; > $r->objects( [$author] ) if $author; > } > $r->model_class('JeevesLibrary::Authors'); > $r->{template_args}{title} = > ' author / ' . $r->config->application_name; > JeevesLibrary::Authors->$method($r, $author, @{ $r->{args} } ); > } > > This seems to work, but I am still wondering > > (a) why I can't add :Exported methods, dammit don't know, This used to happen to me happen sometimes. Do you have an overrident process method in a base model class? I think it was syntax errors or my overriden process method in my base model class or maybe an upgrade. Sorry not more helpful. > (b) if there is a more elegant way to do the same thing > Do the object switcheroo in the view Template instead, maybe or just modify the template. Isn't authors an array possibly? I can't see how view template handles that as it seems to print the column. Does TT2 automatically print all elements of array? ===== pjs __________________________________ Do you Yahoo!? The all-new My Yahoo! - What will yours do? http://my.yahoo.com From sethg@ropine.com Thu Dec 2 21:27:08 2004 From: sethg@ropine.com (Seth Gordon) Date: Thu, 02 Dec 2004 16:27:08 -0500 Subject: [Maypole] the subtleties of many-to-many stringification In-Reply-To: <20041202204718.92887.qmail@web52108.mail.yahoo.com> References: <20041202204718.92887.qmail@web52108.mail.yahoo.com> Message-ID: <41AF88AC.1050202@ropine.com> >>...and everything Just Worked, except for one small detail: the >>"authors" list on the ...library/titles/view/#### page just has the >>authors' names, and not the relationships. >> > > > Isn't this what you want since you looking at the title already? If a book is *written by* Smith and *edited by* Jones, the title_author_rel table will record "by" and "ed.", respectively, in the relationship field. When I do my funky dance with JeevesLibrary::TitleAuthorRel::process, a titles/view page will show me GREAT AMERICAN NOVEL ... Authors * by Smith * ed. Jones whereas if I just set up all the relationships in their default fashions, I get GREAT AMERICAN NOVEL ... Authors * Smith * Jones >>(a) why I can't add :Exported methods, dammit Aha! It has to do with the order of module loading. (All of my model classes are in the JeevesLibrary.pm file, which may be a contributing factor.) If I wrap the call to JeevesLibrary->setup in a BEGIN block, then I can add the exported methods. Now I can implement a search method..... >>(b) if there is a more elegant way to do the same thing >> > > > Do the object switcheroo in the view Template instead, maybe or just modify the > template. Hmm. My gut feeling is that this kind of mangling should stay in the model, but I'm not sure I can really justify that as more than a pedantic desire to see how much I can do without touching the default templates. I suspect that the OO-philosophically-ideal way to handle this would be to create a new subclass of Class::DBI::Relationship -- perhaps calling it Class::DBI::Relationship::HasAWithQualifier -- and use that to describe the relationship between title_author_rel and authors. > Isn't authors an array possibly? I can't see how view template handles that as > it seems to print the column. Does TT2 automatically print all elements of > array? One-to-many relationships in the "view" page are handled by the view_related macro, which the view template calls. -- // seth gordon // sethg@ropine.com // http://dynamic.ropine.com/yo/ // From peterspeltz@yahoo.com Thu Dec 2 22:12:26 2004 From: peterspeltz@yahoo.com (Peter Speltz) Date: Thu, 2 Dec 2004 14:12:26 -0800 (PST) Subject: [Maypole] the subtleties of many-to-many stringification In-Reply-To: <41AF88AC.1050202@ropine.com> Message-ID: <20041202221226.68277.qmail@web52105.mail.yahoo.com> --- Seth Gordon wrote: > >>...and everything Just Worked, except for one small detail: the > >>"authors" list on the ...library/titles/view/#### page just has the > >>authors' names, and not the relationships. > >> > > > > > > Isn't this what you want since you looking at the title already? > > If a book is *written by* Smith and *edited by* Jones, the > title_author_rel table will record "by" and "ed.", respectively, in the > relationship field. > > When I do my funky dance with JeevesLibrary::TitleAuthorRel::process, a > titles/view page will show me > > GREAT AMERICAN NOVEL > ... > Authors > * by Smith > * ed. Jones > > whereas if I just set up all the relationships in their default > fashions, I get > > GREAT AMERICAN NOVEL > ... > Authors > * Smith > * Jones > I see there are differnt types of authors. I understand the general problem now. > >>(a) why I can't add :Exported methods, dammit > > Aha! It has to do with the order of module loading. (All of my model > classes are in the JeevesLibrary.pm file, which may be a contributing > factor.) If I wrap the call to JeevesLibrary->setup in a BEGIN block, > then I can add the exported methods. > > Now I can implement a search method..... > Cool. Good to know. That must have been what it was for me. I was requireing modules in wrong order at one time, too. > >>(b) if there is a more elegant way to do the same thing > >> > > > > > > Do the object switcheroo in the view Template instead, maybe or just modify > the > > template. > > Hmm. My gut feeling is that this kind of mangling should stay in the > model, but I'm not sure I can really justify that as more than a > pedantic desire to see how much I can do without touching the default > templates. > More trouble than its worth most of the time but i understand. > I suspect that the OO-philosophically-ideal way to handle this would be > to create a new subclass of Class::DBI::Relationship -- perhaps calling > it Class::DBI::Relationship::HasAWithQualifier -- and use that to > describe the relationship between title_author_rel and authors. > > > Isn't authors an array possibly? I can't see how view template handles that > as > > it seems to print the column. Does TT2 automatically print all elements of > > array? > > One-to-many relationships in the "view" page are handled by the > view_related macro, which the view template calls. > AHAA! That's right. And that's the problem. You need a custom view_related macro for titles to make it link to authors instead. Or if you have only one type of related , authors, then copy it to "view_related_author_title" in the main macros and adjust it to link to author if looking at a title, and title if looking at a author. Then replace "view_related" with "view_related_author_title" in your titles/view. IMO , thats more elegant than overriding process since what you really want is the author_title relationship and not just author or title in these instances. ===== pjs __________________________________ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail From brian@glassbrian.com Fri Dec 3 12:46:27 2004 From: brian@glassbrian.com (Brian Glass) Date: Fri, 03 Dec 2004 07:46:27 -0500 Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <20041202192102.41951.qmail@web52103.mail.yahoo.com> References: <20041202192102.41951.qmail@web52103.mail.yahoo.com> Message-ID: <41B06023.7030200@glassbrian.com> Peter Speltz wrote: >It, putting this in _to_select, is desireable but It is tricky because the text >for the option is the stringify of the object so you need the object to get >that EXCEPT if this is set via "columns(Stringify" I believe. So, it seems >there has to be a little more communication between AsForm and the model class >to let _to_select know do this the efficient way ONLY IF the stringify value is >set via a sub. Does this sound about right? > >My idea is to make a sql_select_box_data via set_sql that would return id and >columns you want in string to appear in the select box. > >Then > if (@select_box_cols = $class->select_box_cols || $class->columns('Stringify') >) { > # Do it efficient way, no object creation > my $sth = $class->sql_select_box_data; > # Someone fill in here >} > >else { > # current inefficient way >} > > > If sub stringify_self is defined then we CANNOT do this the efficient way. stringify_self needs to be called for each row/object and will probably proceed to go out and do more SQL queries. Only if the stringifying is done via __PACKAGE__->columns( Stringify => /foobar/ ) should we do things the efficient way. OTOH, I am using both methods in my class and the select boxes are generated using Stringify and most other things via stringify_self. If I'm not mistaken set_sql does object creation. I think this is what we're trying to avoid in this case so it would probably be better to go with straight DBI. From dhoworth@mrc-lmb.cam.ac.uk Fri Dec 3 14:02:54 2004 From: dhoworth@mrc-lmb.cam.ac.uk (Dave Howorth) Date: Fri, 03 Dec 2004 14:02:54 +0000 Subject: [Maypole] Debugging Maypole apps Message-ID: <41B0720E.4090908@mrc-lmb.cam.ac.uk> I've just spent a few days debugging and getting somewhat tired of having to insert print statements in modules because Maypole::CLI runs everything before the debugger gets a chance to stop the program. Then inspiration flashed and I wrote the script below to let me debug things more easily. I expect somebody will tell me there's an easier way to do this, but just in case there isn't, here it is ... Cheers, Dave ============== #!/usr/bin/perl use strict; use warnings; use UNIVERSAL::require; =pod =head1 Name maypole-test.pl Test harness for Maypole applications that allows the debugger to take control earlier than with raw Maypole::CLI. =head1 Synopsis perl -d maypole-test.pl YourClassName 'http://your/url/' =head1 Description Step through the program and just ignore this warning: Too late to run CHECK block at /Maypole/CLI.pm line 17. Step into the call_url and handler to debug the request workflow. You can also step into the import and turn trace on to debug initialization code. There's probably a better way to do that but I haven't thought about it yet. =cut my ($class, $url) = @ARGV; die "Usage: $0 class url\nor: perl -d $0 class url\n" unless $class and $url and @ARGV == 2; my $cli = 'Maypole::CLI'; $cli->require; $cli->import($class); print $class->call_url($url); From peterspeltz@yahoo.com Fri Dec 3 14:23:36 2004 From: peterspeltz@yahoo.com (Peter Speltz) Date: Fri, 3 Dec 2004 06:23:36 -0800 (PST) Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <41B06023.7030200@glassbrian.com> Message-ID: <20041203142336.75683.qmail@web52108.mail.yahoo.com> --- Brian Glass wrote: > Peter Speltz wrote: > > >It, putting this in _to_select, is desireable but It is tricky because the > text > >for the option is the stringify of the object so you need the object to get > >that EXCEPT if this is set via "columns(Stringify" I believe. So, it seems > >there has to be a little more communication between AsForm and the model > class > >to let _to_select know do this the efficient way ONLY IF the stringify value > is > >set via a sub. Does this sound about right? > > > >My idea is to make a sql_select_box_data via set_sql that would return id > and > >columns you want in string to appear in the select box. > > > >Then > > if (@select_box_cols = $class->select_box_cols || > $class->columns('Stringify') > >) { > > # Do it efficient way, no object creation > > my $sth = $class->sql_select_box_data; > > # Someone fill in here > >} > > > >else { > > # current inefficient way > >} > > > > > > > If sub stringify_self is defined then we CANNOT do this the efficient > way. stringify_self needs to be called for each row/object and will > probably proceed to go out and do more SQL queries. Only if the > stringifying is done via __PACKAGE__->columns( Stringify => /foobar/ ) > should we do things the efficient way. > Exactly. I thought about it more last night. I going to write a stringify self to accept an arrayref, hashref, or object. Then have _to_select do it the efficient way every time. I have a need for sometimes limiting the rows used in a select box , like on category. I'm trying to figure this out. Ideally, an object would have a "sql_select_box_data" sub. I'd like other_classes to be able to override that by making there own statement. Example Employee object with a type. You want to assign an engiineer to a Job Default Employee->sql_select_box_data would be "Select __ESSENTIAL__ from Employee". It would be awesome in my Job class to be able to simply override that with an new sql statement -- "Select __ESSENTIAL from Employee where type = 'Engineer'". Haven't figured out how to do this yet. > OTOH, I am using both methods in my class and the select boxes are > generated using Stringify and most other things via stringify_self. > > If I'm not mistaken set_sql does object creation. I think this is what > we're trying to avoid in this case so it would probably be better to go > with straight DBI. > You are mistaken. sql_* calls return a statement handle. you then execute it. You're thinking of the add_constructor. > _______________________________________________ > maypole mailing list > maypole@lists.netthink.co.uk > http://lists.netthink.co.uk/listinfo/maypole > ===== pjs __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From sethg@ropine.com Fri Dec 3 14:50:59 2004 From: sethg@ropine.com (Seth Gordon) Date: Fri, 03 Dec 2004 09:50:59 -0500 Subject: [Maypole] when dynamic method generation is not your friend In-Reply-To: <41AF88AC.1050202@ropine.com> References: <20041202204718.92887.qmail@web52108.mail.yahoo.com> <41AF88AC.1050202@ropine.com> Message-ID: <41B07D53.4030707@ropine.com> So when I tried to get a page of book titles from my library app, Maypole::CLI would occasionally pass along this error message: Can't use string ("JeevesLibrary::Titles") as a HASH ref while "strict refs" in use at /usr/local/libdata/perl5/site_perl/Class/DBI.pm line 494. In the underlying database, the titles table has an is_public field, so when Class::DBI creates an accessor for that field, it stomps on the is_public method Maypole::Model::CDBI had provided--the method that Maypole was expecting to see when it calls is_applicable. I thought I had a clever workaround involving accessor_name, but at some point in all my BEGIN hackery it stopped working, and I was despondent until I realized there was a brute-force workaround: package JeevesLibrary::Titles; sub is_public { my ($self, $action) = @_; Maypole::Model::CDBI->is_public( $action ); } Humble request to the Maypole maintainers: Please add something to the initialization code that will detect these kinds of conflicts between the database schema and the methods that Maypole expects to see in its model classes, and give the user a more helpful diagnostic message than the one I had to puzzle over. -- "If John Kerry was the last best hope for the Republic ... then maybe it wasn't worth saving in the first place. I don't believe that, though. And neither do you." --Dan Layman-Kennedy // seth gordon // sethg@ropine.com // http://dynamic.ropine.com/yo/ // From sf@flacks.net Fri Dec 3 15:43:59 2004 From: sf@flacks.net (Simon Flack) Date: Fri, 03 Dec 2004 15:43:59 +0000 Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <20041202192250.58206.qmail@web52110.mail.yahoo.com> References: <20041202192250.58206.qmail@web52110.mail.yahoo.com> Message-ID: <41B089BF.4020200@flacks.net> Peter Speltz wrote: > First i replied just to sender, then replied to wrong list, now replying to > correct list. Sorry bout the duplicates. > > > --- Dave Howorth wrote: > > >>I wrote: >> >>>The first one is the classmetadata and I think you're both agreed that >>>it would be nice to have a means to turn it off. Somehow making it >>>evaluate lazily would be another option. Ironic perhaps, but turning it >>>into an object is my first thought :) >> >>'It' is very ambiguous. 'It' was obviously late at night. 'It' is >>classmetadata.cgi :) >> >>Sorry, Dave >> > > > I was thinking in the view::base where "IT" is created of doing something like > this: > > . . . > cgi => $r->template_args{classmetadata_cgi} || { $class->to_cgi } > . . . > > Then the model's sub can make them if it wants or set it to "1" to get none or > do nothing and get them. That looks good. But I'm not sure that it should be controlled by a template parameter. I was going to suggest something in $r->config, but that doesn't smell quite right either. Perhaps it's something that you define on a class-by-class basis. Or perhaps you want different behaviour for different actions in a model? I'd be tempted to change it to: cgi => sub { $class->to_cgi() }, or cgi => sub { $class->to_field(@_) }, That should work quite nicely for M::V::TT - there's no overhead unless you actually use it in the template. I imagine you'd need a different solution for Mason though. --simonflk From dave@riverside-cms.co.uk Fri Dec 3 16:08:25 2004 From: dave@riverside-cms.co.uk (David Baird) Date: Fri, 03 Dec 2004 16:08:25 +0000 Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <41B089BF.4020200@flacks.net> References: <20041202192250.58206.qmail@web52110.mail.yahoo.com> <41B089BF.4020200@flacks.net> Message-ID: <41B08F79.5020800@riverside-cms.co.uk> Simon Flack wrote: > Peter Speltz wrote: >> I was thinking in the view::base where "IT" is created of doing >> something like >> this: >> >> . . . >> cgi => $r->template_args{classmetadata_cgi} || { $class->to_cgi } >> . . . >> >> Then the model's sub can make them if it wants or set it to "1" to get >> none or >> do nothing and get them. > > > That looks good. But I'm not sure that it should be controlled by a > template parameter. I was going to suggest something in $r->config, but > that doesn't smell quite right either. > > Perhaps it's something that you define on a class-by-class basis. Or > perhaps you want different behaviour for different actions in a model? > > I'd be tempted to change it to: > > cgi => sub { $class->to_cgi() }, > or > cgi => sub { $class->to_field(@_) }, > > That should work quite nicely for M::V::TT - there's no overhead unless > you actually use it in the template. I imagine you'd need a different > solution for Mason though. Mason templates are just Perl, so you would say $classmetadata->{cgi}->() instead of $classmetadata->{cgi} Out of interest, how does the call look in TT - is it the same for both cases? Maybe the whole classmetadata thing should be an object? d. From peterspeltz@yahoo.com Fri Dec 3 16:48:48 2004 From: peterspeltz@yahoo.com (Peter Speltz) Date: Fri, 3 Dec 2004 08:48:48 -0800 (PST) Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <41B08F79.5020800@riverside-cms.co.uk> Message-ID: <20041203164848.69101.qmail@web52101.mail.yahoo.com> --- David Baird wrote: > > > Simon Flack wrote: > > Peter Speltz wrote: > >> I was thinking in the view::base where "IT" is created of doing > >> something like > >> this: > >> > >> . . . > >> cgi => $r->template_args{classmetadata_cgi} || { $class->to_cgi } > >> . . . > >> > >> Then the model's sub can make them if it wants or set it to "1" to get > >> none or > >> do nothing and get them. > > > > > > That looks good. But I'm not sure that it should be controlled by a > > template parameter. I was going to suggest something in $r->config, but > > that doesn't smell quite right either. > > To me, since classmetadata is a template_arg essentially, so it would make sense to override it in template_args. which is what you do now. But you have to do this currently and its all or nothing in the current View::Base my $classmetadata = {} $classmetadata->{cgi} = { col1 => ..., }; $classmetadata->{list_columns} = [ . . . ]; # Below wipes out all classmetadata except what's defined above. $r->template_args->{classmetadata} = $classmetadata; It's obvious why that's undesireable to say the least. That's why i like the $r->{template_args}{TopLevel__NextLevel__YetAnotherLevel} method. Old code still works but use $r->{template_args}{classmetadata__whatever} to override individual vars made in View::Base and $r->{template_args}{TopLevel} to override whole heirarchies. NOTE: double underscore separate levels in hash. > > Perhaps it's something that you define on a class-by-class basis. Or > > perhaps you want different behaviour for different actions in a model? > > Not sure what you mean. Each action sub can override whatever it wants. Say in view, you don't want overhead of making cgi or list_columns say this: sub view { ... $r->template_args{classmetadata__list_columns} = 1; $r->template_args(classmetadata__cgi} = 1; .. . } Everything still backward compatible, just a handy optimization and more powerful configuration of template_args. And template sys. independent. > > I'd be tempted to change it to: > > > > cgi => sub { $class->to_cgi() }, > > or > > cgi => sub { $class->to_field(@_) }, > > This looks interesting. > > That should work quite nicely for M::V::TT - there's no overhead unless > > you actually use it in the template. I imagine you'd need a different > > solution for Mason though. > > Mason templates are just Perl, so you would say > > $classmetadata->{cgi}->() > > instead of > > $classmetadata->{cgi} > > Out of interest, how does the call look in TT - is it the same for both > cases? > [% classmetadata.cgi.column %] In TT objects, hashes, lists all use . operator to do their thing. > Maybe the whole classmetadata thing should be an object? > Can you give an example of how that would significantly improve things now? I don't see how it would help but I wouldn't be surprised if it would. > d. > > _______________________________________________ > maypole mailing list > maypole@lists.netthink.co.uk > http://lists.netthink.co.uk/listinfo/maypole > ===== pjs __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From sf@flacks.net Fri Dec 3 16:55:33 2004 From: sf@flacks.net (Simon Flack) Date: Fri, 03 Dec 2004 16:55:33 +0000 Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <41B08F79.5020800@riverside-cms.co.uk> References: <20041202192250.58206.qmail@web52110.mail.yahoo.com> <41B089BF.4020200@flacks.net> <41B08F79.5020800@riverside-cms.co.uk> Message-ID: <41B09A85.30201@flacks.net> David Baird wrote: > > > Simon Flack wrote: > >> Peter Speltz wrote: >> >>> I was thinking in the view::base where "IT" is created of doing >>> something like >>> this: >>> >>> . . . >>> cgi => $r->template_args{classmetadata_cgi} || { $class->to_cgi } >>> . . . >>> >>> Then the model's sub can make them if it wants or set it to "1" to >>> get none or >>> do nothing and get them. >> >> >> >> That looks good. But I'm not sure that it should be controlled by a >> template parameter. I was going to suggest something in $r->config, >> but that doesn't smell quite right either. >> >> Perhaps it's something that you define on a class-by-class basis. Or >> perhaps you want different behaviour for different actions in a model? >> >> I'd be tempted to change it to: >> >> cgi => sub { $class->to_cgi() }, >> or >> cgi => sub { $class->to_field(@_) }, >> >> That should work quite nicely for M::V::TT - there's no overhead >> unless you actually use it in the template. I imagine you'd need a >> different solution for Mason though. > > > Mason templates are just Perl, so you would say > > $classmetadata->{cgi}->() > > instead of > > $classmetadata->{cgi} > > Out of interest, how does the call look in TT - is it the same for both > cases? In the first instance, it'd be something like: [% classmetadata.cgi.field_name %] but if you're calling that multiple times in the same template, you'd want to assign classmetadata.cgi to a temporary variable to avoid creating all the html elements every time: [% elements = classmetadata.cgi %] [% elements.field_name %] [% elements.another_field %] The second option, would look like this: [% classmetadata.cgi('field_name') %] and wouldn't need a temporary variable. But both of these approaches change the current behaviour - the first option keeps the same syntax, but is very expensive if you forget to assign it to a variable. But there may be a way of optimising it in TT, or memoizing the function. --simonflk From sf@flacks.net Fri Dec 3 17:28:44 2004 From: sf@flacks.net (Simon Flack) Date: Fri, 03 Dec 2004 17:28:44 +0000 Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <20041203164848.69101.qmail@web52101.mail.yahoo.com> References: <20041203164848.69101.qmail@web52101.mail.yahoo.com> Message-ID: <41B0A24C.5000209@flacks.net> Peter Speltz wrote: > --- David Baird wrote: > > >> >>Simon Flack wrote: >> >>>Peter Speltz wrote: >>> >>>>I was thinking in the view::base where "IT" is created of doing >>>>something like >>>>this: >>>> >>>> . . . >>>> cgi => $r->template_args{classmetadata_cgi} || { $class->to_cgi } >>>> . . . >>>> >>>>Then the model's sub can make them if it wants or set it to "1" to get >>>>none or >>>>do nothing and get them. >>> >>> >>>That looks good. But I'm not sure that it should be controlled by a >>>template parameter. I was going to suggest something in $r->config, but >>>that doesn't smell quite right either. >>> > > > To me, since classmetadata is a template_arg essentially, so it would make > sense to override it in template_args. which is what you do now. But you have > to do this currently and its all or nothing in the current View::Base > my $classmetadata = {} > $classmetadata->{cgi} = { col1 => ..., }; > $classmetadata->{list_columns} = [ . . . ]; > # Below wipes out all classmetadata except what's defined above. > $r->template_args->{classmetadata} = $classmetadata; It just seems a little odd to me to alter the relationship between the model and the view by setting a template variable. It feels more like a hack than a proper solution. I don't mean any offence, we may have to go with hacks for the short-term to preserve compatability, but I'd like to know what the ideal solution would be first. > It's obvious why that's undesireable to say the least. That's why i like the > $r->{template_args}{TopLevel__NextLevel__YetAnotherLevel} method. Old code > still works but use $r->{template_args}{classmetadata__whatever} to override > individual vars made in View::Base and $r->{template_args}{TopLevel} to > override whole heirarchies. > > NOTE: double underscore separate levels in hash. > > >>>Perhaps it's something that you define on a class-by-class basis. Or >>>perhaps you want different behaviour for different actions in a model? >>> > > > Not sure what you mean. Each action sub can override whatever it wants. Say in > view, you don't want overhead of making cgi or list_columns say this: > sub view { > ... > $r->template_args{classmetadata__list_columns} = 1; > $r->template_args(classmetadata__cgi} = 1; > > .. . > } That syntax looks quirky to me. I'd rather change Maypole::View::Base to set each param individually than to add to the list of parameters that we need to support. > Everything still backward compatible, just a handy optimization and more > powerful configuration of template_args. And template sys. independent. > > >>>I'd be tempted to change it to: >>> >>> cgi => sub { $class->to_cgi() }, >>>or >>> cgi => sub { $class->to_field(@_) }, >>> > > > This looks interesting. > > >>>That should work quite nicely for M::V::TT - there's no overhead unless >>>you actually use it in the template. I imagine you'd need a different >>>solution for Mason though. >> >>Mason templates are just Perl, so you would say >> >> $classmetadata->{cgi}->() >> >>instead of >> >> $classmetadata->{cgi} >> >>Out of interest, how does the call look in TT - is it the same for both >>cases? >> > > > [% classmetadata.cgi.column %] > In TT objects, hashes, lists all use . operator to do their thing. > > >>Maybe the whole classmetadata thing should be an object? >> > > > Can you give an example of how that would significantly improve things now? I > don't see how it would help but I wouldn't be surprised if it would. I'm not sure we need the extra complexity. Everything in 'classmetadata' is already the result of a method call on $class. We could just *always* provide classmetadata.name and make the rest of it optional. Then you can call the methods you're interested in from your template (e.g. with Template::Plugin::Class). And from the sound of it, you can do the same in Mason without a plugin. --simonflk From peterspeltz@yahoo.com Fri Dec 3 19:32:54 2004 From: peterspeltz@yahoo.com (Peter Speltz) Date: Fri, 3 Dec 2004 11:32:54 -0800 (PST) Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <41B0A24C.5000209@flacks.net> Message-ID: <20041203193255.40957.qmail@web52105.mail.yahoo.com> --- Simon Flack wrote: > > It just seems a little odd to me to alter the relationship between the > model and the view by setting a template variable. Well, when a gets relationship is dysfunctional sometimes you simply have to spice it up a little. :) IMO, its changing it any but only making it better. Relationship is still -- View::Base is a good friend to Model and sets some default template_args for it. Models can override them. >It feels more like a > hack than a proper solution. I don't mean any offence, we may have to go > with hacks for the short-term to preserve compatability. but I'd like to > know what the ideal solution would be first. No offense. Its a hack. If i could code the ideal solution on my own I would have submitted a patch already and not wasted my or others's time talking about it :) Is there any chance of knowing the ideal solution soon , so we can go ahead and start using it ? > > In view, you don't want overhead of making cgi or list_columns say this: > > sub view { > > ... > > $r->template_args{classmetadata__list_columns} = 1; > > $r->template_args(classmetadata__cgi} = 1; > > > > .. . > > } > > That syntax looks quirky to me. I'd rather change Maypole::View::Base to > set each param individually than to add to the list of parameters that > we need to support. > Not sure what you mean "add to list ... support". If You mean something like do : $classmetadata->{cgi} = $r->template_args{cgi} || $class->to_cgi -- I like that better too. > >>Maybe the whole classmetadata thing should be an object? > >> > > > > > > Can you give an example of how that would significantly improve things now? > I > > don't see how it would help but I wouldn't be surprised if it would. > > I'm not sure we need the extra complexity. Everything in 'classmetadata' > is already the result of a method call on $class. > > We could just *always* provide classmetadata.name and make the rest of > it optional. Then you can call the methods you're interested in from > your template (e.g. with Template::Plugin::Class). And from the sound of > it, you can do the same in Mason without a plugin. > This might be a good option on or off option for people who want max performance. ===== pjs __________________________________ Do you Yahoo!? The all-new My Yahoo! - What will yours do? http://my.yahoo.com From jester@panix.com Sat Dec 4 04:20:23 2004 From: jester@panix.com (Jesse Sheidlower) Date: Fri, 3 Dec 2004 23:20:23 -0500 Subject: Straight templates (Was: Re: [Maypole] model_class issues on 1.7->2.x upgrade?) In-Reply-To: <20041118210336.66950.qmail@web52105.mail.yahoo.com> References: <20041118194920.GB6774@panix.com> <20041118210336.66950.qmail@web52105.mail.yahoo.com> Message-ID: <20041204042023.GA28780@panix.com> On Thu, Nov 18, 2004 at 01:03:36PM -0800, Peter Speltz wrote: > > --- Jesse Sheidlower wrote: > > > > > Before I spend too much time debugging this, I thought someone > > might have run into this and could help out. > > > > I just upgraded Maypole from 1.7 to 2.04. Several applications > > were unaffected, but one relatively complex one, which has some > > authentication juju going on, had problems. I'm now throwing > > errors of the sort: > > > > caught authenticate error: Can't call method "can" on an undefined > > value at... > > > > with the relevant line, in the main module, being > > > > return $r->model_class->sub_authenticate($r) > > if $r->model_class->can("sub_authenticate"); > > > > What's the main module? You're driver? Are you going to a page that doesn't > have a model class associated with it like a straight template? Wrap above > code in an "if ($r->model_class) { warn "No model classs in sub authenticate; > .. . } and see if everything works ok. Check error log for warnings and see > what situations you get the warning. Just coming back to this after some time working on the real $JOB. Indeed, this was only happening on the frontpage template; anything associated with a model class works fine. Which leads me to two questions: 1. What changed from 1.7 to 2.x so that visiting such a page no longer works, and more to the point what do I need to do under 2.x so that visits to such a page don't fail? Is there a way to default things to the base model class if there's no other? 2. I hadn't realized you can deliberately go to a straight template page. In my apps when I have a plain template, I've been doing things like: sub about_this_site :Exported { my ($self, $r); $r->{template} = "about_this_site"; } But perhaps there's a much better way. Thanks. Jesse Sheidlower From andre@buyerexchange.com Sat Dec 4 15:27:32 2004 From: andre@buyerexchange.com (Andre Sanchez) Date: Sat, 04 Dec 2004 15:27:32 +0000 Subject: [Maypole] Maypole FAQ compromised??? Message-ID: <1102174052.4014.4.camel@localhost.localdomain> It looks like http://maypole.perl.org/?FAQ has been compromised. Is there an explanation? Is this a reflection on the security of Maypole? Thanks. Andre From Danijel.Milicevic@rawmode.org Sat Dec 4 15:43:06 2004 From: Danijel.Milicevic@rawmode.org (Danijel Milicevic) Date: Sat, 04 Dec 2004 16:43:06 +0100 Subject: [Maypole] Maypole FAQ compromised??? In-Reply-To: <1102174052.4014.4.camel@localhost.localdomain> References: <1102174052.4014.4.camel@localhost.localdomain> Message-ID: <1102174986.2227.1.camel@localhost.localdomain> Hi, > It looks like http://maypole.perl.org/?FAQ has been compromised. Is > there an explanation? Is this a reflection on the security of Maypole? > > Thanks. > > Andre Don't confuse Maypole with the maypole.perl.org website. The website is running a Kwiki, which editable by everyone per default. An earlier revision can be restored thou. Regards, Danijel From netthink.co.uk@paulm.com Sat Dec 4 16:02:21 2004 From: netthink.co.uk@paulm.com (Paul Makepeace) Date: Sat, 4 Dec 2004 16:02:21 +0000 Subject: [Maypole] Maypole FAQ compromised??? In-Reply-To: <1102174986.2227.1.camel@localhost.localdomain> References: <1102174052.4014.4.camel@localhost.localdomain> <1102174986.2227.1.camel@localhost.localdomain> Message-ID: <20041204160221.GF23442@mythix.realprogrammers.com> Je 2004-12-04 15:43:06 +0000, Danijel Milicevic skribis: > Hi, > > > It looks like http://maypole.perl.org/?FAQ has been compromised. Is > > there an explanation? Is this a reflection on the security of Maypole? > > > > Thanks. > > > > Andre > > Don't confuse Maypole with the maypole.perl.org website. The website is > running a Kwiki, which editable by everyone per default. An earlier > revision can be restored thou. To do this, AIUI, you click Previous until you return to sanity (but double- check as sometimes they adopt the subtle approach and slip in links here and there). Then click Edit and simply Save. (I've just done all this.) If anyone can improve on this approach I'm sure they'll post ;-) Any open wiki is vulnerable to this abuse without some other kind of content filter. It's unrelated to Maypole's security. Cheers, HTH, Paul -- Paul Makepeace .............................. http://paulm.com/inchoate/ "What is brown and sticky? Do you really want to know." -- http://paulm.com/toys/surrealism/ From sf@flacks.net Sat Dec 4 16:20:52 2004 From: sf@flacks.net (Simon Flack) Date: Sat, 4 Dec 2004 16:20:52 +0000 Subject: Straight templates (Was: Re: [Maypole] model_class issues on 1.7->2.x upgrade?) In-Reply-To: <20041204042023.GA28780@panix.com> References: <20041118194920.GB6774@panix.com> <20041118210336.66950.qmail@web52105.mail.yahoo.com> <20041204042023.GA28780@panix.com> Message-ID: <20041204155639.M12268@flacks.net> On Fri, 3 Dec 2004 23:20:23 -0500, Jesse Sheidlower wrote > On Thu, Nov 18, 2004 at 01:03:36PM -0800, Peter Speltz wrote: > > > > --- Jesse Sheidlower wrote: > > > > > > > > Before I spend too much time debugging this, I thought someone > > > might have run into this and could help out. > > > > > > I just upgraded Maypole from 1.7 to 2.04. Several applications > > > were unaffected, but one relatively complex one, which has some > > > authentication juju going on, had problems. I'm now throwing > > > errors of the sort: > > > > > > caught authenticate error: Can't call method "can" on an undefined > > > value at... > > > > > > with the relevant line, in the main module, being > > > > > > return $r->model_class->sub_authenticate($r) > > > if $r->model_class->can("sub_authenticate"); > > > > > > > What's the main module? You're driver? Are you going to a page that doesn't Indeed, is that code in your driver, or are you referring to call_authenticate() in Maypole.pm? If it's the former, that's your problem. > > have a model class associated with it like a straight template? Wrap above > > code in an "if ($r->model_class) { warn "No model classs in sub authenticate; > > .. . } and see if everything works ok. Check error log for warnings and see > > what situations you get the warning. > > Just coming back to this after some time working on the real $JOB. > > Indeed, this was only happening on the frontpage template; anything > associated with a model class works fine. > > Which leads me to two questions: > > 1. What changed from 1.7 to 2.x so that visiting such a page no > longer works, and more to the point what do I need to do under 2.x > so that visits to such a page don't fail? Is there a way to default > things to the base model class if there's no other? 2.x authenticates plain templates but 1.7 didn't. But that shouldn't cause a problem in itself, it depends what your authenticate() method is doing. When Maypole is given a request that doesn't have a model, or the action isn't public, $r->model_class is undefined. So if you're calling a method on $r->model_class in your authenticate() method, you need to check that there is a model_class first. BTW, Maypole checks to see if there's a model_class->authenticate() and if so, calls it before calling $r->authenticate. So you shouldn't need to do that yourself in your driver's authenticate() method. > 2. I hadn't realized you can deliberately go to a straight template > page. In my apps when I have a plain template, I've been doing > things like: > > sub about_this_site :Exported { > my ($self, $r); > $r->{template} = "about_this_site"; > } > > But perhaps there's a much better way. Yes, if your authenticate() method returns OK for requests that don't have a model_class, you can remove that method and Maypole should take care of it. > Thanks. > > Jesse Sheidlower > > _______________________________________________ > maypole mailing list > maypole@lists.netthink.co.uk > http://lists.netthink.co.uk/listinfo/maypole --simonflk From sf@flacks.net Sat Dec 4 16:36:37 2004 From: sf@flacks.net (Simon Flack) Date: Sat, 4 Dec 2004 16:36:37 +0000 Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <20041203193255.40957.qmail@web52105.mail.yahoo.com> References: <41B0A24C.5000209@flacks.net> <20041203193255.40957.qmail@web52105.mail.yahoo.com> Message-ID: <20041204162613.M44121@flacks.net> On Fri, 3 Dec 2004 11:32:54 -0800 (PST), Peter Speltz wrote > --- Simon Flack wrote: > > > > > It just seems a little odd to me to alter the relationship between the > > model and the view by setting a template variable. > > Well, when a gets relationship is dysfunctional sometimes you simply > have to spice it up a little. :) IMO, its changing it any but only > making it better. Relationship is still -- View::Base is a good > friend to Model and sets some default template_args for it. Models > can override them. > > >It feels more like a > > hack than a proper solution. I don't mean any offence, we may have to go > > with hacks for the short-term to preserve compatability. but I'd like to > > know what the ideal solution would be first. > > No offense. Its a hack. If i could code the ideal solution on my > own I would have submitted a patch already and not wasted my or > others's time talking about it :) Is there any chance of knowing the > ideal solution soon , so we can go ahead and start using it ? I think I'm sold on your idea of setting template_args. It's simple and fairly intuitive and it requires the least amount of work. For more advanced requirements you can still use a custom model/view. So, unless anyone objects, in 2.05 you'll be able to set $r->template_args->{classmetadata}{foo} and the view class won't attempt to set its own classmetadata.foo. It'll also makes it easier to extend classmetadata with properties of your own. --simonflk From jester@panix.com Sat Dec 4 17:14:13 2004 From: jester@panix.com (Jesse Sheidlower) Date: Sat, 4 Dec 2004 12:14:13 -0500 Subject: Straight templates (Was: Re: [Maypole] model_class issues on 1.7->2.x upgrade?) In-Reply-To: <20041204155639.M12268@flacks.net> References: <20041118194920.GB6774@panix.com> <20041118210336.66950.qmail@web52105.mail.yahoo.com> <20041204042023.GA28780@panix.com> <20041204155639.M12268@flacks.net> Message-ID: <20041204171412.GA17775@panix.com> On Sat, Dec 04, 2004 at 04:20:52PM +0000, Simon Flack wrote: > On Fri, 3 Dec 2004 23:20:23 -0500, Jesse Sheidlower wrote > > On Thu, Nov 18, 2004 at 01:03:36PM -0800, Peter Speltz wrote: > > > > > > --- Jesse Sheidlower wrote: > > > > > > > > > > > Before I spend too much time debugging this, I thought someone > > > > might have run into this and could help out. > > > > > > > > I just upgraded Maypole from 1.7 to 2.04. Several applications > > > > were unaffected, but one relatively complex one, which has some > > > > authentication juju going on, had problems. I'm now throwing > > > > errors of the sort: > > > > > > > > caught authenticate error: Can't call method "can" on an undefined > > > > value at... > > > > > > > > with the relevant line, in the main module, being > > > > > > > > return $r->model_class->sub_authenticate($r) > > > > if $r->model_class->can("sub_authenticate"); > > > > > > > > > > What's the main module? You're driver? Are you going to a page that doesn't > > Indeed, is that code in your driver, or are you referring to > call_authenticate() in Maypole.pm? If it's the former, that's your problem. Yes, it was in my driver. I was following the instructions that are in Maypole::Manual::Request, and that are on the Wiki's authentication page. Perhaps these should be changed :-) > > > have a model class associated with it like a straight template? Wrap above > > > code in an "if ($r->model_class) { warn "No model classs in sub authenticate; > > > .. . } and see if everything works ok. Check error log for warnings and see > > > what situations you get the warning. > > > > Just coming back to this after some time working on the real $JOB. > > > > Indeed, this was only happening on the frontpage template; anything > > associated with a model class works fine. > > > > Which leads me to two questions: > > > > 1. What changed from 1.7 to 2.x so that visiting such a page no > > longer works, and more to the point what do I need to do under 2.x > > so that visits to such a page don't fail? Is there a way to default > > things to the base model class if there's no other? > > 2.x authenticates plain templates but 1.7 didn't. But that shouldn't cause a > problem in itself, it depends what your authenticate() method is doing. My authentication routine was not dissimilar to what's in the above-referenced pages. I have different access levels, but the code is straightforward. For now, though, just sticking a return OK if $r->{template} eq "frontpage"; at the top of the routine seems to have done the trick. For this app it's my only template page. Perhaps for others, if I had template pages that did need authentication, I'd have to do more. > When Maypole is given a request that doesn't have a model, or the action isn't > public, $r->model_class is undefined. So if you're calling a method on > $r->model_class in your authenticate() method, you need to check that there is > a model_class first. > > BTW, Maypole checks to see if there's a model_class->authenticate() and if so, > calls it before calling $r->authenticate. So you shouldn't need to do that > yourself in your driver's authenticate() method. See above. It's in the docs! Thanks. Everything's working now! Time to clean up my hacked templates, eh gabbana ;-)? Jesse Sheidlower From sf@flacks.net Sat Dec 4 17:49:42 2004 From: sf@flacks.net (Simon Flack) Date: Sat, 4 Dec 2004 17:49:42 +0000 Subject: Straight templates (Was: Re: [Maypole] model_class issues on 1.7->2.x upgrade?) In-Reply-To: <20041204171412.GA17775@panix.com> References: <20041118194920.GB6774@panix.com> <20041118210336.66950.qmail@web52105.mail.yahoo.com> <20041204042023.GA28780@panix.com> <20041204155639.M12268@flacks.net> <20041204171412.GA17775@panix.com> Message-ID: <20041204172717.M99384@flacks.net> On Sat, 4 Dec 2004 12:14:13 -0500, Jesse Sheidlower wrote > On Sat, Dec 04, 2004 at 04:20:52PM +0000, Simon Flack wrote: > > On Fri, 3 Dec 2004 23:20:23 -0500, Jesse Sheidlower wrote > > > On Thu, Nov 18, 2004 at 01:03:36PM -0800, Peter Speltz wrote: > > > > > > > > --- Jesse Sheidlower wrote: > > > > > > > > > > > > > > Before I spend too much time debugging this, I thought someone > > > > > might have run into this and could help out. > > > > > > > > > > I just upgraded Maypole from 1.7 to 2.04. Several applications > > > > > were unaffected, but one relatively complex one, which has some > > > > > authentication juju going on, had problems. I'm now throwing > > > > > errors of the sort: > > > > > > > > > > caught authenticate error: Can't call method "can" on an undefined > > > > > value at... > > > > > > > > > > with the relevant line, in the main module, being > > > > > > > > > > return $r->model_class->sub_authenticate($r) > > > > > if $r->model_class->can("sub_authenticate"); > > > > > > > > > > > > > What's the main module? You're driver? Are you going to a page that doesn't > > > > Indeed, is that code in your driver, or are you referring to > > call_authenticate() in Maypole.pm? If it's the former, that's your problem. > > Yes, it was in my driver. I was following the instructions that are > in Maypole::Manual::Request, and that are on the Wiki's > authentication page. Perhaps these should be changed :-) Good point. I've made a small change to the wiki to check r->model_class before calling method on it. > > > > have a model class associated with it like a straight template? Wrap above > > > > code in an "if ($r->model_class) { warn "No model classs in sub authenticate; > > > > .. . } and see if everything works ok. Check error log for warnings and see > > > > what situations you get the warning. > > > > > > Just coming back to this after some time working on the real $JOB. > > > > > > Indeed, this was only happening on the frontpage template; anything > > > associated with a model class works fine. > > > > > > Which leads me to two questions: > > > > > > 1. What changed from 1.7 to 2.x so that visiting such a page no > > > longer works, and more to the point what do I need to do under 2.x > > > so that visits to such a page don't fail? Is there a way to default > > > things to the base model class if there's no other? > > > > 2.x authenticates plain templates but 1.7 didn't. But that shouldn't cause a > > problem in itself, it depends what your authenticate() method is doing. > > My authentication routine was not dissimilar to what's in the above-referenced > pages. I have different access levels, but the code is straightforward. > > For now, though, just sticking a > > return OK if $r->{template} eq "frontpage"; > > at the top of the routine seems to have done the trick. For this app > it's my only template page. Perhaps for others, if I had template > pages that did need authentication, I'd have to do more. > > > When Maypole is given a request that doesn't have a model, or the action isn't > > public, $r->model_class is undefined. So if you're calling a method on > > $r->model_class in your authenticate() method, you need to check that there is > > a model_class first. > > > > BTW, Maypole checks to see if there's a model_class->authenticate() and if so, > > calls it before calling $r->authenticate. So you shouldn't need to do that > > yourself in your driver's authenticate() method. > > See above. It's in the docs! Interesting, Maypole has handled model_class->authenticate since 1.0. I suppose authenticate and sub_authenticate are separate hooks, but that's not particularly clear in the docs. --simonflk From Dave.Howorth@acm.org Sat Dec 4 18:35:36 2004 From: Dave.Howorth@acm.org (Dave Howorth) Date: Sat, 04 Dec 2004 18:35:36 +0000 Subject: Straight templates (Was: Re: [Maypole] model_class issues on 1.7->2.x upgrade?) In-Reply-To: <20041204172717.M99384@flacks.net> References: <20041118194920.GB6774@panix.com> <20041118210336.66950.qmail@web52105.mail.yahoo.com> <20041204042023.GA28780@panix.com> <20041204155639.M12268@flacks.net> <20041204171412.GA17775@panix.com> <20041204172717.M99384@flacks.net> Message-ID: <41B20378.4040308@acm.org> Jesse wrote: >>>>>> I just upgraded Maypole from 1.7 to 2.04. Several >>>>>> applications were unaffected, but one relatively complex >>>>>> one, which has some authentication juju going on, had >>>>>> problems. >> Yes, it was in my driver. I was following the instructions that are >> in Maypole::Manual::Request, and that are on the Wiki's >> authentication page. Perhaps these should be changed :-) Hi Jesse, The docs are quite out of date in a number of places. I'm reviewing them so I hope they'll improve soon. If anybody else knows of particular issues in the docs and wants to mail me directly, I'll try to fix them also. > Good point. I've made a small change to the wiki to check > r->model_class before calling method on it. Simon, Authentication isn't an area I've played with yet, so if you could have a look at Request.pod and suggest any changes for that, it would be great. >>> 2.x authenticates plain templates but 1.7 didn't. But that >>> shouldn't cause a problem in itself, it depends what your >>> authenticate() method is doing. Reading this correspondence, I was struck by another aspect of the vanilla HTML files and plain template files (with no Maypole objects) question. Assuming that for some reason one wants to have the Maypole application handle them (pretty URLs?) it would make sense for Maypole to short-circuit their handling, especially in a CGI environment. There's no point in even connecting to the database, let alone going through all the class initialization, if all you're going to do is copy an HTML file to STDOUT, or invoke TT. Cheers, Dave From marcus@thefeed.no Sat Dec 4 18:58:03 2004 From: marcus@thefeed.no (marcus@thefeed.no) Date: Sat, 4 Dec 2004 19:58:03 +0100 (CET) Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <20041204162613.M44121@flacks.net> References: <41B0A24C.5000209@flacks.net> <20041203193255.40957.qmail@web52105.mail.yahoo.com> <20041204162613.M44121@flacks.net> Message-ID: <13123.80.212.236.200.1102186683.squirrel@80.212.236.200> > On Fri, 3 Dec 2004 11:32:54 -0800 (PST), Peter Speltz wrote >> --- Simon Flack wrote: >> No offense. Its a hack. If i could code the ideal solution on my >> own I would have submitted a patch already and not wasted my or >> others's time talking about it :) Is there any chance of knowing the >> ideal solution soon , so we can go ahead and start using it ? > > I think I'm sold on your idea of setting template_args. It's simple and > fairly > intuitive and it requires the least amount of work. For more advanced > requirements you can still use a custom model/view. > > So, unless anyone objects, in 2.05 you'll be able to set > $r->template_args->{classmetadata}{foo} and the view class won't attempt > to > set its own classmetadata.foo. > > It'll also makes it easier to extend classmetadata with properties of your > own. I agree. I think this is a good way to allow for more flexible classmetadata without changing the actual API. Marcus From jester@panix.com Sat Dec 4 20:47:15 2004 From: jester@panix.com (Jesse Sheidlower) Date: Sat, 4 Dec 2004 15:47:15 -0500 Subject: Straight templates (Was: Re: [Maypole] model_class issues on 1.7->2.x upgrade?) In-Reply-To: <41B20378.4040308@acm.org> References: <20041118194920.GB6774@panix.com> <20041118210336.66950.qmail@web52105.mail.yahoo.com> <20041204042023.GA28780@panix.com> <20041204155639.M12268@flacks.net> <20041204171412.GA17775@panix.com> <20041204172717.M99384@flacks.net> <41B20378.4040308@acm.org> Message-ID: <20041204204715.GB28572@panix.com> On Sat, Dec 04, 2004 at 06:35:36PM +0000, Dave Howorth wrote: > > Reading this correspondence, I was struck by another aspect of the > vanilla HTML files and plain template files (with no Maypole objects) > question. Assuming that for some reason one wants to have the Maypole > application handle them (pretty URLs?) Because even a database-driven application will have some static or static-ish pages, and you might as well keep them in the same place and have them handled in the same way. As one of my earlier examples had it, you might very well have an "about" page, or a "contact_info" page, or something else, along with your various search forms and results lists and everything else. When I need such pages, I just write them in TT, and toss them into my custom/ directory. And yes, it would be nice if Maypole could serve these up with as low overhead as possible. Jesse Sheidlower From peterspeltz@yahoo.com Sun Dec 5 05:12:02 2004 From: peterspeltz@yahoo.com (Peter Speltz) Date: Sat, 4 Dec 2004 21:12:02 -0800 (PST) Subject: [Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world) In-Reply-To: <13123.80.212.236.200.1102186683.squirrel@80.212.236.200> Message-ID: <20041205051202.40505.qmail@web52106.mail.yahoo.com> > > I think I'm sold on your idea of setting template_args. It's simple and > > fairly > > intuitive and it requires the least amount of work. For more advanced > > requirements you can still use a custom model/view. > > > > So, unless anyone objects, in 2.05 you'll be able to set > > $r->template_args->{classmetadata}{foo} and the view class won't attempt > > to > > set its own classmetadata.foo. > > > > It'll also makes it easier to extend classmetadata with properties of your > > own. > > I agree. I think this is a good way to allow for more flexible > classmetadata without changing the actual API. > Just to clarify, Maypole always had the flexibility. It just does it inefficiently (but easily) -- makes all default classmetadata and other vars before it even looks at template_args to see if you override them. ===== pjs __________________________________ Do you Yahoo!? The all-new My Yahoo! - Get yours free! http://my.yahoo.com From andre@buyerexchange.com Sun Dec 5 23:59:13 2004 From: andre@buyerexchange.com (Andre Sanchez) Date: Sun, 05 Dec 2004 15:59:13 -0800 Subject: [Maypole] Running Maypole On Fedora 3 Message-ID: <41B3A0D1.3020700@buyerexchange.com> The link below, in the Platform Dependent Gotchas! section says not to run Maypole on the Fedora 2 httpd and mod_perl. http://wiki.simon-cozens.org/index.cgi?InstallationIssues I am running Fedora Core 3, and I am having trouble. Before I go about and uninstall apache and mod_perl, and reinstall them, is this going to solve my problem? Problem: From apache error_log: [Sun Dec 05 15:09:20 2004] [error] [client 127.0.0.1] failed to resolve handler `BeerDB': Can't locate BeerDB.pm in @INC (@INC contains: /home/andre/Maypole-2.04/ex/ ... eventhough: [andre@laptop ex]$ pwd /home/andre/Maypole-2.04/ex [andre@laptop ex]$ ls -l total 16 -rw-r--r-- 1 andre website 1326 Dec 4 08:19 BeerDB.pm -rw-r--r-- 1 andre andre 1218 Dec 4 07:50 BeerDB.pm.bak Thanks for your advice in advanced. --Andre Sanchez From perrin@elem.com Mon Dec 6 00:48:28 2004 From: perrin@elem.com (Perrin Harkins) Date: Sun, 05 Dec 2004 19:48:28 -0500 Subject: [Maypole] Running Maypole On Fedora 3 In-Reply-To: <41B3A0D1.3020700@buyerexchange.com> References: <41B3A0D1.3020700@buyerexchange.com> Message-ID: <1102294108.3455.32.camel@localhost.localdomain> On Sun, 2004-12-05 at 15:59 -0800, Andre Sanchez wrote: > From apache error_log: > > [Sun Dec 05 15:09:20 2004] [error] [client 127.0.0.1] failed to resolve > handler `BeerDB': Can't locate BeerDB.pm in @INC (@INC contains: > /home/andre/Maypole-2.04/ex/ ... > > eventhough: > > [andre@laptop ex]$ pwd > /home/andre/Maypole-2.04/ex > [andre@laptop ex]$ ls -l > total 16 > -rw-r--r-- 1 andre website 1326 Dec 4 08:19 BeerDB.pm > -rw-r--r-- 1 andre andre 1218 Dec 4 07:50 BeerDB.pm.bak Remember that the entire directory path to these files need to be accessible by the user who your server runs as (commonly "nobody"). Try becoming that user and see if you can see those files. - Perrin From bg271828@yahoo.com Mon Dec 6 01:31:33 2004 From: bg271828@yahoo.com (Your Name) Date: Sun, 5 Dec 2004 17:31:33 -0800 (PST) Subject: [Maypole] specifying different names for classmetadata elements Message-ID: <20041206013133.71134.qmail@web53407.mail.yahoo.com> Hi, i want to specify different values for classmtadata.plural and classmetadata.moniker so that without touching the templates i can get better values for these fields than what Maypole gives by getting them from the table names. How do i do this? Thanks, Jen __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From dhoworth@mrc-lmb.cam.ac.uk Mon Dec 6 11:45:43 2004 From: dhoworth@mrc-lmb.cam.ac.uk (Dave Howorth) Date: Mon, 06 Dec 2004 11:45:43 +0000 Subject: [Maypole] specifying different names for classmetadata elements In-Reply-To: <20041206013133.71134.qmail@web53407.mail.yahoo.com> References: <20041206013133.71134.qmail@web53407.mail.yahoo.com> Message-ID: <41B44667.40600@mrc-lmb.cam.ac.uk> Your Name wrote: > Hi, i want to specify different values for > classmtadata.plural and classmetadata.moniker so that > without touching the templates i can get better values > for these fields than what Maypole gives by getting > them from the table names. > > How do i do this? Sorry, but I don't believe it's sensible to try. Maypole's generation of names for output is, IMHO, a mess. I believe you'd do much better to modify the templates to do what you want, for at least two reasons: (1) what you propose may not entirely solve your problem (see below) and (2) it's not something that's particularly easy to do - you'll need to override the whole of classmetadata in template_args or modify the View class, though this may get easier in the next release. I'm working on a different Maypole loader for various reasons, but one is to address this problem. It includes a separate name mangling module. I intend to publish more details in the next day or two. FWIW, here's my understanding of how Maypole generates names: ClassNames are generated from SQL table_names by Class::DBI::Loader::Generic::_table2class() which is called in two places: Maypole::Model::CDBI::class_of() and Class::DBI::Loader::mysql::_load_classes(). _table2class() converts table names to class names, by upper-casing the first letter of words and removing underscores, then prefixing with the namespace. (*** I think Class:DBI::Autoloader does a slightly better job because it deals with any non-alphanumeric separator, not just underscores, and in any case I need to change this to handle plurals ***) Table visibility is determined by config->{display_tables} which makes all tables visible by default. Displayed table names are sometimes (addnew box) obtained from the moniker and moniker_plural methods of the table's model class, which are generated from the class's name by UNIVERSAL::moniker, which is used by Class::DBI. In particular, this means that if your table names are plural then moniker_plural will be singular! At other places (navbar, frontpage), displayed table names are obtained from the template variable config.display_tables, which defaults to the list of raw SQL table names generated by the loader, but can be set explicitly in the config by the application's controller class. Column visibility and order is determined by Maypole::Model::Base::display_columns(), which makes all columns visible and displayed in alphabetical order unless overridden. Displayed column names are generated from SQL column names by Maypole::Model::Base::column_names() Cheers, Dave From sf@flacks.net Mon Dec 6 12:11:30 2004 From: sf@flacks.net (Simon Flack) Date: Mon, 06 Dec 2004 12:11:30 +0000 Subject: [Maypole] specifying different names for classmetadata elements In-Reply-To: <20041206013133.71134.qmail@web53407.mail.yahoo.com> References: <20041206013133.71134.qmail@web53407.mail.yahoo.com> Message-ID: <41B44C72.9050907@flacks.net> Your Name wrote: > Hi, i want to specify different values for > classmtadata.plural and classmetadata.moniker so that > without touching the templates i can get better values > for these fields than what Maypole gives by getting > them from the table names. > > How do i do this? You can define moniker() and plural_moniker() in your model classes. I'm not sure how this would affect the rest of the system. AFAIK, they're only presentational, so it should be ok to do that. They're undocumented at the moment, but I don't see why they couldn't be overridden sensibly. Also, note that the moniker is used in one of the standard template paths. So if you change it, you might need to move some of your templates. --simonflk From tony@kasei.com Mon Dec 6 12:22:49 2004 From: tony@kasei.com (Tony Bowden) Date: Mon, 6 Dec 2004 12:22:49 +0000 Subject: [Maypole] specifying different names for classmetadata elements In-Reply-To: <41B44C72.9050907@flacks.net> References: <20041206013133.71134.qmail@web53407.mail.yahoo.com> <41B44C72.9050907@flacks.net> Message-ID: <20041206122249.GA5242@soto.kasei.com> On Mon, Dec 06, 2004 at 12:11:30PM +0000, Simon Flack wrote: > You can define moniker() and plural_moniker() in your model classes. I'm > not sure how this would affect the rest of the system. AFAIK, they're > only presentational, so it should be ok to do that. They're not only presentational. Class::DBI uses them for a variety of purposes; mostly for guessing arguments in relationships. If you're going to change them you may need to specify more things explicitly in other places, depending on your database set-up. Tony From dhoworth@mrc-lmb.cam.ac.uk Mon Dec 6 17:03:57 2004 From: dhoworth@mrc-lmb.cam.ac.uk (Dave Howorth) Date: Mon, 06 Dec 2004 17:03:57 +0000 Subject: [Maypole] Maypole SQLT->TT loader Message-ID: <41B490FD.6040804@mrc-lmb.cam.ac.uk> I've been working on a loader for Maypole that uses SQLT to read a DDL file. The schema is then pushed through a TT template to generate Perl initialization code for CDBI and Maypole (i.e. it generates BeerDB.pm from beer_d_b.sql) The work isn't finished, but I thought I'd post an early version to get some feedback and because there was a recent question on the Maypole list about table name mangling, which is a feature of this loader. It's at Cheers, Dave -- Dave Howorth MRC Centre for Protein Engineering Hills Road, Cambridge, CB2 2QH 01223 252960 From sri@oook.de Mon Dec 6 17:40:58 2004 From: sri@oook.de (Sebastian Riedel) Date: Mon, 06 Dec 2004 18:40:58 +0100 Subject: [Maypole] Re: [Maypole-dev] CGI::Prototype In-Reply-To: <41B495C5.7000703@flacks.net> References: <41B0A24C.5000209@flacks.net> <20041203193255.40957.qmail@web52105.mail.yahoo.com> <20041204162613.M44121@flacks.net> <41B495C5.7000703@flacks.net> Message-ID: <1102354858.20419.9.camel@localhost> Simon Flack: > > ... or even a CGI::Prototype::Maypole... Recently talked with Randal about this and he was thinking about writing it. ;) > If anyone here gives CGI::Prototype a go, > I'd be interested to hear about their experiences. If you're a fan of classless objects you'll like it... sebastian From sf@flacks.net Mon Dec 6 21:06:05 2004 From: sf@flacks.net (Simon Flack) Date: Mon, 6 Dec 2004 21:06:05 +0000 Subject: [Maypole] Maypole SQLT->TT loader In-Reply-To: <41B490FD.6040804@mrc-lmb.cam.ac.uk> References: <41B490FD.6040804@mrc-lmb.cam.ac.uk> Message-ID: <20041206203639.M9847@flacks.net> On Mon, 06 Dec 2004 17:03:57 +0000, Dave Howorth wrote > I've been working on a loader for Maypole that uses SQLT to read a > DDL file. The schema is then pushed through a TT template to > generate Perl initialization code for CDBI and Maypole (i.e. it > generates BeerDB.pm from beer_d_b.sql) > > The work isn't finished, but I thought I'd post an early version to > get some feedback and because there was a recent question on the > Maypole list about table name mangling, which is a feature of this > loader. It's at It looks interesting. I have a slight aversion to auto-generated code, even when I can control what the code looks like. I think it's because hand-editing the code is usually a pain - e.g. in this case, adding actions. Do you plan on making the code generator support manual edits? --simonflk From Dave.Howorth@acm.org Tue Dec 7 00:31:52 2004 From: Dave.Howorth@acm.org (Dave Howorth) Date: Tue, 07 Dec 2004 00:31:52 +0000 Subject: [Maypole] Maypole SQLT->TT loader In-Reply-To: <20041206203639.M9847@flacks.net> References: <41B490FD.6040804@mrc-lmb.cam.ac.uk> <20041206203639.M9847@flacks.net> Message-ID: <41B4F9F8.8030105@acm.org> > It looks interesting. I have a slight aversion to auto-generated > code, even when I can control what the code looks like. I think it's I sympathize with your aversion, having encountered many bad code generating products in the past. On the other hand, every program you run is auto-generated code of some sort :) > I think it's because hand-editing the code is usually a pain - e.g. > in this case, adding actions. Do you plan on making the code > generator support manual edits? I think you're suggesting some additional hooks, a bit like the ***_config.tt thing. I had a plan to do that, of which the MAYBE_PROCESS macro was an early version. Then I thought, why bother with all that complication when you can just as easily edit the main template? Or just write the actions in a completely separate file. I still haven't made my mind up. I plan to use it on my real project now and see what that throws up, as well as see what feedback I get. So the answer's a definite maybe! Cheers, Dave From dhoworth@mrc-lmb.cam.ac.uk Tue Dec 7 13:04:14 2004 From: dhoworth@mrc-lmb.cam.ac.uk (Dave Howorth) Date: Tue, 07 Dec 2004 13:04:14 +0000 Subject: [Maypole] specifying different names for classmetadata elements In-Reply-To: <20041206122249.GA5242@soto.kasei.com> References: <20041206013133.71134.qmail@web53407.mail.yahoo.com> <41B44C72.9050907@flacks.net> <20041206122249.GA5242@soto.kasei.com> Message-ID: <41B5AA4E.8080900@mrc-lmb.cam.ac.uk> Tony Bowden wrote: > On Mon, Dec 06, 2004 at 12:11:30PM +0000, Simon Flack wrote: >>You can define moniker() and plural_moniker() in your model classes. I'm >>not sure how this would affect the rest of the system. AFAIK, they're >>only presentational, so it should be ok to do that. > > They're not only presentational. > > Class::DBI uses them for a variety of purposes; mostly for guessing > arguments in relationships. Maypole itself uses them as well. It uses them to create the alternative template variable names (i.e. 'beers' for 'objects'). So they'd better continue to have GluedTogetherSemantics; not ideal for displaying Long Table Names. Cheers, Dave From dhoworth@mrc-lmb.cam.ac.uk Tue Dec 7 17:04:08 2004 From: dhoworth@mrc-lmb.cam.ac.uk (Dave Howorth) Date: Tue, 07 Dec 2004 17:04:08 +0000 Subject: [Maypole] bug in macros.tt? Message-ID: <41B5E288.30504@mrc-lmb.cam.ac.uk> I think there's a bug in the maybe_link_view macro. It produces HTML links from fields that are foreign keys to rows in related tables, but is a bit overzealous. It divides fields into two categories, 'objects' and 'non-objects' and it assumes that every object can only be a foreign key. But this isn't true, it could just be a field with an inflated value (such as Time::Piece). Its means of determining whether something is an object is to invoke the thing's 'table' method. This doesn't do the right thing on arbitrary objects :) I suggest instead testing whether the thing inherits from Maypole::Model::Base and this appears to work for me. Here's a patch: --- factory/macros.tt Mon Oct 25 12:21:55 2004 +++ custom/macros.tt Tue Dec 7 16:50:49 2004 @@ -34,14 +33,13 @@ [% MACRO maybe_link_view(object) BLOCK; - IF object.table; # It's an object, i.e. a has-a + IF object.isa('Maypole::Model::Base') ; link(object.table, "view", object.id, object); ELSE; object; Cheers, Dave From marcus@thefeed.no Tue Dec 7 17:22:17 2004 From: marcus@thefeed.no (Marcus Ramberg) Date: Tue, 7 Dec 2004 18:22:17 +0100 Subject: [Maypole] bug in macros.tt? In-Reply-To: <41B5E288.30504@mrc-lmb.cam.ac.uk> References: <41B5E288.30504@mrc-lmb.cam.ac.uk> Message-ID: <8B66BB80-4874-11D9-B27A-000A956D773E@thefeed.no> On 7. des. 2004, at 18.04, Dave Howorth wrote: > I think there's a bug in the maybe_link_view macro. > > It produces HTML links from fields that are foreign keys to rows in > related tables, but is a bit overzealous. It divides fields into two > categories, 'objects' and 'non-objects' and it assumes that every > object can only be a foreign key. But this isn't true, it could just > be a field with an inflated value (such as Time::Piece). > > Its means of determining whether something is an object is to invoke > the thing's 'table' method. This doesn't do the right thing on > arbitrary objects :) I suggest instead testing whether the thing > inherits from Maypole::Model::Base and this appears to work for me. > Here's a patch: This makes sense, I've applied this patch. In the future, it would be nice to have patches against the CPAN distribution (where the file is named macros not macros.tt :) It's easier to apply then. Marcus From dave@riverside-cms.co.uk Tue Dec 7 17:35:52 2004 From: dave@riverside-cms.co.uk (David Baird) Date: Tue, 07 Dec 2004 17:35:52 +0000 Subject: [Maypole] bug in macros.tt? In-Reply-To: <8B66BB80-4874-11D9-B27A-000A956D773E@thefeed.no> References: <41B5E288.30504@mrc-lmb.cam.ac.uk> <8B66BB80-4874-11D9-B27A-000A956D773E@thefeed.no> Message-ID: <41B5E9F8.6060304@riverside-cms.co.uk> Marcus Ramberg wrote: > > On 7. des. 2004, at 18.04, Dave Howorth wrote: > >> I think there's a bug in the maybe_link_view macro. >> >> It produces HTML links from fields that are foreign keys to rows in >> related tables, but is a bit overzealous. It divides fields into two >> categories, 'objects' and 'non-objects' and it assumes that every >> object can only be a foreign key. But this isn't true, it could just >> be a field with an inflated value (such as Time::Piece). >> >> Its means of determining whether something is an object is to invoke >> the thing's 'table' method. This doesn't do the right thing on >> arbitrary objects :) I suggest instead testing whether the thing >> inherits from Maypole::Model::Base and this appears to work for me. >> Here's a patch: > > > This makes sense, I've applied this patch. Ditto for the MasonX::Maypole template. d. From takahashi.kou@aig.co.jp Wed Dec 8 09:00:39 2004 From: takahashi.kou@aig.co.jp (Takahashi, Koutaro) Date: Wed, 8 Dec 2004 18:00:39 +0900 Subject: [Maypole] Maypole on Windows2000 Message-ID: <6DD27F567142A04B9A99002A684FDB00052BA065@shmbx01j.aig.co.jp> Hi, I have been trying to set up Maypole on my Windows2000 machine; however, I am stack. Can anyone describe me how to set up Maypole on Windows? I am using Apache/2.0.52 (Win32) mod_perl/1.99_13 Perl/v5.8.4 Unfortunately I cannot even find a template-toolkit.ppd and other stuff. Are there any websites related to Maypole on Windows? I would appreciate any kind of information. Thanks in advance. Ko From sf@flacks.net Wed Dec 8 10:51:57 2004 From: sf@flacks.net (Simon Flack) Date: Wed, 08 Dec 2004 10:51:57 +0000 Subject: [Maypole] Maypole on Windows2000 In-Reply-To: <6DD27F567142A04B9A99002A684FDB00052BA065@shmbx01j.aig.co.jp> References: <6DD27F567142A04B9A99002A684FDB00052BA065@shmbx01j.aig.co.jp> Message-ID: <41B6DCCD.5090006@flacks.net> Takahashi, Koutaro wrote: > Hi, > > I have been trying to set up Maypole on my Windows2000 machine; however, I > am stack. > Can anyone describe me how to set up Maypole on Windows? > I am using Apache/2.0.52 (Win32) mod_perl/1.99_13 Perl/v5.8.4 > Unfortunately I cannot even find a template-toolkit.ppd and other stuff. Template Toolkit PPMs are available from http://openinteract.sourceforge.net/ppmpackages See http://search.cpan.org/src/PODMASTER/PPM-Repositories-0.09/Repositories.pm for a list of publick PPM repositories. You may need to download some of the dependencies from non-ActiveState repositories. > Are there any websites related to Maypole on Windows? > I would appreciate any kind of information. There was some minimal information on http://maypole.perl.org/?MaypoleOnWindows. But that page is empty now. Let us know how you get on --simonflk From veljko.vidovic@aero.bombardier.com Wed Dec 8 15:03:57 2004 From: veljko.vidovic@aero.bombardier.com (Veljko Vidovic) Date: Wed, 08 Dec 2004 10:03:57 -0500 Subject: [Maypole] Maypole on Windows2000 In-Reply-To: <41B6DCCD.5090006@flacks.net> References: <6DD27F567142A04B9A99002A684FDB00052BA065@shmbx01j.aig.co.jp> <41B6DCCD.5090006@flacks.net> Message-ID: <41B717DD.9080409@aero.bombardier.com> This is a multi-part message in MIME format... ------------=_1102518153-17177-66 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-2022-JP Content-Disposition: inline Simon Flack wrote: >>Can anyone describe me how to set up Maypole on Windows? >>I am using Apache/2.0.52 (Win32) mod_perl/1.99_13 Perl/v5.8.4 >>Unfortunately I cannot even find a template-toolkit.ppd and other stuff. If you are using ActivePerl, there is a problem with Class::DBI. You will have to build CDBI from CPAN, since one from ppm is actualy 0.95, even it says it is 0.96. > There was some minimal information on > http://maypole.perl.org/?MaypoleOnWindows. But that page is empty now. This is entirely my fault. I was able to make Maypole work on Win2K but it was far from stable and with too much tweaks. So, I wanted to try it with Windows Services for UNIX (www.microsoft.com/windows/sfu) and never had time to document it. But I would recommend that path. Regards, Veljko ------------=_1102518153-17177-66 Content-Type: text/plain; name="Disclaimer.txt" Content-Disposition: inline; filename="Disclaimer.txt" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.411 (Entity 5.404) E-mail disclaimer: This message contains information, which is intended for the sole use of the recipient or authorized representative. Any person who receives this e-mail by mistake shall immediately notify the sender and destroy it. E-mail transmissions cannot be guaranteed to be error-free as information could be intercepted, altered, or contain viruses. The sender therefore does not accept any liability for damages caused by the fraudulent alteration of this message including, without limitations, damages caused by any virus transmitted by it. Ce message contient de l'information destin=E9e au seul usage du destinataire ou de son repr=E9sentant autoris=E9. Toute personne qui re=E7oit ce courriel par erreur doit en aviser imm=E9diatement l"exp=E9diteur et d=E9truire le courriel. Les transmissions de courriels ne peuvent =EAtre garanties exemptes d'erreurs puisque l'information peut =EAtre intercept=E9e, modifi=E9e ou contenir des virus. L'exp=E9diteur ne peut donc accepter de responsabilit=E9 quant aux dommages caus=E9s par une modification frauduleuse du message, y compris, sans s'y limiter, tout dommage occasionn=E9 par un virus qu'il aurait transmis. ------------=_1102518153-17177-66-- From sethg@ropine.com Wed Dec 8 21:49:52 2004 From: sethg@ropine.com (Seth Gordon) Date: Wed, 08 Dec 2004 16:49:52 -0500 Subject: [Maypole] using the Authentication::Abstract plugin Message-ID: <41B77700.30700@ropine.com> I'm trying to add a very simple login/logout feature to my application, using Authentication::Abstract. Since I only want my wife and I to have login access, I didn't bother creating a separate database table of users, and I just created a class: package JeevesLibrary::User; use base qw(Class::Accessor); __PACKAGE__->mk_ro_accessors(qw/id/); sub search { my ($class, %params) = @_; my $user = $params{'user'}; my $password = $params{'password'}; print STDERR "about to create a user obj in search\n"; if (($user eq 'sethg' or $user eq 'jen') and $password eq 'xxx') { return $class->new(id => $user); } else { return (); } } sub retrieve { my ($class, $user) = @_; if ($user eq 'sethg' or $user eq 'jen') { print STDERR "about to create a user obj in retrieve\n"; return __PACKAGE__->new(id => $user); } else { return undef; } } I added some code to my main application class to handle logging in and out: package JeevesLibrary; use strict; use Maypole::Application qw(-Debug Authentication::Abstract); use Data::Dumper; use Maypole::Constants; # ... sub authenticate { my $r = shift; $r->private; $r->{template_args}{user} = $r->user->id if $r->user; return OK; } sub additional_data { my $r = shift; $r->logout if $r->params->{logout}; ## ... ## Set up the default order and the page title... ## this is old code that has nothing to do with authentication. ## ... } I added some code to a custom template to provide a login/logout form and to pass along error messages. Results: When I load a page as usual, there's a login form where I expect it to be and everything else works fine. When I type a username and an *incorrect* password, I get a "Bad username or password" error message at the top of the page, and the rest of the page loads normally, just as I would expect. But when I enter the *correct* password, I get a blank page in the browser, and I get the following in my Apache error log: about to create a user obj in search caught authenticate error: Can't use string ("id") as a HASH ref while "strict refs" in use at /usr/local/libdata/perl5/site_perl/Class/Accessor.pm line 136. Can't use string ("id") as a HASH ref while "strict refs" in use at /usr/local/libdata/perl5/site_perl/Class/Accessor.pm line 136. ...caught at /usr/local/libdata/perl5/site_perl/Maypole/View/Base.pm line 74. Use of uninitialized value in concatenation (.) or string at /usr/local/libdata/perl5/site_perl/Apache/MVC.pm line 45. Use of uninitialized value in length at /usr/local/libdata/perl5/site_perl/Apache/MVC.pm line 50. Use of uninitialized value in subroutine entry at /usr/local/libdata/perl5/site_perl/Apache/MVC.pm line 52. When I comment out the Class::Accessor stuff and use a regular blessed hash instead, I don't get the error message and I do get the "Hello, [%user%]" message when I log in. The message doesn't persist when I follow a link or reload the page; I assume that's because I'm not using Apache::Session or some such to persist the fact that I logged in. So my questions for the assembled multitude are: (1) What's wrong with my use of Class::Accessor? (2) What's the simplest way to convert my JeevesLibrary::User class into something that persists appropriately? -- "If John Kerry was the last best hope for the Republic ... then maybe it wasn't worth saving in the first place. I don't believe that, though. And neither do you." --Dan Layman-Kennedy // seth gordon // sethg@ropine.com // http://dynamic.ropine.com/yo/ // From simon@simon-cozens.org Wed Dec 8 22:49:56 2004 From: simon@simon-cozens.org (Simon Cozens) Date: Wed, 8 Dec 2004 22:49:56 +0000 Subject: [Maypole] Maypole on Windows2000 In-Reply-To: <41B717DD.9080409@aero.bombardier.com> References: <6DD27F567142A04B9A99002A684FDB00052BA065@shmbx01j.aig.co.jp> <41B6DCCD.5090006@flacks.net> <41B717DD.9080409@aero.bombardier.com> Message-ID: <20041208224956.GA30028@alibi.simon-cozens.org> Veljko Vidovic: > > There was some minimal information on > > http://maypole.perl.org/?MaypoleOnWindows. But that page is empty now. > This is entirely my fault. I was able to make Maypole work on Win2K but > it was far from stable and with too much tweaks. So, I wanted to try it > with Windows Services for UNIX (www.microsoft.com/windows/sfu) and never > had time to document it. But I would recommend that path. I have been running Maypole applications on Win 2K, and if I remember how I did it, will document the path I took. I remember that it wasn't particularly difficult. -- "OK. Enter system password, out of ttys, can't fork process, Panic Double Panic, can't open socket, bad magic number, NO ROUTE TO HOST, hme is down, stale file handle, /var is full, and it's January 1970." - sing, sing, halt From dave@riverside-cms.co.uk Thu Dec 9 01:24:56 2004 From: dave@riverside-cms.co.uk (David Baird) Date: Thu, 09 Dec 2004 01:24:56 +0000 Subject: [Maypole] Re: [Maypole-dev] [PATCH] Split the guts of the view template into a macro In-Reply-To: References: Message-ID: <41B7A968.7060400@riverside-cms.co.uk> Dagfinn Ilmari Manns=E5ker wrote: > It's me again :) >=20 > I needed to replace just the related part of the view template for some > of my tables, so instead of duplicating most of it, I split the guts of= f > into a view_item macro. I've applied this (and the button patch) to the MasonX::Maypole templates. d. >=20 > Index: templates/factory/macros > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- templates/factory/macros (revision 304) > +++ templates/factory/macros (working copy) > @@ -117,3 +117,57 @@ > END; > END; > %] > +[%# > + > +=3Dhead2 view_item > + > +This takes an object and and displays its properties in a table.=20 > + > +=3Dcut > + > +#%] > +[% MACRO view_item(item) BLOCK; %] > + [% SET string =3D item.stringify_column %] > +
[% item.$string %]
> + [% INCLUDE navbar %] > + > + > + > + > + [% FOR col =3D classmetadata.columns.list; > + NEXT IF col =3D=3D "id" OR col =3D=3D string; > + NEXT UNLESS item.$col; > + %] > +[%#=20 > + > +=3Dfor doc > + > +It gets the displayable form of a column's name from the hash returned > +from the C method: > + > +#%] > + > + > + > + > + [% END; %] > +
[% classmetadata.colnames.$string %] > + [% item.$string %]
[% classmetadata.colnames.$col; %]= > + [% IF col =3D=3D "url" && item.url; # Possibly to= o much magic. > + ' '; item.url; ''; > + ELSE; > + maybe_link_view(item.$col);=20 > + END; %] > +[%# > + > +This tests whether or not the returned value is an object, and if so, > +creates a link to a page viewing that object; if not, it just displays > +the text as normal. The object is linked using its stringified name; > +by default this calls the C method, or returns the object's ID > +if there is no C method or other stringification method defined. > + > +=3Dcut > + > +#%]=20 > +
> +[% END %] > Index: templates/factory/view > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- templates/factory/view (revision 303) > +++ templates/factory/view (working copy) > @@ -11,51 +11,9 @@ > [% PROCESS macros %] > [% INCLUDE header %] > [% FOR item =3D objects %] > - [% SET string =3D item.stringify_column %] > -
[% item.$string %]
> - [% INCLUDE navbar %] > - > - > - > - > - [% FOR col =3D classmetadata.columns.list; > - NEXT IF col =3D=3D "id" OR col =3D=3D string; > - NEXT UNLESS item.$col; > - %] > -[%#=20 > - > -=3Dfor doc > - > -It gets the displayable form of a column's name from the hash returned > -from the C method: > - > -#%] > - > - > - > - > - [% END; %] > -
[% classmetadata.colnames.$string %] > - [% item.$string %]
[% classmetadata.colnames.$col; %]= > - [% IF col =3D=3D "url" && item.url; # Possibly to= o much magic. > - ' '; item.url; ''; > - ELSE; > - maybe_link_view(item.$col);=20 > - END; %] > +[% view_item(item); %] > [%# > =20 > -This tests whether or not the returned value is an object, and if so, > -creates a link to a page viewing that object; if not, it just displays > -the text as normal. The object is linked using its stringified name; > -by default this calls the C method, or returns the object's ID > -if there is no C method or other stringification method defined. > - > -=3Dcut > - > -#%]=20 > -
> -[%# > - > =3Dfor doc > =20 > The C template also displays a list of other objects related to = the first >=20 >=20 From dhoworth@mrc-lmb.cam.ac.uk Thu Dec 9 10:24:21 2004 From: dhoworth@mrc-lmb.cam.ac.uk (Dave Howorth) Date: Thu, 09 Dec 2004 10:24:21 +0000 Subject: [Maypole] Re: [Maypole-dev] [PATCH] Split the guts of the view template into a macro In-Reply-To: References: Message-ID: <41B827D5.60903@mrc-lmb.cam.ac.uk> Dagfinn Ilmari Mannsåker wrote: > I needed to replace just the related part of the view template for some > of my tables, so instead of duplicating most of it, I split the guts off > into a view_item macro. Why not simply split it into two separate templates instead of adding it to (a.k.a. bloating :) the macros file? That seems more the TT way, IMHO. Cheers, Dave From maypole@wintrmute.net Thu Dec 9 15:51:52 2004 From: maypole@wintrmute.net (Toby Corkindale) Date: Thu, 9 Dec 2004 15:51:52 +0000 Subject: [Maypole] Direct access to DBI handle? Message-ID: <20041209155152.GG61075@tigger.mamista.net> Hi, I'm sorry to bother you all with this, but I've had a fair try and finding it myself with no luck so far. I'm using M-Auth-UserSessionCookie, and I want to use Apache::Session::Postgres with the existing database handle that Maypole will have opened a little earlier in the ->setup() call. A-S-Postgres requires one to pass the Handle => $dbh parameter, where $dbh is the open DBI handle. How can I access that? I've traced as far as that ->loader will contain the Class::DBI::Loader object, which is related, but I don't know how to obtain the DBI handle from it.. Thanks, Toby -- Turning and turning in the widening gyre/The falcon cannot hear the falconer; Things fall apart, the centre cannot hold/Mere anarchy is loosed upon the world (gpg --keyserver www.co.uk.pgp.net --recv-key 897E5FF3) From jester@panix.com Thu Dec 9 16:02:32 2004 From: jester@panix.com (Jesse Sheidlower) Date: Thu, 9 Dec 2004 11:02:32 -0500 Subject: [Maypole] Direct access to DBI handle? In-Reply-To: <20041209155152.GG61075@tigger.mamista.net> References: <20041209155152.GG61075@tigger.mamista.net> Message-ID: <20041209160231.GA12103@panix.com> On Thu, Dec 09, 2004 at 03:51:52PM +0000, Toby Corkindale wrote: > Hi, > I'm sorry to bother you all with this, but I've had a fair try and finding it > myself with no luck so far. > > I'm using M-Auth-UserSessionCookie, and I want to use > Apache::Session::Postgres with the existing database handle that Maypole will > have opened a little earlier in the ->setup() call. > > A-S-Postgres requires one to pass the Handle => $dbh parameter, where $dbh is > the open DBI handle. How can I access that? > I've traced as far as that ->loader will contain the Class::DBI::Loader > object, which is related, but I don't know how to obtain the DBI handle from > it.. MyApp::MyClass->db_Main() Best Jesse Sheidlower From maypole@wintrmute.net Thu Dec 9 16:24:26 2004 From: maypole@wintrmute.net (Toby Corkindale) Date: Thu, 9 Dec 2004 16:24:26 +0000 Subject: [Maypole] Direct access to DBI handle? Message-ID: <20041209162426.GI61075@tigger.mamista.net> On Thu, Dec 09, 2004 at 11:02:32AM -0500, Jesse Sheidlower wrote: > On Thu, Dec 09, 2004 at 03:51:52PM +0000, Toby Corkindale wrote: > > Hi, > > I'm sorry to bother you all with this, but I've had a fair try and finding > > it myself with no luck so far. > > > > I'm using M-Auth-UserSessionCookie, and I want to use > > Apache::Session::Postgres with the existing database handle that Maypole > > will have opened a little earlier in the ->setup() call. > > > > A-S-Postgres requires one to pass the Handle => $dbh parameter, where $dbh > > is the open DBI handle. How can I access that? I've traced as far as that > > ->loader will contain the Class::DBI::Loader object, which is related, but > > I don't know how to obtain the DBI handle from it.. > > MyApp::MyClass->db_Main() Thanks! Unfortunately.. I had tried something like that, like so: EHS::Diesel->setup($config->dsn, $config->dbuser, $config->dbpass, { AutoCommit => 1, PrintError => 1 }); # [snip] # Setup Auth stuff for M-A-UserSessionCookie: EHS::Diesel->config->{auth} = { session_class => 'Apache::Session::Postgres', session_args => { Handle => EHS::Diesel->db_Main, Commit => 1 } }; ----- [error] Can't locate object method "db_Main" via package "EHS::Diesel" at /home/tobyc/svn/DieselWorld/lib/Foo/Bar.pm line 34.\nCompilation failed in require at (eval 6) line 3.\n Do I need to do something to ensure it's setup by that stage? thaks, tjc From dhoworth@mrc-lmb.cam.ac.uk Thu Dec 9 16:47:38 2004 From: dhoworth@mrc-lmb.cam.ac.uk (Dave Howorth) Date: Thu, 09 Dec 2004 16:47:38 +0000 Subject: [Maypole] AsForm again - selects? Message-ID: <41B881AA.5070801@mrc-lmb.cam.ac.uk> I'm looking at the addnew form for a table that has a foreign key that is allowed to be null. AsForm has generated a select box for it, which is good (modulo the other issues we know about :) But it's populated the select box with all the existing keys. There doesn't seem to be any way to say that I want a NULL value for this field in my new record. I have SQL like this: CREATE TABLE a_table ( id INT NOT NULL, fk INT, FOREIGN KEY (fk) REFERENCES another_table (id) ) TYPE=InnoDB; and code like this: ATable->has_a( fk => 'AnotherTable' ); AnotherTable->might_have(entries => 'ATable', 'fk'); Is there something else I should be configuring or do I need to think about overriding AsForm? maypole.perl.org seems to be down, so I couldn't check if has anything new. BTW, I'm frequently having trouble getting to perldoc.com over the past few weeks. Is this a shared problem? Are there mirrors? Thanks, Dave From maypole@wintrmute.net Thu Dec 9 16:49:07 2004 From: maypole@wintrmute.net (Toby Corkindale) Date: Thu, 9 Dec 2004 16:49:07 +0000 Subject: [Maypole] Direct access to DBI handle? In-Reply-To: <20041209163327.GA15086@panix.com> References: <20041209155152.GG61075@tigger.mamista.net> <20041209160231.GA12103@panix.com> <20041209161229.GA34389@tigger.mamista.net> <20041209163327.GA15086@panix.com> Message-ID: <20041209164907.GJ61075@tigger.mamista.net> On Thu, Dec 09, 2004 at 11:33:27AM -0500, Jesse Sheidlower wrote: > On Thu, Dec 09, 2004 at 04:12:29PM +0000, Toby Corkindale wrote: > > On Thu, Dec 09, 2004 at 11:02:32AM -0500, Jesse Sheidlower wrote: > > > On Thu, Dec 09, 2004 at 03:51:52PM +0000, Toby Corkindale wrote: [snip] > > > > A-S-Postgres requires one to pass the Handle => $dbh parameter, where > > > > $dbh is the open DBI handle. How can I access that? I've traced as > > > > far as that ->loader will contain the Class::DBI::Loader object, which > > > > is related, but I don't know how to obtain the DBI handle from it.. > > > > > > MyApp::MyClass->db_Main() > > > > Thanks! > > Unfortunately.. I had tried something like that, like so: > > > > EHS::Diesel->setup($config->dsn, $config->dbuser, $config->dbpass, > > { AutoCommit => 1, > > PrintError => 1 > > }); > > Try wrapping the above in a BEGIN block, i.e. > > BEGIN { > EHS::Diesel->setup($config->dsn, $config->dbuser, $config->dbpass, > { AutoCommit => 1, > PrintError => 1 }); > } Thanks. I've just tried this, and unfortunately it didn't change the error message. I'm calling this in my base class, not the model classes - I've used the db_Main() call in them successfully before. Should I try using a dummy class, eg. Handle => EHS::Diesel::Users->db_Main() instead of EHS::Diesel->db_Main()? It seems like the "wrong thing" to do though.. tjc. -- Turning and turning in the widening gyre/The falcon cannot hear the falconer; Things fall apart, the centre cannot hold/Mere anarchy is loosed upon the world (gpg --keyserver www.co.uk.pgp.net --recv-key 897E5FF3) From maypole@wintrmute.net Thu Dec 9 16:58:35 2004 From: maypole@wintrmute.net (Toby Corkindale) Date: Thu, 9 Dec 2004 16:58:35 +0000 Subject: [Maypole] Direct access to DBI handle? In-Reply-To: <20041209164907.GJ61075@tigger.mamista.net> References: <20041209155152.GG61075@tigger.mamista.net> <20041209160231.GA12103@panix.com> <20041209161229.GA34389@tigger.mamista.net> <20041209163327.GA15086@panix.com> <20041209164907.GJ61075@tigger.mamista.net> Message-ID: <20041209165834.GB34389@tigger.mamista.net> On Thu, Dec 09, 2004 at 04:49:07PM +0000, Toby Corkindale wrote: > On Thu, Dec 09, 2004 at 11:33:27AM -0500, Jesse Sheidlower wrote: > > On Thu, Dec 09, 2004 at 04:12:29PM +0000, Toby Corkindale wrote: > > > On Thu, Dec 09, 2004 at 11:02:32AM -0500, Jesse Sheidlower wrote: > > > > On Thu, Dec 09, 2004 at 03:51:52PM +0000, Toby Corkindale wrote: > [snip] > > > > > A-S-Postgres requires one to pass the Handle => $dbh parameter, > > > > > where $dbh is the open DBI handle. How can I access that? I've > > > > > traced as far as that ->loader will contain the Class::DBI::Loader > > > > > object, which is related, but I don't know how to obtain the DBI > > > > > handle from it.. > > > > > > > > MyApp::MyClass->db_Main() > > > > > > Thanks! > > > Unfortunately.. I had tried something like that, like so: > > > > > > EHS::Diesel->setup($config->dsn, $config->dbuser, $config->dbpass, > > > { AutoCommit => 1, > > > PrintError => 1 > > > }); > > > > Try wrapping the above in a BEGIN block, i.e. > > > > BEGIN { > > EHS::Diesel->setup($config->dsn, $config->dbuser, $config->dbpass, > > { AutoCommit => 1, > > PrintError => 1 }); > > } > > Thanks. I've just tried this, and unfortunately it didn't change the error > message. > > I'm calling this in my base class, not the model classes - I've used the > db_Main() call in them successfully before. > > Should I try using a dummy class, eg. > Handle => EHS::Diesel::Users->db_Main() > instead of EHS::Diesel->db_Main()? It seems like the "wrong thing" to do > though.. Note: Doing this seems to work, although it seems to be the "wrong" way to do it? Thanks all, Toby -- Turning and turning in the widening gyre/The falcon cannot hear the falconer; Things fall apart, the centre cannot hold/Mere anarchy is loosed upon the world (gpg --keyserver www.co.uk.pgp.net --recv-key 897E5FF3) From dhoworth@mrc-lmb.cam.ac.uk Thu Dec 9 17:19:46 2004 From: dhoworth@mrc-lmb.cam.ac.uk (Dave Howorth) Date: Thu, 09 Dec 2004 17:19:46 +0000 Subject: [Maypole] Direct access to DBI handle? In-Reply-To: <20041209165834.GB34389@tigger.mamista.net> References: <20041209155152.GG61075@tigger.mamista.net> <20041209160231.GA12103@panix.com> <20041209161229.GA34389@tigger.mamista.net> <20041209163327.GA15086@panix.com> <20041209164907.GJ61075@tigger.mamista.net> <20041209165834.GB34389@tigger.mamista.net> Message-ID: <41B88932.5010807@mrc-lmb.cam.ac.uk> Toby Corkindale wrote: >>I'm calling this in my base class, not the model classes - I've used the >>db_Main() call in them successfully before. >> >>Should I try using a dummy class, eg. >>Handle => EHS::Diesel::Users->db_Main() >>instead of EHS::Diesel->db_Main()? It seems like the "wrong thing" to do >>though.. > > Note: Doing this seems to work, although it seems to be the "wrong" way to do > it? The DBI handle belongs (indirectly) to CDBI, which your model classes inherit from; your main application class doesn't. Your main model class or any of the subclasses should be OK, AFAIK. You can only access it after the application class setup method has run, because that's what initializes CDBI and sets up the inheritance path you want to use. Cheers, Dave From peterspeltz@yahoo.com Thu Dec 9 18:42:24 2004 From: peterspeltz@yahoo.com (Peter Speltz) Date: Thu, 9 Dec 2004 10:42:24 -0800 (PST) Subject: [Maypole] AsForm again - selects? In-Reply-To: <41B881AA.5070801@mrc-lmb.cam.ac.uk> Message-ID: <20041209184224.3223.qmail@web52101.mail.yahoo.com> --- Dave Howorth wrote: > I'm looking at the addnew form for a table that has a foreign key that > is allowed to be null. AsForm has generated a select box for it, which > is good (modulo the other issues we know about :) But it's populated > the select box with all the existing keys. There doesn't seem to be any > way to say that I want a NULL value for this field in my new record. > > I have SQL like this: > > CREATE TABLE a_table ( > id INT NOT NULL, > fk INT, > FOREIGN KEY (fk) REFERENCES another_table (id) > ) TYPE=InnoDB; > > and code like this: > > ATable->has_a( fk => 'AnotherTable' ); > AnotherTable->might_have(entries => 'ATable', 'fk'); > > Is there something else I should be configuring or do I need to think > about overriding AsForm? > Not sure i understand. Are you saying you want a select box with a NULL option on top so you can select that? Search form does that by unshifting a HTML::Element (option) to the respective select element. See that template. > maypole.perl.org seems to be down, so I couldn't check if > has anything new. > I've been working on AsForm and this was a