annotate lib/IMPL/Class/ClassInfo.pm @ 427:09e0086a82a7 ref20150831 tip

Merge
author cin
date Tue, 15 May 2018 00:51:33 +0300
parents 60c2892a577c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
423
60c2892a577c working on base class system
cin
parents:
diff changeset
1 package IMPL::Class::ClassInfo;
60c2892a577c working on base class system
cin
parents:
diff changeset
2 use strict;
60c2892a577c working on base class system
cin
parents:
diff changeset
3
60c2892a577c working on base class system
cin
parents:
diff changeset
4 use Sub::Util qw(subname);
60c2892a577c working on base class system
cin
parents:
diff changeset
5 use mro;
60c2892a577c working on base class system
cin
parents:
diff changeset
6
60c2892a577c working on base class system
cin
parents:
diff changeset
7 my %props;
60c2892a577c working on base class system
cin
parents:
diff changeset
8
60c2892a577c working on base class system
cin
parents:
diff changeset
9 sub new {
60c2892a577c working on base class system
cin
parents:
diff changeset
10 my ( $self, $class ) = @_;
60c2892a577c working on base class system
cin
parents:
diff changeset
11
60c2892a577c working on base class system
cin
parents:
diff changeset
12 return bless \$class, $self;
60c2892a577c working on base class system
cin
parents:
diff changeset
13 }
60c2892a577c working on base class system
cin
parents:
diff changeset
14
60c2892a577c working on base class system
cin
parents:
diff changeset
15 sub className {
60c2892a577c working on base class system
cin
parents:
diff changeset
16 ${ $_[0] };
60c2892a577c working on base class system
cin
parents:
diff changeset
17 }
60c2892a577c working on base class system
cin
parents:
diff changeset
18
60c2892a577c working on base class system
cin
parents:
diff changeset
19 sub linearISA {
60c2892a577c working on base class system
cin
parents:
diff changeset
20 return mro::get_linear_isa( ${ $_[0] } );
60c2892a577c working on base class system
cin
parents:
diff changeset
21 }
60c2892a577c working on base class system
cin
parents:
diff changeset
22
60c2892a577c working on base class system
cin
parents:
diff changeset
23 sub members {
60c2892a577c working on base class system
cin
parents:
diff changeset
24
60c2892a577c working on base class system
cin
parents:
diff changeset
25 }
60c2892a577c working on base class system
cin
parents:
diff changeset
26
60c2892a577c working on base class system
cin
parents:
diff changeset
27 sub methods {
60c2892a577c working on base class system
cin
parents:
diff changeset
28 my ( $this, %opts ) = @_;
60c2892a577c working on base class system
cin
parents:
diff changeset
29
60c2892a577c working on base class system
cin
parents:
diff changeset
30 my %hide;
60c2892a577c working on base class system
cin
parents:
diff changeset
31
60c2892a577c working on base class system
cin
parents:
diff changeset
32 if ( !$opts{hidden} ) {
60c2892a577c working on base class system
cin
parents:
diff changeset
33 %hide =
60c2892a577c working on base class system
cin
parents:
diff changeset
34 map ( ( $_, 1 ), map @{$_}{qw(getter setter)},
60c2892a577c working on base class system
cin
parents:
diff changeset
35 $this->properties(%opts) );
60c2892a577c working on base class system
cin
parents:
diff changeset
36 }
60c2892a577c working on base class system
cin
parents:
diff changeset
37
60c2892a577c working on base class system
cin
parents:
diff changeset
38 if ( !$opts{inherited} ) {
60c2892a577c working on base class system
cin
parents:
diff changeset
39 no strict 'refs';
60c2892a577c working on base class system
cin
parents:
diff changeset
40 my $class = $this->className();
60c2892a577c working on base class system
cin
parents:
diff changeset
41
60c2892a577c working on base class system
cin
parents:
diff changeset
42 my @members;
60c2892a577c working on base class system
cin
parents:
diff changeset
43
60c2892a577c working on base class system
cin
parents:
diff changeset
44 while ( my ( $k, $v ) = each %{"${class}::"} ) {
60c2892a577c working on base class system
cin
parents:
diff changeset
45 my $fn = *{$v}{CODE};
60c2892a577c working on base class system
cin
parents:
diff changeset
46 next unless $fn;
60c2892a577c working on base class system
cin
parents:
diff changeset
47
60c2892a577c working on base class system
cin
parents:
diff changeset
48 my ( $fqname, $pkg, $name ) =
60c2892a577c working on base class system
cin
parents:
diff changeset
49 ( subname($fn) =~ m/^((.+)::(.+?))$/ );
60c2892a577c working on base class system
cin
parents:
diff changeset
50
60c2892a577c working on base class system
cin
parents:
diff changeset
51 push @members, $fqname if $pkg eq $class and not $hide{$name};
60c2892a577c working on base class system
cin
parents:
diff changeset
52 }
60c2892a577c working on base class system
cin
parents:
diff changeset
53
60c2892a577c working on base class system
cin
parents:
diff changeset
54 return @members;
60c2892a577c working on base class system
cin
parents:
diff changeset
55 }
60c2892a577c working on base class system
cin
parents:
diff changeset
56 else {
60c2892a577c working on base class system
cin
parents:
diff changeset
57
60c2892a577c working on base class system
cin
parents:
diff changeset
58 my @isa =
60c2892a577c working on base class system
cin
parents:
diff changeset
59 reverse( $opts{inherited} ? $this->linearISA() : $this->className() );
60c2892a577c working on base class system
cin
parents:
diff changeset
60
60c2892a577c working on base class system
cin
parents:
diff changeset
61 my %methods = map { $_->memberName(), $_ }
60c2892a577c working on base class system
cin
parents:
diff changeset
62 grep not( $hide{ $_->memberName() } ),
60c2892a577c working on base class system
cin
parents:
diff changeset
63 map { IMPL::Class::ClassInfo->new($_)->methods( inherited => 0 ) } @isa;
60c2892a577c working on base class system
cin
parents:
diff changeset
64
60c2892a577c working on base class system
cin
parents:
diff changeset
65 return values %methods;
60c2892a577c working on base class system
cin
parents:
diff changeset
66 }
60c2892a577c working on base class system
cin
parents:
diff changeset
67 }
60c2892a577c working on base class system
cin
parents:
diff changeset
68
60c2892a577c working on base class system
cin
parents:
diff changeset
69 sub properties {
60c2892a577c working on base class system
cin
parents:
diff changeset
70
60c2892a577c working on base class system
cin
parents:
diff changeset
71 }
60c2892a577c working on base class system
cin
parents:
diff changeset
72
60c2892a577c working on base class system
cin
parents:
diff changeset
73 1;