| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 26 | 351 | my $token = shift @tokens; | |||||||||||||||||||||||||||||||
| 27 | 351 | ▶ | next if $token->class eq 'PPI::Token::Whitespace'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 28 | 351 | ▶ | $started = 1, next if not $started and $token->content =~ /^Class::XSAccessor(?:::Array)?$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $started and $token->content =~ /^Class::XSAccessor(?:::Array)?$/
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)?$/
| |||||||||||||||||||||||||||||||||
| 29 | 320 | ▶ | next if not $started; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | # handle embedded ()'s | ||||||||||||||||||||||||||||||||
| 32 | 289 | ▶ | if ($token->isa("PPI::Structure::List")) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | 2 | next; | |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 287 | ▶ | if ($state eq 'key') { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 41 | 79 | my $keyname = File::PackageIndexer::PPI::Util::get_keyname($token); | |||||||||||||||||||||||||||||||
| 42 | 79 | ▶ | return() if not defined $keyname; # broken usage? | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 48 | 129 | ▶ | last if $token->content eq ';'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | 129 | ▶ | return() unless $token->content =~ /^(?:,|=>)$/; # are there other valid comma-likes? | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 50 | 129 | ▶ | $state = defined($key) ? 'value' : 'key'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | elsif ($state eq 'value') { | ||||||||||||||||||||||||||||||||
| 53 | 79 | ▶ | if ($key eq 'class') { | ||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||
| 54 | 8 | ▶ | $class = $token->isa("PPI::Token::Quote") ? $token->string : $token->content; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$struct and ref $struct eq "ARRAY"
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"
| |||||||||||||||||||||||||||||||||
| 62 | 17 | push @subs, @$struct; | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | ▶ | elsif ($struct and ref($struct) eq 'HASH') { | |||||||||||||||||||||||||||||||
|
Condition33%1/3
$struct and ref $struct eq "HASH"
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"
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||