Changeset 8023 for lang/perl/App-MadEye

Show
Ignore:
Timestamp:
03/17/08 13:18:20 (8 months ago)
Author:
tokuhirom
Message:

Rule も kwalify できるようにした。

Location:
lang/perl/App-MadEye/trunk/lib/App/MadEye
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/App-MadEye/trunk/lib/App/MadEye/Plugin/Base.pm

    r8011 r8023  
    33use warnings; 
    44use base qw/Class::Component::Plugin/; 
     5use App::MadEye::Util qw/get_schema_from_pod/; 
    56use Kwalify (); 
    6 use Pod::POM (); 
    7 use List::Util qw/first/; 
    8 use YAML (); 
    97 
    108sub new { 
     
    1210    my $self = $class->SUPER::new(@_); 
    1311 
    14     my $parser = Pod::POM->new; 
    15     my $pom = $parser->parse(Class::Inspector->resolved_filename($class)); 
    16     if (my $schema_node = first { $_->title eq 'SCHEMA' } $pom->head1) { 
    17         my $schema_content = $schema_node->content; 
    18         $schema_content =~ s/^    //gm; 
    19         my $schema = YAML::Load($schema_content); 
    20  
     12    if (my $schema = get_schema_from_pod($self)) { 
    2113        Kwalify::validate($schema, $self->config->{config}); 
    2214    } 
  • lang/perl/App-MadEye/trunk/lib/App/MadEye/Rule.pm

    r7563 r8023  
    22use strict; 
    33use warnings; 
     4use App::MadEye::Util qw/get_schema_from_pod/; 
     5use Kwalify (); 
    46 
    57sub new { 
    68    my ($class, $config) = @_; 
    79    $config ||= {}; 
     10    if (my $schema = get_schema_from_pod($class)) { 
     11        Kwalify::validate($schema, $config); 
     12    } 
    813    bless {config => $config}, $class; 
    914} 
  • lang/perl/App-MadEye/trunk/lib/App/MadEye/Util.pm

    r8015 r8023  
    44use base qw/Exporter/; 
    55 
    6 our @EXPORT = qw/timeout log_stopwatch/; 
     6our @EXPORT = qw/timeout log_stopwatch get_schema_from_pod/; 
    77 
    88use Sys::Syslog qw/:DEFAULT/; 
     9use Pod::POM (); 
     10use List::Util qw/first/; 
     11use YAML (); 
    912 
    1013sub timeout($$&) {    ## no critic. 
     
    3740} 
    3841 
     42sub get_schema_from_pod { 
     43    my $target = shift; 
     44    my $proto = ref $target || $target; 
     45 
     46    my $parser = Pod::POM->new; 
     47    my $pom = $parser->parse(Class::Inspector->resolved_filename($proto)); 
     48    if (my $schema_node = first { $_->title eq 'SCHEMA' } $pom->head1) { 
     49        my $schema_content = $schema_node->content; 
     50        $schema_content =~ s/^    //gm; 
     51        my $schema = YAML::Load($schema_content); 
     52        return $schema; 
     53    } else { 
     54        return; # 404 schema not found. 
     55    } 
     56} 
     57 
    39581;