PackageIndexer/PPI/ClassXSAccessor.pm

filter: Statementstmt 100% 53 / 53 Branchbran 77.2% 34 / 44 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 85.4% 100 / 117 CC 28 SCAR 33.0
CC
28
Cov
88%
handle_class_xsaccessor
29.9
BEGIN
1.0
BEGIN
1.0
CRAP 27.1
↑ Summary PackageIndexer/PPI/Util.pm »
1 package File::PackageIndexer::PPI::ClassXSAccessor;
2  
3 9 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 our $VERSION = '0.01';
8  
9  
10 # The Class::XSAccessor special case
11 31 ▶sub handle_class_xsaccessor {
Subroutine handle_class_xsaccessor: called CC=28 SCAR=34.0
Pod undocumented
12 31 my $indexer = shift;
13 31 my $statement = shift;
14 31 my $curpkg = shift;
15 31 my $pkgs = shift;
16  
17 31 my @subs;
18 31 ▶ my $class = defined($curpkg) ? $curpkg->{name} : $indexer->default_package;
Branch: 1 branch
BranchTrueFalseTotal
defined $curpkg ? : 21 10 31
19 31 my $started = 0;
20 31 my $state = "key";
21 31 my $key;
22 31 my @tokens = $statement->schildren();
23 31 pop @tokens; # remove ;
24  
25 31 ▶ while (@tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens) 351 31 382
26 351 my $token = shift @tokens;
27 351 ▶ next if $token->class eq 'PPI::Token::Whitespace';
Branch: 1 branch
BranchTrueFalseTotal
if $token->class eq "PPI::Token::Whitespace" 0 351 351
28 351 ▶ $started = 1, next if not $started and $token->content =~ /^Class::XSAccessor(?:::Array)?$/;
Branch: 1 branch
BranchTrueFalseTotal
if not $started and $token->content =~ /^Class::XSAccessor(?:::Array)?$/ 31 320 351
Condition100%3/3
not $started and $token->content =~ /^Class::XSAccessor(?:::Array)?$/
!ll&&!rl&&r
2893131
MC/DC100%2/2
not $started and $token->content =~ /^Class::XSAccessor(?:::Array)?$/
not $started $token->content =~ /^Class::XSAccessor(?:::Array)?$/
Truth table100%3/3
not(A) and B
A= not $startedB= $token->content =~ /^Class::XSAccessor(?:::Array)?$/
ABresult
0X0
100
111
29 320 ▶ next if not $started;
Branch: 1 branch
BranchTrueFalseTotal
unless $started 31 289 320
30  
31 # handle embedded ()'s
32 289 ▶ if ($token->isa("PPI::Structure::List")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->isa("PPI::Structure::List")) 2 287 289
33 2 my @t = $token->schildren;
34 2 foreach my $t (@t) {
35 2 ▶ unshift @tokens, ($t->isa("PPI::Statement::Expression") ? $t->schildren() : $t);
Branch: 1 branch
BranchTrueFalseTotal
$t->isa('PPI::Statement::Expression') ? : 2 0 2
36 }
37 2 next;
38 }
39  
40 287 ▶ if ($state eq 'key') {
Branch: 3 branches
BranchTrueFalseTotal
if ($state eq 'key') { } 79 208 287
elsif ($state eq 'comma') { } 129 79 208
elsif ($state eq 'value') { } 79 0 79
41 79 my $keyname = File::PackageIndexer::PPI::Util::get_keyname($token);
42 79 ▶ return() if not defined $keyname; # broken usage?
Branch: 1 branch
BranchTrueFalseTotal
unless defined $keyname 0 79 79
43 79 $key = $keyname;
44 79 $state = 'comma';
45 }
46 elsif ($state eq 'comma') {
47 129 ▶ return() unless $token->isa("PPI::Token::Operator");
Branch: 1 branch
BranchTrueFalseTotal
unless $token->isa("PPI::Token::Operator") 0 129 129
48 129 ▶ last if $token->content eq ';';
Branch: 1 branch
BranchTrueFalseTotal
if $token->content eq ";" 0 129 129
49 129 ▶ return() unless $token->content =~ /^(?:,|=>)$/; # are there other valid comma-likes?
Branch: 1 branch
BranchTrueFalseTotal
unless $token->content =~ /^(?:,|=>)$/ 0 129 129
50 129 ▶ $state = defined($key) ? 'value' : 'key';
Branch: 1 branch
BranchTrueFalseTotal
defined $key ? : 79 50 129
51 }
52 elsif ($state eq 'value') {
53 79 ▶ if ($key eq 'class') {
Branch: 4 branches
BranchTrueFalseTotal
if ($key eq 'class') { } 8 71 79
elsif ($key =~ /^(?:chained|replace)$/) { } 18 53 71
elsif ($token->isa('PPI::Structure::Constructor')) { } 51 2 53
elsif ($token->isa('PPI::Token::Quote')) { } 2 0 2
54 8 ▶ $class = $token->isa("PPI::Token::Quote") ? $token->string : $token->content;
Branch: 1 branch
BranchTrueFalseTotal
$token->isa('PPI::Token::Quote') ? : 8 0 8
55 }
56 elsif ($key =~ /^(?:chained|replace)$/) {
57 # option, do nothing
58 }
59 elsif ($token->isa("PPI::Structure::Constructor")) {
60 51 my $struct = File::PackageIndexer::PPI::Util::constructor_to_structure($token);
61 51 ▶ if ($struct and ref($struct) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if ($struct and ref $struct eq 'ARRAY') { } 17 34 51
elsif ($struct and ref $struct eq 'HASH') { } 34 0 34
Condition66%2/3
$struct and ref $struct eq "ARRAY"
!ll&&!rl&&r
03417
MC/DC50%1/2
$struct and ref $struct eq "ARRAY"
$struct ref $struct eq "ARRAY"
Truth table66%2/3
A and B
A= $structB= ref $struct eq "ARRAY"
ABresult
0X0
100
111
62 17 push @subs, @$struct;
63 }
64 ▶ elsif ($struct and ref($struct) eq 'HASH') {
Condition33%1/3
$struct and ref $struct eq "HASH"
!ll&&!rl&&r
0034
MC/DC0%0/2
$struct and ref $struct eq "HASH"
$struct ref $struct eq "HASH"
Truth table33%1/3
A and B
A= $structB= ref $struct eq "HASH"
ABresult
0X0
100
111
65 34 push @subs, keys %$struct;
66 }
67 }
68 elsif ($token->isa("PPI::Token::Quote")) {
69 2 push @subs, $token->string;
70 }
71 79 $key = undef;
72 79 $state = 'comma';
73 } # end if value
74  
75 } # end while tokens
76  
77 31 my $pkg = $indexer->lazy_create_pkg($class, $pkgs);
78 31 my $subs = $pkg->{subs};
79 31 $pkg->{subs}{$_} = 1 for @subs;
80 31 return();
81 }
82  
83  
84  
85 9 1;
86  
87 __END__
↑ Summary PackageIndexer/PPI/Util.pm »