[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] Splitting run mode


Apologies all ... I'm sorely in need of sleep. I hope this makes sense....

Jonathan,

My main issue was that there were always a few things that needed done before a template was displayed. So I wrote a "display" method that loads a template, associates it with my query (CGI.pm) object, does any other stuff, then returns the displayed template.

So, my run mode is the "process" part, then at the end I make sure all my template variables are in my query object, then
  return $self->display('template_name');

The only time I break from that is when I have something that really is two-step, such as processing a search (check for input errors, see if it's there) and displaying a record. In that case, the displaying of the record isn't really a "run mode", it's just a function. That function would either return the $self->display('template'), or put its results into a query parameter that has its own part of the template. So it's something like this:

sub mode1 {
  my $self = shift;
  return $self->display('template1');
}

sub mode2 {
  my $self = shift;
  # Lots of things happen
  my $record = hash_ref_of_stuff_from_the_record;
  # tidy up your query object with other template variables
  return $self->display_record($record);
}

sub display_record {
  my $self = shift;
  my $record = shift;
  # Format the record how you want it; put results in your query object
  return $self->display('recordtemplate');
}

OR

sub mode2 {
  ...
$self->query->param(-name=>'record', -value=> $self->format($record) );
  return $self->display('template2');
}

sub format {
  my $self=shift;
  my $record = shift;
# build $output as record display. You can use a template, or whatever you want.
  return $output;
}


Hope that is somewhat coherent and helps you a bit...

Jaclyn



On Feb 7, 2005, at 3:43 PM, Jonathan Mangin wrote:


----- Original Message ----- From: "Michael Peters" <suppressed>
To: "Jonathan Mangin" <suppressed>
Cc: <suppressed>
Sent: Monday, February 07, 2005 3:43 PM
Subject: Re: [cgiapp] Splitting run mode


Jonathan Mangin wrote:
The docs talk about having display run modes and process run modes.
Does that mean I can split mode2 below into 2 run modes?  And how
would I call mode3 (show_template_2) with vars from process_mode_1?

sub mode1 {
  show_template_1();
}

sub mode2 {
  process_mode1();
  show_template_2();
}

If I understand correctly, I would:

sub mode1 {
  my $self = shift;
  # load and display some template
  return $tmpl->output();
}

sub mode2 {
  my $self = shift;
  # process data from mode1
  # now show it again
  return $self->mode1();
}

sub mode3 {
  my $self = shift;
  # load and display some other template
  return $tmpl->output();
}

Hope you can understand my question,

If that doesn't answer your question, then I guess I didn't understand it :)

--
Michael Peters
Developer
Plus Three, LP


I believe you understood it, though I can't do what you suggest.

mode1 asks for a uid whose profile I want to edit.
mode2 fetches the profile data and then displays the full record.

Just wondered if I could somehow split the fetch/display into
separate run modes. It's not important and I'm guessing the best
answer is "why?"

Thanks,
Jon




---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
             http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
             http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.