Changeset 1117

Show
Ignore:
Timestamp:
11/05/07 07:07:34 (6 years ago)
Author:
tokuhirom
Message:

lang/perl/mobirc: added config schema validate feature.

Location:
lang/perl/mobirc/trunk/mobirc/lib
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/mobirc/trunk/mobirc/lib/Mobirc.pm

    r1110 r1117  
    1313 
    1414our $VERSION = 0.02; 
     15 
     16our $HasKwalify; 
     17eval { 
     18    require Kwalify; 
     19    $HasKwalify++; 
     20}; 
    1521 
    1622my $context; 
     
    3642        DEBUG "LOAD PLUGIN: $plugin->{module}"; 
    3743        $plugin->{module}->use or die $@; 
     44        if ( $HasKwalify && $plugin->{module}->can('config_schema') ) { 
     45            my $res = Kwalify::validate( $plugin->{module}->config_schema, $plugin->{config} ); 
     46            unless ( $res == 1 ) { 
     47                die "config.yaml validation error : $plugin->{module}, $res"; 
     48            } 
     49        } 
    3850        $plugin->{module}->register( $self, $plugin->{config} ); 
    3951    } 
  • lang/perl/mobirc/trunk/mobirc/lib/Mobirc/Plugin/Component/XMPP.pm

    r1113 r1117  
    1616use Mobirc::Util; 
    1717 
     18sub config_schema { 
     19    { 
     20        type    => 'map', 
     21        mapping => { 
     22            jid => { 
     23                type     => 'str', 
     24                required => 1, 
     25            }, 
     26            password => { 
     27                type     => 'str', 
     28                required => 1, 
     29            }, 
     30            hostname        => { type => 'str', }, 
     31            channel         => { type => 'str', }, 
     32            alias           => { type => 'str', }, 
     33            connection_type => { type => 'int', }, 
     34        } 
     35    } 
     36} 
     37 
    1838our $PLUGIN_COUNT = 0; 
    19 our $XMPP_SESSION_NAME; # XXX for debug 
    2039sub register { 
    2140    my ($class, $global_context, $conf) = @_; 
     
    4059    $conf->{channel} ||= U 'xmpp[%s]'; 
    4160    $conf->{alias} ||= "XMPP$PLUGIN_COUNT"; 
    42     $XMPP_SESSION_NAME = $conf->{alias}; 
    4361    $conf->{connection_type} ||= POE::Component::Jabber::ProtocolFactory::XMPP; 
    4462}