Putting aside it was more Mason 2.x question, I think <%shared> block introduced all sorts of problems, which made this not so trivial. I think one of them was accessing GET/POST parameters that are usually required to fetch some data.
At least I remember having lots of problems using method you described, can't recall how it ended but it wasn't as easy as you say unfortunately :/ On 16 July 2012 00:13, Nic Wolff <n...@angel.net> wrote: > FYI, in Mason 1, this can be done with a <%method> in the base component, > which can be called from autohanders above it. The method can see variables > defined in <%shared> sections, like this: > > ----- index.m ----- > <%method page_title><% $title %></%method> > <%shared> > my $title = 'Home page'; # or get page title from database or > somewhere > </%shared> > > ----- autohandler ----- > <%method page_title>Default page title</%method> > <title><% $m->scomp('SELF:page_title') %></title> > > > On 15 Jul 2012, at 4:53 PM, Kamil Niechajewicz wrote: > > Hello, > > > > In our upcoming project we've decided to give Mason 2.0 a go - we'll be > > completly rewritting pretty big web portal with over 10 years of history > > which had previously been written in old Mason/mod_perl. > > > > I checked documentation and I really like the direction of 2.0 version, > but > > considering our needs I have one important question: biggest problem with > > old Mason was using infromation from top page component (the one which > was > > accessed from browser, like index.m) in upper "wrappers" that decided on > > things like meta data, HTML header and base layout. > > > > To give an example (pardon pseudo code but I just want to make it clear > as > > quick as possible) in Mason 1.x: > > > > ---------------------------------------- > > */index.m* > > <%init> > > my $article = Article::get_article(...); > > my $title = "Article: " . $article->{title}; > > </%init> > > <h1><% $article->{title}</h1> > > <% $article->{body} %> > > > > > > ---------------------------------------- > > */autohandler* > > <%init> > > my $title = "Default title"; > > </%init> > > <html> > > <head> > > <title><% $title %></title> // $title should be either default or > > // overriden by base components like > index.m > > </head> > > <body> > > <% $m->call_next %> > > > > In Mason 1.x it was quite hard (if not impossible) to get that $title > from > > base component (index.m) up to autohandler which required that > information > > to set up <title></title> of web page. <%attr> block worked a bit like > > this, but it was static and could not be changed depending on some logic > > (like setting title of fetched article etc.) > > > > My question is - how can this be achieved in Mason 2.0 - I suppose that > > having components as classes help here a lot? I couldn't find the exact > > example of such "passing" of attributes. If Base.mc is some kind of > > autohandler (if I'm correct) then it will become a parent of index.mc > > component, > > right? If so, can I define > > > > */Base.mc* > > <%class> > > has 'title' > > </%class> > > <html> > > <head> > > <title><% $self->title %></title> > > </head> > > <body> > > <% inner() %> > > > > and then in index.mc do this: > > > > /index.mc > > <%init> > > $self->title('New title'); > > </%init> > > > > And it will cause the Base.mc component class to display the title set by > > its child? Or should we approach this more in a OO manner defining some > > virtual method in Base.mc like GetPageTitle() and override it in other > > components with a method returning a specific title? > > > > I'd be really grateful for some short examples of good practices of doing > > this in Mason 2.0 :) > > > > Thanks, > > > > KN > > > ------------------------------------------------------------------------------ > > Live Security Virtual Conference > > Exclusive live event will cover all the ways today's security and > > threat landscape has changed and how IT managers can respond. Discussions > > will include endpoint security, mobile security and the latest in malware > > threats. > http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________ > > Mason-users mailing list > > Mason-users@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/mason-users > > -- Kamil Niechajewicz Kierownik ds. Rozwoju *Biuro serwisu Bankier.pl* www.bankier.pl ul. Mokotowska 1, 00-640 Warszawa kom. +48 601 951 495, fax +48 22 378 99 06 e-mail: k.niechajew...@bankier.pl <k.niechajew...@firma.bankier.pl> Grupa Allegro Sp. z o.o. z siedzibą w Poznaniu, 60-324 Poznań, przy ul. Marcelińskiej 90, wpisana do rejestru przedsiębiorców prowadzonego przez Sąd Rejonowy Poznań - Nowe Miasto i Wilda w Poznaniu, VIII Wydział Gospodarczy Krajowego Rejestru Sądowego pod numerem KRS 0000268796, o kapitale zakładowym w wysokości 33.474.500 zł, posiadająca numer identyfikacji podatkowej NIP 527 25 25 995, Regon: 140762508.
<<image003.jpg>>
------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________ Mason-users mailing list Mason-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mason-users