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/; |
8 |
|
use File::Find; |
9 |
|
|
10 |
has 'class' => ( |
has 'class' => ( |
11 |
is => 'rw', |
is => 'rw', |
29 |
}, |
}, |
30 |
); |
); |
31 |
|
|
32 |
sub find { |
sub find_doc_el { |
33 |
my ( $self, $coderef ) = @_; |
my ( $self, $coderef ) = @_; |
34 |
|
|
35 |
my $doc = $self->doc; |
my $doc = $self->doc; |
44 |
my ( $self ) = @_; |
my ( $self ) = @_; |
45 |
|
|
46 |
my @attribute_order; |
my @attribute_order; |
47 |
$self->find(sub { |
$self->find_doc_el(sub { |
48 |
my ($doc,$el) = @_; |
my ($doc,$el) = @_; |
49 |
return unless |
return unless |
50 |
$el->isa('PPI::Statement') && |
$el->isa('PPI::Statement') && |
65 |
my $self = shift; |
my $self = shift; |
66 |
|
|
67 |
my $include; |
my $include; |
68 |
$self->find(sub { |
$self->find_doc_el(sub { |
69 |
my ($doc,$el) = @_; |
my ($doc,$el) = @_; |
70 |
return unless $el->isa('PPI::Statement::Include'); |
return unless $el->isa('PPI::Statement::Include'); |
71 |
|
|
72 |
warn "## include ",dump( $el->module, $el->type, $el->pragma ) if $self->debug; |
warn "## include ",dump( $el->module, $el->type, $el->pragma ) if $self->debug; |
73 |
push @{ $include->{ $el->type } }, $el->module |
push @{ $include->{ $el->type } }, $el->module |
74 |
|
unless $el->module eq 'lib'; # skip use lib 'lib'; |
75 |
}); |
}); |
76 |
warn "# ", $self->class, " include ", dump( $include ) if $self->debug; |
warn "# ", $self->class, " include ", dump( $include ) if $self->debug; |
77 |
return $include; |
return $include; |
82 |
sub parse_tests { |
sub parse_tests { |
83 |
my ( $self ) = @_; |
my ( $self ) = @_; |
84 |
|
|
85 |
map { |
finddepth({ no_chdir => 1, wanted => sub { |
86 |
|
return unless m{\.t$}; |
87 |
|
|
88 |
warn "## ppi test $_" if $self->debug; |
warn "## ppi test $_" if $self->debug; |
89 |
|
|
90 |
my $doc = Frey::PPI->new( class => $_ ); |
my $ppi = Frey::PPI->new( class => $_ ); |
91 |
my @tests; |
my @tests; |
92 |
|
|
93 |
# warn "## ",dump( $doc ); |
# warn "## ",dump( $doc ); |
94 |
|
|
95 |
$doc->find(sub { |
$ppi->find_doc_el(sub { |
96 |
my ($doc,$el) = @_; |
my ($doc,$el) = @_; |
97 |
return unless |
return unless |
98 |
$el->isa('PPI::Statement') && |
$el->isa('PPI::Statement') && |
103 |
my $class = $el->child(1)->child(0)->child(0)->literal; |
my $class = $el->child(1)->child(0)->child(0)->literal; |
104 |
$class_has_tests->{$class}->{$_}++; |
$class_has_tests->{$class}->{$_}++; |
105 |
}); |
}); |
106 |
} glob 't/*.t'; |
} }, 't/'); |
107 |
warn "# collected class tests ",dump( $class_has_tests ) if $self->debug; |
warn "# collected class tests ",dump( $class_has_tests ) if $self->debug; |
108 |
|
|
109 |
return $class_has_tests; |
return $class_has_tests; |
118 |
sub has_tests { |
sub has_tests { |
119 |
my ($self) = shift; |
my ($self) = shift; |
120 |
|
|
121 |
$self->parse_tests unless defined $class_has_tests; |
$self->parse_tests unless $class_has_tests; |
122 |
|
|
123 |
my $class = $self->class; |
my $class = $self->class; |
124 |
|
|
125 |
if ( my $tests = $class_has_tests->{ $class } ) { |
if ( my $tests = $class_has_tests->{ $class } ) { |
126 |
# warn "# has_tests $class ",dump( keys %$tests ); |
my @tests = keys %$tests; |
127 |
return [ keys %$tests ]; |
warn "# has_tests $class ",dump( @tests ); |
128 |
|
return @tests; |
129 |
} |
} |
|
return []; |
|
130 |
} |
} |
131 |
|
|
132 |
=head2 as_data |
=head2 as_data |