--- trunk/lib/Frey/PPI.pm 2008/11/19 15:28:23 455 +++ trunk/lib/Frey/PPI.pm 2008/11/24 17:09:00 487 @@ -19,8 +19,10 @@ lazy => 1, default => sub { my ( $self ) = @_; - warn "# doc from ", $self->class if $self->debug; - my $doc = PPI::Document->new( $self->class_path( $self->class ) ); + my $path = $self->class; + $path = $self->class_path( $path ) unless $path =~ m{/}; + warn "# doc from ", $self->class, " at ", $path if $self->debug; + my $doc = PPI::Document->new( $path ); $doc->prune('PPI::Token::Whitespace'); return $doc; }, @@ -43,7 +45,10 @@ my @attribute_order; $self->find(sub { my ($doc,$el) = @_; - return unless ( $el->isa('PPI::Statement') && $el->{children}->[0]->isa('PPI::Token::Word') && $el->{children}->[0]->literal eq 'has' ); + return unless + $el->isa('PPI::Statement') && + $el->{children}->[0]->isa('PPI::Token::Word') && + $el->{children}->[0]->literal eq 'has'; warn "## has ",$el->{children}->[1]->literal if $self->debug; push @attribute_order, $el->{children}->[1]->literal; @@ -70,11 +75,67 @@ return $include; } +our $class_has_tests; + +sub parse_tests { + my ( $self ) = @_; + + map { + warn "## ppi test $_" if $self->debug; + + my $doc = Frey::PPI->new( class => $_ ); + my @tests; + +# warn "## ",dump( $doc ); + + $doc->find(sub { + my ($doc,$el) = @_; + return unless + $el->isa('PPI::Statement') && + $el->{children}->[0]->isa('PPI::Token::Word') && + $el->{children}->[0]->literal eq 'use_ok'; + +# warn "## ",dump( $el ); + my $class = $el->child(1)->child(0)->child(0)->literal; + $class_has_tests->{$class}->{$_}++; + }); + } glob 't/*.t'; + warn "# collected class tests ",dump( $class_has_tests ) if $self->debug; + + return $class_has_tests; +} + +=head2 has_tests + + my @tests = $self->has_tests; + +=cut + +sub has_tests { + my ($self) = shift; + + $self->parse_tests unless defined $class_has_tests; + + my $class = $self->class; + + if ( my $tests = $class_has_tests->{ $class } ) { +# warn "# has_tests $class ",dump( keys %$tests ); + return [ keys %$tests ]; + } + return []; +} + +=head2 as_data + +Debugging output + +=cut + sub as_data { my $self = shift; return { includes => $self->includes, - attribute_order => $self->attribute_order, + attribute_order => [ $self->attribute_order ], doc => $self->doc, }; }