--- trunk/lib/Frey/PPI.pm 2008/11/16 19:50:36 364 +++ trunk/lib/Frey/PPI.pm 2008/11/24 17:26:47 489 @@ -19,8 +19,10 @@ lazy => 1, default => sub { my ( $self ) = @_; - warn "doc from ", $self->class; - my $doc = PPI::Document->new( $self->class_path( $self->class ) ) || die $!; + 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; }, @@ -40,18 +42,22 @@ sub attribute_order { my ( $self ) = @_; - my $attribute_order; + 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; + push @attribute_order, $el->{children}->[1]->literal; }); - warn "# ", $self->class, " attribute_order ", dump( $attribute_order ) if $self->debug; + warn "# ", $self->class, " attribute_order ", dump( @attribute_order ) if $self->debug; - return $attribute_order; + return @attribute_order if wantarray; + return \@attribute_order; } sub includes { @@ -69,11 +75,67 @@ return $include; } -sub data { +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 $class_has_tests; + + my $class = $self->class; + + if ( my $tests = $class_has_tests->{ $class } ) { + my @tests = keys %$tests; + warn "# has_tests $class ",dump( @tests ); + return @tests; + } +} + +=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, }; }