Show
Ignore:
Timestamp:
04/02/08 17:43:57 (5 years ago)
Author:
yappo
Message:

lang/perl/Class-Component: attribute をハンドルする所を別メソッドの class_component_plugin_attribute_detect として外だしして、アプリ側で拡張しやすくした

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Class-Component/trunk/lib/Class/Component/Plugin.pm

    r8646 r8653  
    2323sub init {} 
    2424 
     25sub class_component_plugin_attribute_detect { 
     26    my($self, $attr) = @_; 
     27    return unless my($key, $value) = ($attr =~ /^(.*?)(?:\(\s*(.+?)\s*\))?$/); 
     28    return ($key, $value) unless defined $value; 
     29 
     30    my $pkg    = ref $self; 
     31    # from Attribute::Handlers 
     32    my $evaled = eval "package $pkg; no warnings; local \$SIG{__WARN__} = sub{ die \@_ }; [$value]"; ## no critic 
     33    $@ and croak "$pkg: $value: $@"; 
     34    my $data   = $evaled || [$value]; 
     35    $value     = (@{ $data } > 1) ? $data : $data->[0]; 
     36 
     37    return ($key, $value); 
     38} 
     39 
    2540sub register { 
    2641    my($self, $c) = @_; 
     
    3752    for my $data (@{ $self->__methods_cache }) { 
    3853        for my $attr (@{ $data->{attrs} }) { 
    39             next unless my($key, $value) = ($attr =~ /^(.*?)(?:\(\s*(.+?)\s*\))?$/); 
    40             if (defined $value) { 
    41                 my $pkg    = ref $self; 
    42                 # from Attribute::Handlers 
    43                 my $evaled = eval "package $pkg; no warnings; local \$SIG{__WARN__} = sub{ die \@_ }; [$value]"; ## no critic 
    44                 $@ and croak "$pkg: $value: $@"; 
    45                 my $data   = $evaled || [$value]; 
    46                 $value     = (@{ $data } > 1) ? $data : $data->[0]; 
    47             } 
    48  
     54            next unless my($key, $value) = $self->class_component_plugin_attribute_detect($attr); 
    4955 
    5056            for my $isa_pkg (@{ Class::Component::Implement->isa_list_cache($c) }) {