From: Vitor <vs...@uo...> - 2004-11-19 18:47:51
|
Michael, Thank you very much. This is exactly what i was looking for. Regards, VX -----Mensagem original----- De: mas...@li... [mailto:mas...@li...]Em nome de michael bayer Enviada em: sexta-feira, 19 de novembro de 2004 14:26 Para: Mason Users List Assunto: Re: RES: [Mason] $m->fetch_comp with args On Nov 18, 2004, at 6:32 PM, Alex Robinson wrote: > > Indeed you could remove initialise altogether and do this in the > shared block > > <%shared> > my $id = $m->caller_args(0)->{id}; > </%shared> i think the original poster wants to avoid calling any method at all with the ID, i.e. he wants to send it within the fetch_comp() call itself when the owning component is retrieved, and then never reference it again on the outside. which indicates a misunderstanding of the more or less stateless nature of a component. %shared gives you request-scoped state but wouldnt necessarily work, since you cant use widget.mc with any other ID for the life of the request unless you call some method that specifically changes the value of $id, which, he doesnt want to do. its also a shaky reliance on the current process model of mason, i.e. not multithreaded as of yet (apache 2.0 ? perl 6 ? ) personally, being a big fan of decades-old procedural programming standards, I would just pass the ID to each method. but since he doesnt want to do that, id say he skips fetch_comp() altogether and implements a stateful service object either within widget.mc or in a generic library: <%init> my $widget = $m->comp('widget.mc:get_service', id=>$my_id); $widget->call_method('javascript'); $widget->call_method('tr_id'); </%init> widget.mc: <%method get_service> <%args> $id </%args> <%init> { package WidgetService; sub new { my ($class, $owner, $id) =@_; my $self = {id=>$id, comp=>$owner}; bless $self, $class; return $self; } sub call_method { my ($self, $method) = @_; $self->{comp}->call_method($method, id=>$self->{id}); } } return new WidgetService($m->current_comp->owner(), $id) </%init> </%method> you could genericize this approach to take an arbitrary argument list as well and just use it throughout an application wherever you want "stateful" component calling behavior. ------------------------------------------------------- This SF.Net email is sponsored by: InterSystems CACHE FREE OODBMS DOWNLOAD - A multidimensional database that combines robust object and relational technologies, making it a perfect match for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8 _______________________________________________ Mason-users mailing list Mas...@li... https://lists.sourceforge.net/lists/listinfo/mason-users |