Changeset 25412 for lang/perl/Shika

Show
Ignore:
Timestamp:
11/30/08 17:19:39 (4 years ago)
Author:
yappo
Message:

add subtype function

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

Legend:

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

    r25393 r25412  
    22use strict; 
    33use warnings; 
     4 
     5sub import { 
     6    my $class  = shift; 
     7    my $caller = caller(0); 
     8 
     9    no strict 'refs'; 
     10    *{"$caller\::subtype"} = \&_subtype; 
     11} 
     12 
     13my $SUBTYPE = +{}; 
     14sub _subtype { 
     15    my($name, $code) = @_; 
     16    $SUBTYPE->{$name} = $code; 
     17} 
    418 
    519sub check_valid { 
     
    2438        } 
    2539        return; 
     40    } 
     41    if (exists $SUBTYPE->{$isa}) { 
     42        return $SUBTYPE->{$isa}->(@_); 
    2643    } 
    2744    defined $_[0] && ref($_[0]) eq $isa;