| 1 | package PLS::Parser::PackageSymbols; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Fcntl (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Storable (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | PLS::Parser::PackageSymbols | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | This package executes a Perl process to import a package and interrogate | ||||||||||||||||||||||||||||
| 16 | its symbol table to find all of the symbols in the package. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub get_package_functions | ||||||||||||||||||||||||||||
| 21 | { | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | my ($package, $inc) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_package_functions: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | return unless (length $package); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # Fork off a process that imports the package | ||||||||||||||||||||||||||||
| 27 | # and gets a list of all the functions available. | ||||||||||||||||||||||||||||
| 28 | # | ||||||||||||||||||||||||||||
| 29 | # We fork to avoid polluting our own namespace. | ||||||||||||||||||||||||||||
| 30 | 0 | pipe my $read_fh, my $write_fh; | |||||||||||||||||||||||||||
| 31 | 0 | my $pid = fork; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($pid) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||
| 35 | 0 | close $write_fh; | |||||||||||||||||||||||||||
| 36 | 0 | my $timeout = 0; | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | local $SIG{ALRM} = sub { $timeout = 1 }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 38 | 0 | alarm 10; | |||||||||||||||||||||||||||
| 39 | 0 | my $result = eval { Storable::fd_retrieve($read_fh) }; | |||||||||||||||||||||||||||
| 40 | 0 | alarm 0; | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | return if $timeout; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | waitpid $pid, 0; | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | return if (ref $result ne 'HASH' or not $result->{ok}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $result ne "HASH" or not $result->{"ok"}
MC/DC0%0/2
ref $result ne "HASH" or not $result->{"ok"}
ref $result ne "HASH"
not $result->{"ok"}
Truth table0%0/3
A or not(B)
A= ref $result ne "HASH"B= not $result->{"ok"}
| |||||||||||||||||||||||||||||
| 44 | 0 | return $result->{functions}; | |||||||||||||||||||||||||||
| 45 | } ## end if ($pid) | ||||||||||||||||||||||||||||
| 46 | else | ||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||
| 48 | 0 | close $read_fh; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | my $flags = fcntl $write_fh, Fcntl::F_GETFD, 0; | |||||||||||||||||||||||||||
| 51 | 0 | fcntl $write_fh, Fcntl::F_SETFD, $flags & ~Fcntl::FD_CLOEXEC; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | my $script = _get_package_functions_script(fileno($write_fh), $package); | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | my @inc = map { "-I$_" } @{$inc // []}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$inc // []
MC/DC0%0/1
$inc // []
$inc
Truth table0%0/2
A
A= $inc
| |||||||||||||||||||||||||||||
| 55 | 0 | exec $^X, @inc, '-e', $script; | |||||||||||||||||||||||||||
| 56 | } ## end else [ if ($pid) ] | ||||||||||||||||||||||||||||
| 57 | } ## end sub get_package_functions | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | sub _get_package_functions_script | ||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | my ($fileno, $package) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_get_package_functions_script: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | my $script = << 'EOF'; | |||||||||||||||||||||||||||
| 64 | use File::Spec; | ||||||||||||||||||||||||||||
| 65 | use Storable; | ||||||||||||||||||||||||||||
| 66 | use Sub::Util; | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | open STDOUT, '>', File::Spec->devnull; | ||||||||||||||||||||||||||||
| 69 | open STDERR, '>', File::Spec->devnull; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | open my $write_fh, '>>&=', %d; | ||||||||||||||||||||||||||||
| 72 | my $package = q{%s} =~ s/['"]//gr; | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | my @module_parts = split /::/, $package; | ||||||||||||||||||||||||||||
| 75 | my @parent_module_parts = @module_parts; | ||||||||||||||||||||||||||||
| 76 | pop @parent_module_parts; | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | my @functions; | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | foreach my $parts (\@parent_module_parts, \@module_parts) | ||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | my $package = join '::', @{$parts}; | ||||||||||||||||||||||||||||
| 83 | eval "require $package"; | ||||||||||||||||||||||||||||
| 84 | next if $@; | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | my $ref = \%%::; | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | foreach my $part (@{$parts}) | ||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||
| 90 | $ref = $ref->{"${part}::"}; | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | foreach my $name (keys %%{$ref}) | ||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||
| 95 | next if $name =~ /^BEGIN|UNITCHECK|INIT|CHECK|END|VERSION|import$/; | ||||||||||||||||||||||||||||
| 96 | my $code_ref = $package->can($name); | ||||||||||||||||||||||||||||
| 97 | next unless (ref $code_ref eq 'CODE'); | ||||||||||||||||||||||||||||
| 98 | next if Sub::Util::subname($code_ref) !~ /^${package}(?:::.+)*::${name}$/; | ||||||||||||||||||||||||||||
| 99 | push @functions, $name; | ||||||||||||||||||||||||||||
| 100 | } ## end foreach my $name (keys %%{$ref...}) | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | Storable::nstore_fd({ok => 1, functions => \@functions}, $write_fh); | ||||||||||||||||||||||||||||
| 104 | EOF | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | return sprintf $script, $fileno, $package; | |||||||||||||||||||||||||||
| 107 | } ## end sub _get_package_functions_script | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 1 | 1; | |||||||||||||||||||||||||||