/[Frey]/trunk/lib/Frey/PPI.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/PPI.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 486 by dpavlin, Wed Nov 19 15:28:23 2008 UTC revision 487 by dpavlin, Mon Nov 24 17:09:00 2008 UTC
# Line 19  has 'doc' => ( Line 19  has 'doc' => (
19          lazy => 1,          lazy => 1,
20          default => sub {          default => sub {
21                  my ( $self ) = @_;                  my ( $self ) = @_;
22                  warn "# doc from ", $self->class if $self->debug;                  my $path = $self->class;
23                  my $doc = PPI::Document->new( $self->class_path( $self->class ) );                  $path = $self->class_path( $path ) unless $path =~ m{/};
24                    warn "# doc from ", $self->class, " at ", $path if $self->debug;
25                    my $doc = PPI::Document->new( $path );
26                  $doc->prune('PPI::Token::Whitespace');                  $doc->prune('PPI::Token::Whitespace');
27                  return $doc;                  return $doc;
28          },          },
# Line 43  sub attribute_order { Line 45  sub attribute_order {
45          my @attribute_order;          my @attribute_order;
46          $self->find(sub {          $self->find(sub {
47                  my ($doc,$el) = @_;                  my ($doc,$el) = @_;
48                  return unless ( $el->isa('PPI::Statement') && $el->{children}->[0]->isa('PPI::Token::Word') && $el->{children}->[0]->literal eq 'has' );                  return unless
49                            $el->isa('PPI::Statement') &&
50                            $el->{children}->[0]->isa('PPI::Token::Word') &&
51                            $el->{children}->[0]->literal eq 'has';
52    
53                  warn "## has ",$el->{children}->[1]->literal if $self->debug;                  warn "## has ",$el->{children}->[1]->literal if $self->debug;
54                  push @attribute_order, $el->{children}->[1]->literal;                  push @attribute_order, $el->{children}->[1]->literal;
# Line 70  sub includes { Line 75  sub includes {
75          return $include;          return $include;
76  }  }
77    
78    our $class_has_tests;
79    
80    sub parse_tests {
81            my ( $self ) = @_;
82    
83            map {
84                    warn "## ppi test $_" if $self->debug;
85    
86                    my $doc = Frey::PPI->new( class => $_ );
87                    my @tests;
88    
89    #               warn "## ",dump( $doc );
90    
91                    $doc->find(sub {
92                            my ($doc,$el) = @_;
93                            return unless
94                                    $el->isa('PPI::Statement') &&
95                                    $el->{children}->[0]->isa('PPI::Token::Word') &&
96                                    $el->{children}->[0]->literal eq 'use_ok';
97    
98    #                       warn "## ",dump( $el );
99                            my $class = $el->child(1)->child(0)->child(0)->literal;
100                            $class_has_tests->{$class}->{$_}++;
101                    });
102            } glob 't/*.t';
103            warn "# collected class tests ",dump( $class_has_tests ) if $self->debug;
104    
105            return $class_has_tests;
106    }
107    
108    =head2 has_tests
109    
110      my @tests = $self->has_tests;
111    
112    =cut
113    
114    sub has_tests {
115            my ($self) = shift;
116            
117            $self->parse_tests unless defined $class_has_tests;
118    
119            my $class = $self->class;
120    
121            if ( my $tests = $class_has_tests->{ $class } ) {
122    #               warn "# has_tests $class ",dump( keys %$tests );
123                    return [ keys %$tests ];
124            }
125            return [];
126    }
127    
128    =head2 as_data
129    
130    Debugging output
131    
132    =cut
133    
134  sub as_data {  sub as_data {
135          my $self = shift;          my $self = shift;
136          return {          return {
137                  includes => $self->includes,                  includes => $self->includes,
138                  attribute_order => $self->attribute_order,                  attribute_order => [ $self->attribute_order ],
139                  doc => $self->doc,                  doc => $self->doc,
140          };          };
141  }  }

Legend:
Removed from v.486  
changed lines
  Added in v.487

  ViewVC Help
Powered by ViewVC 1.1.26