On Thursday 07 March 2013 11:00:37 Ken Peng wrote:
> Hello,
> 
> How do you setup config file in modperl web development?
> I currently use the style like a package:
> ...
> I don't know if this is a good way. Do you have suggestions?

I am not an expert here, but I think it's acceptable way. YAML is another 
alternative. Here's my example for model call validation config:
---
params:
    ip:
        regex: ^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$
        default: defaults.ip
    cookie:
        max-size: 40
        min-size: 4
result:
    OK:
        redirect: /appIndex
        set-cookie:
            auth:
              value: TT response.auth
              secure: 1
              expires: +1d
              domain: .fr.iii.la
call_method: model
allowed_source:
    - submit # ajax, submit, template
    - ajax

This config translates into Perl structure with hashes and arrays (Dumper 
output):
$VAR1 = {                                                                       
                                                                                
                                                                                
                               
  'params' => {                                                                 
                                                                                
                                                                                
                               
    'ip' => {                                                                   
                                                                                
                                                                                
                               
      'regex' => '^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$',                 
                                                                                
                                                                                
                               
      'default' => 'defaults.ip'                                                
                                                                                
                                                                                
                               
    },                                                                          
                                                                                
                                                                                
                               
    'cookie' => {                                                               
                                                                                
                                                                                
                               
      'min-size' => 4,                                                          
                                                                                
                                                                                
                               
      'max-size' => 40                                                          
                                                                                
                                                                                
                               
    }                                                                           
                                                                                
                                                                                
                               
  },                                                                            
                                                                                
                                                                                
                               
  'call_method' => 'model',                                                     
                                                                                
                                                                                
                               
  'allowed_source' => [                                                         
                                                                                
                                                                                
                               
    'submit',                                                                   
                                                                                
                                                                                
                               
    'ajax'                                                                      
                                                                                
                                                                                
                               
  ],                                                                            
                                                                                
                                                                                
                               
  'result' => {                                                                 
                                                                                
                                                                                
                               
    'OK' => {                                                                   
                                                                                
                                                                                
                               
      'set-cookie' => {                                                         
                                                                                
                                                                                
                               
        'auth' => {                                                             
                                                                                
                                                                                
                               
          'domain' => '.fr.iii.la',                                             
                                                                                
                                                                                
                               
          'value' => 'TT response.auth',                                        
                                                                                
                                                                                
                               
          'secure' => 1,                                                        
                                                                                
                                                                                
                               
          'expires' => '+1d'                                                    
                                                                                
                                                                                
                               
        }                                                                       
                                                                                
                                                                                
                               
      },                                                                        
                                                                                
                                                                                
                               
      'redirect' => '/appIndex'                                                 
                                                                                
                                                                                
                               
    }                                                                           
                                                                                
                                                                                
                               
  }                                                                             
                                                                                
                                                                                
                               
};                                                                              
                                                                                
                                                                                
                               
--
Anton Petrusevich

Reply via email to