Murat Ünalan > Decision-Table-0.02_02 > Decision::Table::Compact

Download:
Decision-Table-0.02_02.tar.gz

Dependencies

Annotate this POD

Source  

Decision::Table::Compact ^

This table is a Decision::Table with a different constructor. It takes scalars instead of objects. Decision::Table::Condition are constructed with the text attribute filled with the scalar. Same as the actions initialized with c<Decision::Table::Action> objects.

  my $dt = Decision::Table::Compact->new( 
    
      conditions =>
      [
       'drove too fast ?',
       'comsumed alcohol ?',
       'Police is making controls ?',
      ],
      
      actions =>
      [
       'charged admonishment',         # 0
       'drivers license cancellation', # 1
       'nothing happened',             # 2
      ],
      
      # @conditions => @actions
      
      rules =>
      [
      [ 1, 0, 1 ] => [ 0 ],
      [ 1, 1, 1 ] => [ 0, 1 ],
      [ 0, 0, 0 ] => [ 2 ],
      ],
 );

Note: $dt->conditions property (and actions) will handle $objects as normal. Only the constructor is different.

$dt->table

Returns a complete table of the condition status. The format is

 $condition_id => action_result 

where the action result is often true || false.

 {
   '0' => true,
   '1' => false,
   '2' => true
 };

Note that you just need to reverse the hash to know if one of the tests failed.

syntax highlighting: