Tim Colson wrote:
> 
> 
> What I'd like is the controller to do more than just dispatch to an action
> and expect the action will return output to the browser. I'd like it to both
> dispatch to an Action/Run-Mode, and then accept the return of that Action
> and chain to additional Actions/RunModes or to OutputModes as specified by
> my config.

Hello Tim, Jesse, and friends. 

I work in the same problem space-- lots of forms to
add/update/delete/view entities from a
a database. The entities keep changing, but the problemspace doesn't
change much. :) I've been happy with CGI::App in it's currents states to
handle my needs. I admit I may have a blind-spot about a way this could
be improved that I'm not seeing. :) However, I'd like to prevent an
example of some "real world" code of how this works for me. This is a
fairly direct copy/paste with some enhanced comments. This a run mode to
process a entity that has just been updated in a form:

sub admin_user_insert_process {
        my $self = shift;
  
    # validate form. This is a non-run mode subroutine used for both
        # updating and inserting the item. It uses Data::FormValidator under
the covers
        my ($valid,$missing,$invalid,$msgs) = user_validate(style=>'insert');

   # if there are errors, return the errors
   # Note that I'm calling another run-mode here, with some extra info
   # to display error tokens. 
        if (@$missing or @$invalid) {
      require HTML::FillInForm;
      my $fif = new HTML::FillInForm;
      return $fif->fill(
                        scalarref => \$self->admin_user_insert_form(
                        error_marks( $missing, $invalid,$msgs)
                        ),
         fobject => $self->query),
   }

   else {

      # insert into the database
      require DBIx::Abstract;
      my $db = DBIx::Abstract->connect($DBH);

      $valid->{user_state} = 'active';
      $valid->{registration_ip} = $ENV{REMOTE_ADDR};
      $db->insert('users',$valid);
      
      # Here I dynamically return them to a different run mode
          # Either a "main page" or the same form to make further updates. 
         # failsafe is JavaScript is missing. -mls
      $FORM{return_rm} ||= 'admin_index';
      return eval( '$self->'.$FORM{return_rm}.q{(undef,msg=>'User Added
Successfully')} );
   }
}

#############

What do you think? Is this "use" or "abuse" of the CGI::App framework? 

  -mark 

 . . . . . . . . . . . . . . . . . . . . . . . . . .
   Mark Stosberg              Principal Developer  
   [EMAIL PROTECTED]       Summersault, LLC     
   v: 765-939-9301 ext 223    website development  
 . . . . . http://www.summersault.com/ . . . . . . .

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to