| 1 | package Perl::Analysis::Static::Analysis::Declaration::Package; | ||||||||||
| 2 | { | ||||||||||
| 3 | 1 | $Perl::Analysis::Static::Analysis::Declaration::Package::VERSION = '0.004'; # TRIAL | |||||||||
| 4 | } | ||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: find all declarations of packages | ||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use English qw( -no_match_vars ); # Avoids regex performance penalty | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use Perl::Analysis::Static::Element::Declaration::Package; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | extends 'Perl::Analysis::Static::Analysis'; | |||||||||
| 15 | |||||||||||
| 16 | 1 | has '_ppi_class' => | |||||||||
| 17 | ( is => 'rw', isa => 'Str', default => 'PPI::Statement::Package' ); | ||||||||||
| 18 | |||||||||||
| 19 | 2 | ▶ | sub _convert { | ||||||||
|
Subroutine
_convert: called CC=3 SCAR=12.6
| |||||||||||
| 20 | 2 | my ( $self, $node ) = @_; | |||||||||
| 21 | |||||||||||
| 22 | # get significant children | ||||||||||
| 23 | 2 | my @schildren = $node->schildren(); | |||||||||
| 24 | |||||||||||
| 25 | # the first child is the keyword | ||||||||||
| 26 | 2 | ▶ | unless ( $schildren[0] eq 'package' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | |||||||||||
| 28 | # CHECK: log a warning if this isn't the case? | ||||||||||
| 29 | 0 | return; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | # the sub's name is the second child | ||||||||||
| 33 | 2 | my $name = $schildren[1]; | |||||||||
| 34 | |||||||||||
| 35 | 2 | ▶ | unless ( $name->isa('PPI::Token::Word') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | die 'PANIC: unexpected class ' . $name->class; | |||||||||
| 37 | 0 | return; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 2 | return Perl::Analysis::Static::Element::Declaration::Package->new( | |||||||||
| 41 | name => $name->content, | ||||||||||
| 42 | from => $node->location->[0], | ||||||||||
| 43 | to => $node->location->[0], | ||||||||||
| 44 | ppi_node => $node | ||||||||||
| 45 | ); | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | 1 | 1; | |||||||||
| 50 | |||||||||||
| 51 | __END__ | ||||||||||