Changeset 2910

Show
Ignore:
Timestamp:
05/10/05 02:02:04 (4 years ago)
Author:
Stevan
svk:copy_cache_prev:
4437
Message:

Perl::MetaClass? - adding visibility property to MetaProperty?; finishing the clsMethod and clsAssoc methods in MetaClass?

Location:
ext/Perl-MetaClass/lib/Perl
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • ext/Perl-MetaClass/lib/Perl/MetaClass.pm

    r2909 r2910  
    9292} 
    9393 
    94 sub clsMethods(Str $inv: Hash ?%methods) returns Hash { 
     94sub clsMethods(Str $inv: Array *@methods) returns Hash { 
    9595    my %self := get_instance($inv, "Perl::MetaClass"); 
    96     %self<methods> = \%methods if %methods.defined; 
     96    if @methods { 
     97        for @methods -> $key, $value { 
     98            ($value.instance_isa('Perl::MetaMethod')) 
     99                || die "Method values must be a Perl::MetaMethod instance (got: '$value')";              
     100            my %methods = %self<methods>; 
     101            %methods{$key} = $value; 
     102            %self<methods> = \%methods;                  
     103        } 
     104    } 
    97105    return %self<methods>; 
    98106} 
    99107 
    100 sub clsAssocs(Str $inv: Hash ?%assocs) returns Hash { 
     108sub clsAssocs(Str $inv: Array *@assocs) returns Hash { 
    101109    my %self := get_instance($inv, "Perl::MetaClass"); 
    102     %self<assocs> = \%assocs if %assocs.defined; 
     110    if @assocs { 
     111        for @assocs -> $key, $value { 
     112            ($value.instance_isa('Perl::MetaAssoc')) 
     113                || die "Assoc values must be a Perl::MetaAssoc instance (got: '$value')";              
     114            my %assocs = %self<assocs>; 
     115            %assocs{$key} = $value; 
     116            %self<assocs> = \%assocs;                  
     117        } 
     118    } 
    103119    return %self<assocs>; 
    104120} 
  • ext/Perl-MetaClass/lib/Perl/MetaProperty.pm

    r2903 r2910  
    55use Hack::Instances;  
    66 
    7 sub Perl::MetaProperty::new(Str $type, Any +$default) returns Str is export { 
     7sub Perl::MetaProperty::new(Str $type, Any +$default, Str +$visibility) returns Str is export { 
    88    my $id = make_instance("Perl::MetaProperty", {  
    9         'type'    => $type, 
    10         'default' => undef 
     9        'type'       => $type, 
     10        'default'    => undef, 
     11        'visibility' => undef, 
    1112    }); 
    12     $id.propDefault($default) if $default.defined; 
     13    $id.propDefault($default)       if $default.defined; 
     14    $id.propVisibility($visibility) if $visibility.defined;     
    1315    return $id; 
    1416} 
     
    4850} 
    4951 
     52sub propVisibility(Str $inv: Str ?$visibility) returns Str { 
     53    my %self := get_instance($inv, "Perl::MetaProperty"); 
     54    if $visibility.defined { 
     55        ($visibility ~~ rx:perl5:i/(private|public)/) 
     56            || die "Visibility must be either 'Private' of 'Public' (got: '$visibility')"; 
     57        %self<visibility> = $visibility; 
     58    } 
     59    return %self<visibility>; 
     60} 
     61 
    5062=pod 
    5163 
     
    7082=item B<propDefault($inv: ?$default)> 
    7183 
     84=item B<propVisibility($inv: ?$visibility)> 
     85 
    7286=back 
    7387