Perl/Analysis/Static/Document.pm

filter: Statementstmt 93.7% 30 / 32 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 88.8% 40 / 45 CC 4 SCAR 6.7
CC
4
Cov
87%
_build_ppi
3.2
find
2.0
BEGIN
1.0
CRAP 2.0
« Perl/Analysis/Static/Question/Sub/NameLike.pm ↑ Summary Perl/Analysis/Static/Analysis/Sub.pm »
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
BranchTrueFalseTotal
unless ($class =~ /Perl::Analysis::Static::Element::(.+)/) 0 4 4
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
BranchTrueFalseTotal
unless ($ppi) 0 11 11
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
BranchTrueFalseTotal
$ppi->index_locations or die "index" 11 0 11
58  
59 11 return $ppi;
60 }
61  
62 13 1;
63  
64 __END__
« Perl/Analysis/Static/Question/Sub/NameLike.pm ↑ Summary Perl/Analysis/Static/Analysis/Sub.pm »