/[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 369 by dpavlin, Mon Nov 17 14:37:48 2008 UTC revision 943 by dpavlin, Tue Jan 6 14:50:30 2009 UTC
# Line 1  Line 1 
1  package Frey::PPI;  package Frey::PPI;
2  use Moose;  use Moose;
3    
4  extends 'Frey::ClassLoader';  extends 'Frey::Class::Loader';
5    
6  use PPI;  use PPI;
7  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
# 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;                  my $path = $self->class;
23                  my $doc = PPI::Document->new( $self->class_path( $self->class ) ) || die $!;                  $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 64  sub includes { Line 69  sub includes {
69                  return unless $el->isa('PPI::Statement::Include');                  return unless $el->isa('PPI::Statement::Include');
70    
71                  warn "## include ",dump( $el->module, $el->type, $el->pragma ) if $self->debug;                  warn "## include ",dump( $el->module, $el->type, $el->pragma ) if $self->debug;
72                  push @{ $include->{ $el->type } }, $el->module                  push @{ $include->{ $el->type } }, $el->module
73                            unless $el->module eq 'lib'; # skip use lib 'lib';
74          });          });
75          warn "# ", $self->class, " include ", dump( $include ) if $self->debug;          warn "# ", $self->class, " include ", dump( $include ) if $self->debug;
76          return $include;          return $include;
77  }  }
78    
79  sub data {  our $class_has_tests;
80    
81    sub parse_tests {
82            my ( $self ) = @_;
83    
84            map {
85                    warn "## ppi test $_" if $self->debug;
86    
87                    my $doc = Frey::PPI->new( class => $_ );
88                    my @tests;
89    
90    #               warn "## ",dump( $doc );
91    
92                    $doc->find(sub {
93                            my ($doc,$el) = @_;
94                            return unless
95                                    $el->isa('PPI::Statement') &&
96                                    $el->{children}->[0]->isa('PPI::Token::Word') &&
97                                    $el->{children}->[0]->literal eq 'use_ok';
98    
99    #                       warn "## ",dump( $el );
100                            my $class = $el->child(1)->child(0)->child(0)->literal;
101                            $class_has_tests->{$class}->{$_}++;
102                    });
103            } glob 't/*.t';
104            warn "# collected class tests ",dump( $class_has_tests ) if $self->debug;
105    
106            return $class_has_tests;
107    }
108    
109    =head2 has_tests
110    
111      my @tests = $self->has_tests;
112    
113    =cut
114    
115    sub has_tests {
116            my ($self) = shift;
117            
118            $self->parse_tests unless $class_has_tests;
119    
120            my $class = $self->class;
121    
122            if ( my $tests = $class_has_tests->{ $class } ) {
123                    my @tests = keys %$tests;
124                    warn "# has_tests $class ",dump( @tests );
125                    return @tests if wantarray;
126                    return \@tests;
127            }
128    }
129    
130    =head2 as_data
131    
132    Debugging output
133    
134    =cut
135    
136    sub as_data {
137          my $self = shift;          my $self = shift;
138          return {          return {
139                  includes => $self->includes,                  includes => $self->includes,
140                  attribute_order => $self->attribute_order,                  attribute_order => [ $self->attribute_order ],
141                  doc => $self->doc,                  doc => $self->doc,
142          };          };
143  }  }

Legend:
Removed from v.369  
changed lines
  Added in v.943

  ViewVC Help
Powered by ViewVC 1.1.26