| 1 | package App::CSE::File::ApplicationXPerl; | ||
| 2 | $App::CSE::File::ApplicationXPerl::VERSION = '0.016'; | ||
| 3 | use Moose; | ||
| 4 | extends qw/App::CSE::File/; | ||
| 5 | |||
| 6 | use PPI; | ||
| 7 | # use PPI::Dumper; | ||
| 8 | |||
| 9 | has 'ppi' => ( is => 'ro', isa => 'Maybe[PPI::Document]', lazy_build => 1); | ||
| 10 | |||
| 11 | sub _build_ppi{ | ||
| 12 | my ($self) = @_; | ||
| 13 | my $doc = PPI::Document->new($self->file_path()); | ||
| 14 | # my $dumper = PPI::Dumper->new( $doc ); | ||
| 15 | # warn($dumper->string()); | ||
| 16 | return $doc; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub _build_call{ | ||
| 20 | my ($self) = @_; | ||
| 21 | unless( $self->ppi() ){ return []; } | ||
| 22 | |||
| 23 | my @calls = (); | ||
| 24 | $self->ppi->find(sub{ | ||
| 25 | if( $_[1]->isa('PPI::Token::Word') && ( $_[1]->method_call() | ||
| 26 | || _is_function_call($_[1]) ) ){ | ||
| 27 | push @calls, $_[1]->literal(); | ||
| 28 | } | ||
| 29 | }); | ||
| 30 | |||
| 31 | return \@calls; | ||
| 32 | } | ||
| 33 | |||
| 34 | # Dirty implementation of 'is a PPI token a function call' | ||
| 35 | # Until PPI does it the right way (see TODO in PPI::Token::Word). | ||
| 36 | sub _is_function_call{ | ||
| 37 | my ($ppi_token) = @_; | ||
| 38 | my $snext = $ppi_token->snext_sibling(); | ||
| 39 | return 0 unless $snext; | ||
| 40 | return $snext->isa('PPI::Structure::List'); | ||
| 41 | } | ||
| 42 | |||
| 43 | sub _build_decl{ | ||
| 44 | my ($self) = @_; | ||
| 45 | |||
| 46 | unless( $self->ppi() ){ return []; } | ||
| 47 | |||
| 48 | my @declarations = (); | ||
| 49 | |||
| 50 | ## Find and push all subs declarations | ||
| 51 | $self->ppi->find(sub{ | ||
| 52 | $_[1]->isa('PPI::Statement::Sub') and $_[1]->name and !$_[1]->reserved() | ||
| 53 | and push @declarations , $_[1]->name(); | ||
| 54 | }); | ||
| 55 | |||
| 56 | ## Find and push all package declarations | ||
| 57 | $self->ppi->find(sub{ $_[1]->isa('PPI::Statement::Package') | ||
| 58 | and $_[1]->namespace() | ||
| 59 | and | ||
| 60 | push @declarations , $_[1]->namespace() | ||
| 61 | } | ||
| 62 | ); | ||
| 63 | return \@declarations; | ||
| 64 | } | ||
| 65 | |||
| 66 | __PACKAGE__->meta->make_immutable(); |