Changeset 21030

Show
Ignore:
Timestamp:
10/09/08 11:44:08 (6 years ago)
Author:
tokuhirom
Message:

use YAML::Syck if can use

Location:
lang/perl/Archer/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Archer/trunk/examples/config.yaml

    r3671 r21030  
    22  work_dir: /tmp/working_archer/ 
    33  dest_dir: /path/to/dest/ 
     4  assets_path: /tmp/ 
    45 
    56tasks: 
  • lang/perl/Archer/trunk/lib/Archer.pm

    r21029 r21030  
    167167    my ( $self, $level ) = @_; 
    168168 
    169     $levels{ $level } 
    170         >= $levels{ $self->{ config }->{ global }->{ log }->{ level } }; 
     169    my $setting_level = $self->{config}->{global}->{log}->{level} || 'debug'; 
     170    $levels{ $level } >= $levels{ $setting_level }; 
    171171} 
    172172 
  • lang/perl/Archer/trunk/lib/Archer/ConfigLoader.pm

    r21029 r21030  
    22use strict; 
    33use warnings; 
    4 use YAML; 
    54use Storable; 
    65use Carp; 
     
    98use FindBin; 
    109 
     10my $yaml_class; 
     11if (eval "require YAML::Syck; 1;") { 
     12    $yaml_class = "YAML::Syck"; 
     13} else { 
     14    require YAML; 
     15    $yaml_class = "YAML"; 
     16} 
     17 
    1118sub new { bless {}, shift } 
    1219 
    1320sub load { 
    1421    my ( $self, $stuff, $context ) = @_; 
     22 
     23    $context->log('debug' => "yaml class: $yaml_class"); 
    1524 
    1625    # load 
     
    1928        || ( -e $stuff && -r _ ) ) 
    2029    { 
    21         $config = YAML::LoadFile($stuff); 
     30        $config = $yaml_class->can('LoadFile')->($stuff); 
    2231        $context->{config_path} = $stuff if $context; 
    2332    } 
    2433    elsif ( ref($stuff) && ref($stuff) eq 'SCALAR' ) { 
    25         $config = YAML::Load( ${$stuff} ); 
     34        $config = $yaml_class->can('Load')->( ${$stuff} ); 
    2635    } 
    2736    elsif ( ref($stuff) && ref($stuff) eq 'HASH' ) { 
     
    3847    # verify 
    3948    my $schema_file = file( $config->{global}->{assets_path}, 'kwalify', 'schema.yaml' ); 
    40     my $res = validate( YAML::LoadFile($schema_file), $config ); 
     49    my $res = validate( $yaml_class->can('LoadFile')->($schema_file), $config ); 
    4150    $context->log( error => $res ) unless $res == 1; 
    4251