Chapter 2.7: Triggers

After acting on component, we may execute another action on a different component immediately, just like running trigger in database.

To use trigger, follow the two steps.

Step 1, Define a New Attribute, nextpages in Model.pm
__PACKAGE__->setup_accessors(
  nextpages => {
    action => [ PAGE, PAGE, ... ],
    action => [ PAGE, PAGE, ... ],
    ...
  },

  insert_pars => [...],
  ...
}

Where action is the class method that would trigger other models;  PAGE is a hash ref defined in call_once and call_nextpage in Section 2.1:

{
  model  => STRING,
  action => STRING, 
  relate_item => {this_field=>other_field, this_field=>other_field, ...},
  manual => {field=>value, field=>value, ...}
}

As you could see, one action could trigger multiple models.

 

Step 2, Return process_after

The inherited RESTful verbs have always triggers enabled, as soon as a verb is defined in nextpages.  To have trigger for your own class method, return the method process_after:

return $self->process_after(action, extra);

in replace of

return;

where action is a method name, usually the current method. process_after will simply look at nextpages, and run call_once or call_nextpage accordingly.

After a successful run, relevant data fields will be collected into $self->{LISTS} and $self->{OTHER}.

A proper use of trigger could minimize redundant codes, keep better programming logic, and take advantages of built-in pagination and row-level-security.