Perl/Analysis/Static/Analysis/Sub.pm

filter: Statementstmt 92.8% 26 / 28 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 89.1% 33 / 37 CC 3 SCAR 6.6
CC
3
Cov
88%
_convert
3.2
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« Perl/Analysis/Static/Document.pm ↑ Summary Perl/Analysis/Static/Element/Block.pm »
1 package Perl::Analysis::Static::Analysis::Sub;
2 {
3 4 $Perl::Analysis::Static::Analysis::Sub::VERSION = '0.004'; # TRIAL
4 }
5  
6 # ABSTRACT: find all subroutine declarations
7  
8 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use English qw( -no_match_vars ); # Avoids regex performance penalty
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶use Perl::Analysis::Static::Element::Sub;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 extends 'Perl::Analysis::Static::Analysis';
15  
16 4 has '_ppi_class' =>
17 ( is => 'rw', isa => 'Str', default => 'PPI::Statement::Sub' );
18  
19 8 ▶sub _convert {
Subroutine _convert: called CC=3 SCAR=11.5
20 8 my ( $self, $node ) = @_;
21  
22 # get significant children
23 8 my @schildren = $node->schildren();
24  
25 # the first child is the keyword, for subs
26 # this has to be 'sub'
27 8 ▶ unless ( $schildren[0] eq 'sub' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($schildren[0] eq "sub") 0 8 8
28  
29 # CHECK: log a warning if this isn't the case?
30 0 return;
31 }
32  
33 # the sub's name is the second child
34 8 my $name = $schildren[1];
35  
36 # CHECK: look for a block that has been found by the Block analysis?
37 8 my $block = $schildren[2];
38  
39 # the third one is the block containing the statements
40 8 ▶ unless ( $block->isa('PPI::Structure::Block') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($block->isa("PPI::Structure::Block")) 0 8 8
41  
42 # CHECK: log a warning if this isn't the case?
43 0 return;
44 }
45  
46 8 my $from = $block->start->location->[0];
47 8 my $to = $block->finish->location->[0];
48  
49 8 return Perl::Analysis::Static::Element::Sub->new(
50 name => $name->content(),
51 from => $from,
52 to => $to,
53 ppi_node => $node
54 );
55 }
56  
57 4 1;
58  
59 __END__
« Perl/Analysis/Static/Document.pm ↑ Summary Perl/Analysis/Static/Element/Block.pm »