Changeset 25208 for lang/perl/Shika

Show
Ignore:
Timestamp:
11/28/08 14:41:45 (6 years ago)
Author:
tokuhirom
Message:

added auto deref feature in copy_functions

Location:
lang/perl/Shika/trunk
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Shika/trunk/lib/Shika/Util.pm

    r25194 r25208  
    1717sub copy_functions { 
    1818    my ($src, $dst, $alias) = @_; 
     19    $src = ref $src if ref $src; 
     20    $dst = ref $dst if ref $dst; 
    1921 
     22    print "[debug] copy functions $src to $dst\n" if $ENV{DEBUG}; 
    2023    no strict 'refs'; 
    2124    for my $method (@{ Shika::Util::get_functions($src) }) { 
    2225        next if $method eq 'has' || $method eq 'requires' || $method eq 'meta' || $method eq 'with'; 
    2326        my $dstmethod = $alias->{$method} ? $alias->{$method} : $method; 
    24         next if $dst->can($dstmethod); 
     27        print "[debug]   copying method $method\n" if $ENV{DEBUG}; 
     28        if ($dst->can($dstmethod)) { 
     29            print "[debug]   $dst already have $dstmethod. skip\n" if $ENV{DEBUG}; 
     30            next; 
     31        } 
    2532        *{"${dst}::${dstmethod}"} = *{"${src}::${method}"}; 
    2633    } 
     
    3037    my $klass = shift; 
    3138    eval "require $klass"; ## no critic ### too bad 
     39    print "[debug] cannot load class $@" if $ENV{DEBUG} && $@; 
    3240} 
    3341