Changeset 14692

Show
Ignore:
Timestamp:
06/27/08 14:44:08 (5 years ago)
Author:
yappo
Message:

できた

Location:
dan/perl/Object-with/branches/yappo
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • dan/perl/Object-with/branches/yappo/lib/Object/with.pm

    r14553 r14692  
    2727 
    2828    my @ret = $code->(@_); 
    29     # %TMP_METHOD_CACHE を片付ける 
     29 
     30    while (my($name, $code) = each %TMP_METHOD_CACHE) { 
     31        no strict 'refs'; 
     32        no warnings 'redefine'; 
     33        *{$name} = $code if $code && ref $code; 
     34        delete $TMP_METHOD_CACHE{$name}; 
     35    } 
    3036 
    3137    @ret; 
     
    3945    my $class   = ref($TMP_OBJ) || $TMP_OBJ; 
    4046 
    41     warn "$name ( $class -> $method )"; 
    42  
    4347    no strict 'refs'; 
    4448    no warnings 'redefine'; 
    4549 
    46     $TMP_METHOD_CACHE{$name} = \&{$name}; 
     50    $TMP_METHOD_CACHE{$name} = defined &{$name} ? \&{$name} : undef unless exists $TMP_METHOD_CACHE{$name}; 
    4751    *{$name}                 = \&{"$class\::$method"}; 
    48     use Data::Dumper; 
    4952} 
    5053 
  • dan/perl/Object-with/branches/yappo/test.pl

    r14553 r14692  
    33sub new { bless {} } 
    44sub hello { warn "hello" } 
     5sub hello2 { warn "hello2" } 
    56 
    67package main; 
     
    1112use Object::with; 
    1213 
     14 
    1315my $o = MyObj->new; 
    1416 
    1517with $o => sub { 
    1618    hello(); 
     19    hello2(); 
     20    hello(); 
    1721}; 
     22hello2(); 
    1823 
     24sub hello2 { die 'end' } 
     25exit; 
     26 
  • dan/perl/Object-with/branches/yappo/with.xs

    r14553 r14692  
    99 
    1010OP * with_entersub(pTHX) { 
    11   dSP; 
    12   SV *sv = *sp; 
     11  dVAR; dSP; 
     12  SV * const name = *(PL_stack_base + TOPMARK + 1); 
    1313 
    14   if (SvTYPE(sv) == SVt_PVGV) { 
    15     /* 
     14  if (SvTYPE(name) == SVt_PVGV) { 
    1615    ENTER; 
    1716    SAVETMPS; 
    1817    PUSHMARK(SP); 
    19     XPUSHs(sv); 
     18    XPUSHs(name); 
    2019    PUTBACK; 
    21     */ 
    2220    call_pv("Object::with::_entersub", G_DISCARD); 
    23     /* 
    2421    FREETMPS; 
    2522    LEAVE; 
    26     */ 
     23     
    2724  } 
    28  
    2925  return PL_ppaddr[PL_op->op_type](aTHX); 
    3026}