comparison Lib/IMPL/Class/Meta.pm @ 369:7c784144d2f1

Implemented object metadata class, cleanup
author cin
date Mon, 09 Dec 2013 17:35:34 +0400
parents c6d0f889ef87
children
comparison
equal deleted inserted replaced
368:010ceafd0c5a 369:7c784144d2f1
25 sub GetMeta { 25 sub GetMeta {
26 my ($class,$meta_class,$predicate,$deep) = @_; 26 my ($class,$meta_class,$predicate,$deep) = @_;
27 $class = ref $class if ref $class; 27 $class = ref $class if ref $class;
28 no strict 'refs'; 28 no strict 'refs';
29 my @result; 29 my @result;
30
31 if ($deep) {
32 @result = map { $_->can('GetMeta') ? $_->GetMeta($meta_class,$predicate,$deep) : () } @{$class.'::ISA'};
33 }
34 30
35 if ($predicate) { 31 if ($predicate) {
36 push @result,grep( &$predicate($_), map( @{$class_meta{$class}{$_}}, grep( $_->isa($meta_class), keys %{$class_meta{$class} || {}} ) ) ); 32 push @result,grep( &$predicate($_), map( @{$class_meta{$class}{$_}}, grep( $_->isa($meta_class), keys %{$class_meta{$class} || {}} ) ) );
37 } else { 33 } else {
38 push @result, map( @{$class_meta{$class}{$_} || []}, grep( $_->isa($meta_class), keys %{$class_meta{$class} || {}} ) ); 34 push @result, map( @{$class_meta{$class}{$_} || []}, grep( $_->isa($meta_class), keys %{$class_meta{$class} || {}} ) );
39 } 35 }
36
37 if ($deep) {
38 push @result, map { $_->can('GetMeta') ? $_->GetMeta($meta_class,$predicate,$deep) : () } @{$class.'::ISA'};
39 }
40
40 wantarray ? @result : \@result; 41 wantarray ? @result : \@result;
41 } 42 }
42 43
43 sub get_meta { 44 sub get_meta {
44 goto &GetMeta; 45 goto &GetMeta;