| 1 | package Perl::Analysis::Static::Document; | ||||||||||
| 2 | { | ||||||||||
| 3 | 13 | $Perl::Analysis::Static::Document::VERSION = '0.004'; # TRIAL | |||||||||
| 4 | } | ||||||||||
| 5 | # ABSTRACT: a Perl document | ||||||||||
| 6 | |||||||||||
| 7 | 13 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 13 | ▶ | use PPI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 13 | ▶ | use PPI::Cache; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 13 | ▶ | use Module::Runtime qw(use_module); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 13 | has 'filename' => ( is => 'rw', isa => 'Str' ); | |||||||||
| 14 | 13 | has 'ppi' => ( | |||||||||
| 15 | is => 'rw', | ||||||||||
| 16 | isa => 'PPI::Document', | ||||||||||
| 17 | lazy => 1, | ||||||||||
| 18 | builder => '_build_ppi' | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | 4 | ▶ | sub find { | ||||||||
|
Subroutine
find: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 23 | 4 | my ($self, $class) = @_; | |||||||||
| 24 | |||||||||||
| 25 | 4 | ▶ | unless ($class =~ m{Perl::Analysis::Static::Element::(.+)}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | # we should do something else here | ||||||||||
| 27 | 0 | die "BUG: Unable to match class '$class'"; | |||||||||
| 28 | } | ||||||||||
| 29 | 4 | my $element=$1; | |||||||||
| 30 | |||||||||||
| 31 | # get name of analysis | ||||||||||
| 32 | 4 | my $analysis_class = 'Perl::Analysis::Static::Analysis::'.$element; | |||||||||
| 33 | |||||||||||
| 34 | 4 | use_module($analysis_class); | |||||||||
| 35 | |||||||||||
| 36 | # TODO | ||||||||||
| 37 | 4 | my $analysis=$analysis_class->new(); | |||||||||
| 38 | 4 | return $analysis->analyse($self); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | |||||||||||
| 42 | 11 | ▶ | sub _build_ppi { | ||||||||
|
Subroutine
_build_ppi: called CC=3 SCAR=11.6
| |||||||||||
| 43 | 11 | my ($self) = @_; | |||||||||
| 44 | |||||||||||
| 45 | # content ought to be passed as reference | ||||||||||
| 46 | # my $ppi = PPI::Document->new( \$self->source()->content() ); | ||||||||||
| 47 | 11 | my $ppi = PPI::Document->new( $self->filename ); | |||||||||
| 48 | 11 | ▶ | unless ($ppi) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | die "Unable to create instance of '".$self->filename."'"; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | # we have to set the tab width and call index_locations or we won't get | ||||||||||
| 53 | # correct information about the location (or maybe no location information | ||||||||||
| 54 | # at all). I don't know if this is always the case or just a matter of | ||||||||||
| 55 | # versioning. | ||||||||||
| 56 | 11 | $ppi->tab_width(4); | |||||||||
| 57 | 11 | ▶ | $ppi->index_locations() or die 'index'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | |||||||||||
| 59 | 11 | return $ppi; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 13 | 1; | |||||||||
| 63 | |||||||||||
| 64 | __END__ | ||||||||||