| 1 | package PMLTQ::Command::query; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | our $AUTHORITY = 'cpan:MATY'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | $PMLTQ::Command::query::VERSION = '1.2.2'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: WIP: Executes query on treebank | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use PMLTQ::Base 'PMLTQ::Command'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Cwd; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Treex::PML; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Treex::PML::Instance; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Treex::PML::Schema; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Getopt::Long qw(GetOptionsFromArray); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use PMLTQ::Common ':tredmacro'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use File::Temp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | my $extension_dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | my %opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | has usage => sub { shift->extract_usage }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | GetOptionsFromArray(\@args, \%opts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 'debug|D', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 'server|s=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 'command|c=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 'ntred|N', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 'jtred|J', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 'btred|B', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 'sql|S', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 'shared-dir|d=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 'keep-tmp-files', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 'filelist|l=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 'username=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 'password=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 'auth-id=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 'pmltq-extension-dir|X=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 'stdin', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 'query|Q=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 'query-id|i=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 'query-file|f=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 'query-pml-file|p=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 'filters|F=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 'no-filters', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 'netgraph-query|G=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 'print-servers|P', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 'config-file|c=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 'node-types|n', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 'relations|r', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 'limit|L=i', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 'timeout|t=i', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 'quiet|q', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 'help|h=s@', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 'usage|u', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 'version|V', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 'man' ) || die "invalid options"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | Treex::PML::AddResourcePath( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | PMLTQ->resources_dir, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | File::Spec->catfile(${FindBin::RealBin},'config'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $ENV{HOME}.'/.tred.d' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | Treex::PML::AddBackends(qw(Storable PMLBackend PMLTransformBackend)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ($opts{stdin}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $opts{query} = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | $opts{$1}=1 if defined($opts{server}) and $opts{server}=~s{^[nbj]tred://}{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $opts{"server"} and $opts{"server"} =~ s[^[nbj]tred://][]
MC/DC0%0/2
defined $opts{"server"} and $opts{"server"} =~ s[^[nbj]tred://][]
defined $opts{"server"}
$opts{"server"} =~ s[^[nbj]tred://][]
Truth table0%0/3
A and B
A= defined $opts{"server"}B= $opts{"server"} =~ s[^[nbj]tred://][]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | $extension_dir = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | $opts{'pmltq-extension-dir'} || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | File::Spec->catfile($ENV{HOME},'.tred.d','extensions', 'pmltq'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opts{'pmltq-extension-dir'} || 'File::Spec'->catfile($ENV{'HOME'}, '.tred.d', 'extensions', 'pmltq')
MC/DC0%0/2
$opts{'pmltq-extension-dir'} || 'File::Spec'->catfile($ENV{'HOME'}, '.tred.d', 'extensions', 'pmltq')
$opts{'pmltq-extension-dir'}
'File::Spec'->catfile($ENV{'HOME'}, '.tred.d', 'extensions', 'pmltq')
Truth table0%0/3
A || B
A= $opts{'pmltq-extension-dir'}B= 'File::Spec'->catfile($ENV{'HOME'}, '.tred.d', 'extensions', 'pmltq')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | Treex::PML::AddResourcePath(File::Spec->catfile($extension_dir,'resources')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ($opts{ntred}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ntred_search(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } elsif ($opts{jtred}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | jtred_search(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } elsif ($opts{btred}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | btred_search(@args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | pmltq_http_search(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | my %auth; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | sub pmltq_http_search { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my @args = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pmltq_http_search: not called CC=51 SCAR=78.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $query; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($opts{query} and !@args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition0%0/3
$opts{"query"} and not @args
MC/DC0%0/2
$opts{"query"} and not @args
$opts{"query"}
not @args
Truth table0%0/3
A and not(B)
A= $opts{"query"}B= not @args
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $query = $opts{query}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ▶ | } elsif (!$query and @args) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
not $query and @args
MC/DC0%0/2
not $query and @args
not $query
@args
Truth table0%0/3
not(A) and B
A= not $queryB= @args
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $query=join ' ',@args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } elsif ($opts{'query-pml-file'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $query_file = Treex::PML::Factory->createDocumentFromFile($opts{'query-pml-file'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | die "Failed to open PML query file $opts{'query-pml-file'}: $Treex::PML::FSError\n" if $Treex::PML::FSError or !$query_file or !$query_file->trees; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$Treex::PML::FSError or not $query_file or not $query_file->trees
$Treex::PML::FSError or not $query_file
MC/DC0%0/3
$Treex::PML::FSError or not $query_file or not $query_file->trees
$Treex::PML::FSError
not $query_file
not $query_file->trees
Truth table0%0/4
A or not(B) or not(C)
A= $Treex::PML::FSErrorB= not $query_fileC= not $query_file->trees
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | $query = first { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | !$opts{'query-id'} or $_->{id} and $_->{id} eq $opts{'query-id'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
Condition0%0/6
!$opts{'query-id'} || $_->{'id'} && $_->{'id'} eq $opts{'query-id'}
$_->{"id"} and $_->{"id"} eq $opts{"query-id"}
MC/DC0%0/3
!$opts{'query-id'} || $_->{'id'} && $_->{'id'} eq $opts{'query-id'}
!$opts{'query-id'}
$_->{"id"}
$_->{"id"} eq $opts{"query-id"}
Truth table0%0/4
not(A) || B and C
A= !$opts{'query-id'}B= $_->{"id"}C= $_->{"id"} eq $opts{"query-id"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | } $query_file->trees; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | die "Didn't find query $opts{'query-id'} in query file $opts{'query-pml-file'}!" unless $query; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $query = encode('UTF-8',PMLTQ::Common::as_text($query)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } elsif ($opts{'query-file'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | open my $fh, $opts{'query-file'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | or die "Cannot open query file '$opts{'query-file'}': $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $query = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ($opts{'query-id'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $query=~s/#\s*==\s*query:\s*\Q$opts{'query-id'}\E\s* ==(.*?)(?:#\s*==\s*query:\s*\w+\s*==.*|$)/$1/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | ▶ | } elsif (!$opts{'node-types'} and !$opts{'relations'} and !$opts{'print-servers'}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$opts{'node-types'} || $opts{'relations'} || $opts{'print-servers'}
$opts{"node-types"} or $opts{"relations"}
MC/DC0%0/3
$opts{'node-types'} || $opts{'relations'} || $opts{'print-servers'}
$opts{"node-types"}
$opts{"relations"}
$opts{'print-servers'}
Truth table0%0/4
A or B || C
A= $opts{"node-types"}B= $opts{"relations"}C= $opts{'print-servers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | pod2usage(-msg => 'pmltq'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | exit 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if (!$opts{'query-pml-file'} and $opts{'netgraph-query'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $opts{"query-pml-file"} and $opts{"netgraph-query"}
MC/DC0%0/2
not $opts{"query-pml-file"} and $opts{"netgraph-query"}
not $opts{"query-pml-file"}
$opts{"netgraph-query"}
Truth table0%0/3
not(A) and B
A= not $opts{"query-pml-file"}B= $opts{"netgraph-query"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | require PMLTQ::NG2PMLTQ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $query = PMLTQ::NG2PMLTQ::ng2pmltq($query,{type=>$opts{'netgraph-query'}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if (!$opts{'node-types'} and !$opts{'relations'} and !$opts{'print-servers'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$opts{"node-types"} or $opts{"relations"} or $opts{"print-servers"}
$opts{"node-types"} or $opts{"relations"}
MC/DC0%0/3
$opts{"node-types"} or $opts{"relations"} or $opts{"print-servers"}
$opts{"node-types"}
$opts{"relations"}
$opts{"print-servers"}
Truth table0%0/4
A or B or C
A= $opts{"node-types"}B= $opts{"relations"}C= $opts{"print-servers"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | die "Query is empty!" unless $query; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my $filters = $opts{'filters'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if ($filters and $filters=~/\S/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$filters and $filters =~ /\S/
MC/DC0%0/2
$filters and $filters =~ /\S/
$filters
$filters =~ /\S/
Truth table0%0/3
A and B
A= $filtersB= $filters =~ /\S/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | $filters='>> '.$filters unless $filters =~ /^\s*>>/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $query .= $filters; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | $opts{'config-file'} ||= Treex::PML::FindInResources('treebase.conf'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opts{"config-file"} ||= Treex::PML::FindInResources("treebase.conf")
MC/DC0%0/2
$opts{"config-file"} ||= Treex::PML::FindInResources("treebase.conf")
$opts{"config-file"}
Treex::PML::FindInResources("treebase.conf")
Truth table0%0/3
A ||= B
A= $opts{"config-file"}B= Treex::PML::FindInResources("treebase.conf")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if ($opts{debug}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | print STDERR "Reading configuration from $opts{'config-file'}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | my $configs = (-f $opts{'config-file'}) ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | Treex::PML::Factory->createPMLInstance({ filename=>$opts{'config-file'} })->get_root->{configurations} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my $id = $opts{'server'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | $id ||= 'default' unless $opts{'print-servers'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$id ||= "default"
MC/DC0%0/1
$id ||= "default"
$id
Truth table0%0/2
A
A= $id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | my ($conf,$type) = $id ? get_server_conf($configs,$id) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | %auth = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | username => $opts{username}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | password => $opts{password}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if ($opts{'auth-id'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my ($auth) = get_server_conf($configs,$opts{'auth-id'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ($auth) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | $auth{$_} ||= $auth->{$_} for qw(username password); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$auth{$_} ||= $auth->{$_}
MC/DC0%0/2
$auth{$_} ||= $auth->{$_}
$auth{$_}
$auth->{$_}
Truth table0%0/3
A ||= B
A= $auth{$_}B= $auth->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | die "Didn't find auth-id configuration: $opts{'auth-id'}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if ($conf) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | $auth{$_} ||= $conf->{$_} for qw(username password); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$auth{$_} ||= $conf->{$_}
MC/DC0%0/2
$auth{$_} ||= $conf->{$_}
$auth{$_}
$conf->{$_}
Truth table0%0/3
A ||= B
A= $auth{$_}B= $conf->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if ($opts{'print-servers'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ($opts{'server'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | unless ($type eq 'http') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | die "Cannot query available services on a $type server"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $result=''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | http_search($conf->{url},$query,{ other=>1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | callback => sub { $result.=$_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | debug=>$opts{debug}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | %auth, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my @services = split /\n/,$result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | for my $srv (@services) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my %srv = map { split(':',$_,2) } split /\t/, $srv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | print $srv{id},"\t",$srv{service},"\t",$srv{title},"\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my @types = qw(dbi http); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my %columns = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | dbi => [qw(driver host port database username sources)], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | http => [qw(url username cached_description/title)], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | my %configs = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | map { my $type = $_; ($_ =>[map $_->value, grep { $_->name eq $type } SeqV($configs)]) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | @types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | for my $type (@types) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my $confs = $configs{$type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if (@$confs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | print uc($type)." configurations:\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | print (("-"x60)."\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | for my $c (@$confs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | print $c->{id}.": ".(join(", ", map "$_->[0]=$_->[1]", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | grep length($_->[1]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | map [m{/(.*)} ? $1 : $_,Treex::PML::Instance::get_data($c,$_)], @{$columns{$type}})."\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | print STDERR $query,"\n" if $opts{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if ($type eq 'http') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | http_search($conf->{url},$query,{ 'node-types'=>$opts{'node-types'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 'relations'=>$opts{'relations'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | debug=>$opts{debug}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | %auth | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | require PMLTQ::SQLEvaluator; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | my $evaluator = PMLTQ::SQLEvaluator->new(undef,{connect => $conf, debug=>$opts{debug}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | %auth | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $evaluator->connect(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | if ($opts{'node-types'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | print join "\n", @{$evaluator->get_node_types}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } elsif ($opts{'relations'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | print join "\n", @{$evaluator->get_specific_relations}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | search($evaluator,$query); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | $evaluator->{dbi}->disconnect() if $evaluator->{dbi}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | sub get_server_conf { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | my ($configs,$id)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_server_conf: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | my ($conf,$type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if ($id =~ /^http:/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $type = 'http'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $conf = {url => $id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | my $conf_el = first { $_->value->{id} eq $id } SeqV($configs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | die "Didn't find server configuration named '$id'!\nUse $0 --print-servers and then $0 --server <config-id|URL>\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | unless $conf_el; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $conf = $conf_el->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $type = $conf_el->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | return ($conf,$type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | sub http_search { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | my ($url,$query,$opts)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http_search: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | $opts||={}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts ||= {}
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | my $tmp = File::Temp->new( TEMPLATE => 'pmltq_XXXXX', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | TMPDIR => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | UNLINK => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | SUFFIX => '.txt' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | $ua->credentials(URI->new($url)->host_port,'PMLTQ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | $auth{username}, $auth{password}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | if $opts->{username}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $ua->agent("PMLTQ/1.0 "); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | $url.='/' unless $url=~m{^https?://.+/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | if ($opts->{'node-types'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $url = qq{${url}nodetypes}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $query = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } elsif ($opts->{'relations'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $url = qq{${url}relations}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $query = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } elsif ($opts->{'other'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $url = qq{${url}other}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $query = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | $url = qq{${url}query}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | $ua->timeout($opts{timeout}+2) if $opts{timeout}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $q = $query; Encode::_utf8_off($q); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | binmode STDOUT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | my $sub = $opts->{callback} || sub { print $_[0] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$opts->{'callback'} || sub {
print $_[0];
}
MC/DC0%0/2
$opts->{'callback'} || sub {
print $_[0];
}
$opts->{'callback'}
sub {
print $_[0];
}
Truth table0%0/3
A || B
A= $opts->{'callback'}B= sub {
print $_[0];
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | my $res = $ua->request(POST($url, [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | query => $q, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | format => 'text', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | limit => $opts{limit}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | row_limit => $opts{limit}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | timeout => $opts{timeout}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ]),$sub ,1024*8 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | unless ($res->is_success) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | die $res->status_line."\n".$res->content."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | sub search { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | my ($evaluator,$query)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my $results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | $evaluator->prepare_query($query); # count=>1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | $results = $evaluator->run({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | node_limit => $opts{limit}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | row_limit => $opts{limit}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | timeout => $opts{timeout}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | timeout_callback => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | print STDERR "Evaluation of query timed out\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | exit 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | warn $@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | if ($results) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | for my $r (@$results) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | print join("\t",@$r)."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | print STDERR $#$results+1," result(s)\n" unless $opts{quiet}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | sub quote_cmdline { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | my $quoted; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quote_cmdline: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | join ' ', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my $arg = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $arg =~ s{'}{'\\''}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | qq{'$arg'} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | sub ntred_search { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | my @args = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ntred_search: not called CC=17 SCAR=57.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | my ($host,$port)= $opts{server} ? split(/:/,$opts{server}) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | my $command = $opts{command} || 'ntred'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts{'command'} || 'ntred'
MC/DC0%0/1
$opts{'command'} || 'ntred'
$opts{'command'}
Truth table0%0/2
A
A= $opts{'command'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | my $shared_dir=File::Spec->rel2abs($opts{'shared-dir'} || '.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts{'shared-dir'} || '.'
MC/DC0%0/1
$opts{'shared-dir'} || '.'
$opts{'shared-dir'}
Truth table0%0/2
A
A= $opts{'shared-dir'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | my $filter_file="$shared_dir/pmltq_ntred_filter.$$.pl"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my @script_flags=('--filter-code-out', $filter_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | foreach (qw(query query-id query-file query-pml-file filters netgraph-query)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | push @script_flags, '--'.$_, (/file/ ? File::Spec->rel2abs($opts{$_}) : $opts{$_}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if defined($opts{$_}) and length($opts{$_}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $opts{$_} and length $opts{$_}
MC/DC0%0/2
defined $opts{$_} and length $opts{$_}
defined $opts{$_}
length $opts{$_}
Truth table0%0/3
A and B
A= defined $opts{$_}B= length $opts{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | $command .= ' '.quote_cmdline( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | ((defined($host) and length($host)) ? ('--hub',$host) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | ((defined($port) and length($port)) ? ('--port',$port) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | '-q', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | '-I', File::Spec->catfile($extension_dir,qw(contrib pmltq pmltq.ntred)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | ($opts{filelist} ? ('-l', File::Spec->rel2abs($opts{filelist})) : (@args ? ('-L', '--', @args) : ())), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/6
defined $host and length $host
defined $port and length $port
MC/DC0%0/2
defined $host and length $host
defined $host
length $host
MC/DC0%0/2
defined $port and length $port
defined $port
length $port
Truth table0%0/3
A and B
A= defined $hostB= length $host
Truth table0%0/3
A and B
A= defined $portB= length $port
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | '--', @script_flags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | open(my $pipe, $command.' | ') || die "Failed to start ntred client: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | apply_filter($pipe, $filter_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | close($pipe); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | unlink $filter_file if -f $filter_file and !$opts{'keep-tmp-files'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $filter_file and not $opts{"keep-tmp-files"}
MC/DC0%0/2
-f $filter_file and not $opts{"keep-tmp-files"}
-f $filter_file
not $opts{"keep-tmp-files"}
Truth table0%0/3
A and not(B)
A= -f $filter_fileB= not $opts{"keep-tmp-files"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | sub jtred_search { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | my @args = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
jtred_search: not called CC=24 SCAR=64.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | my $command = $opts{command} || 'jtred'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts{'command'} || 'jtred'
MC/DC0%0/1
$opts{'command'} || 'jtred'
$opts{'command'}
Truth table0%0/2
A
A= $opts{'command'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $jobname="pmltq_jtred_$$"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | if ($opts{server}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | $jobname.="-".$ENV{HOSTNAME}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | my $shared_dir=File::Spec->rel2abs($opts{'shared-dir'} || '.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts{'shared-dir'} || '.'
MC/DC0%0/1
$opts{'shared-dir'} || '.'
$opts{'shared-dir'}
Truth table0%0/2
A
A= $opts{'shared-dir'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my $filter_file="$shared_dir/$jobname.pl"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | my $filelist; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | if ($opts{filelist}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my ($vol,$dir) = File::Spec->splitpath($opts{filelist}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my $base = File::Spec->catpath($vol,$dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | open my $fh, '<', $opts{filelist} or die "Cannot open filelist $opts{filelist}: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $filelist = "$shared_dir/$jobname.fl"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | open my $out_fh, '>', $filelist or die "Cannot create temporary filelist $filelist: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | print STDERR "Resolving filelist files to $base...\n" unless $opts{quiet}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | while(<$fh>) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | print $out_fh File::Spec->rel2abs($_,$base),"\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | print STDERR "done.\n" unless $opts{quiet}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | close $out_fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | my @script_flags=('--filter-code-out', $filter_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | foreach (qw(query query-id query-file query-pml-file filters netgraph-query)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | push @script_flags, '--'.$_, (/file/ ? File::Spec->rel2abs($opts{$_}) : $opts{$_}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | if defined($opts{$_}) and length($opts{$_}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $opts{$_} and length $opts{$_}
MC/DC0%0/2
defined $opts{$_} and length $opts{$_}
defined $opts{$_}
length $opts{$_}
Truth table0%0/3
A and B
A= defined $opts{$_}B= length $opts{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | my @command = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | $command, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | ($opts{'shared-dir'} ? ('-jw', $shared_dir) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | '-jn', $jobname, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | ($opts{quiet} ? '-jq' : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | ($filelist ? ('-l', $filelist) : @args), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | '-jb', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | '-q', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | '-I', File::Spec->catfile($extension_dir,qw(contrib pmltq pmltq.ntred)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | '-o', @script_flags, '--' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | my $pipe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | if ($opts{server}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | my $cwd = quote_cmdline(getcwd()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | open($pipe, '-|', 'ssh', $opts{server}, <<"SCRIPT".quote_cmdline(@command)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | if [ -f ~/.bash_profile ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | . ~/.bash_profile 2>/dev/null 1>&2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | elif [ -f ~/.profile ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | . ~/.profile 2>/dev/null 1>&2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | cd $cwd; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | SCRIPT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | || die "Failed to start jtred on host $opts{server} over ssh: $!" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | open($pipe, '-|',@command) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | || die "Failed to start jtred: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | apply_filter($pipe, $filter_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | close($pipe); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | unlink $filter_file if -f $filter_file and !$opts{'keep-tmp-files'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $filter_file and not $opts{"keep-tmp-files"}
MC/DC0%0/2
-f $filter_file and not $opts{"keep-tmp-files"}
-f $filter_file
not $opts{"keep-tmp-files"}
Truth table0%0/3
A and not(B)
A= -f $filter_fileB= not $opts{"keep-tmp-files"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | unlink $filelist if $filelist and !$opts{'keep-tmp-files'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$filelist and not $opts{"keep-tmp-files"}
MC/DC0%0/2
$filelist and not $opts{"keep-tmp-files"}
$filelist
not $opts{"keep-tmp-files"}
Truth table0%0/3
A and not(B)
A= $filelistB= not $opts{"keep-tmp-files"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | sub btred_search { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | my @args = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
btred_search: not called CC=15 SCAR=54.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | my $command = $opts{command} || 'btred'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts{'command'} || 'btred'
MC/DC0%0/1
$opts{'command'} || 'btred'
$opts{'command'}
Truth table0%0/2
A
A= $opts{'command'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | my $jobname="pmltq_btred_$$"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | if ($opts{server}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $jobname.="-".$ENV{HOSTNAME}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | my $shared_dir=File::Spec->rel2abs($opts{'shared-dir'} || '.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts{'shared-dir'} || '.'
MC/DC0%0/1
$opts{'shared-dir'} || '.'
$opts{'shared-dir'}
Truth table0%0/2
A
A= $opts{'shared-dir'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | my $filter_file="$shared_dir/$jobname.pl"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | my @script_flags=('--filter-code-out', $filter_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | foreach (qw(query query-id query-file query-pml-file filters netgraph-query)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | push @script_flags, '--'.$_, (/file/ ? File::Spec->rel2abs($opts{$_}) : $opts{$_}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | if defined($opts{$_}) and length($opts{$_}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $opts{$_} and length $opts{$_}
MC/DC0%0/2
defined $opts{$_} and length $opts{$_}
defined $opts{$_}
length $opts{$_}
Truth table0%0/3
A and B
A= defined $opts{$_}B= length $opts{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | for (qw(node-types relations)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | if ($opts{$_}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | push @script_flags, '--info', $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | $command .= ' '.quote_cmdline( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | ($opts{quiet} ? '-Q' : '-q'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | '-I', File::Spec->catfile($extension_dir,qw(contrib pmltq pmltq.ntred)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | '-o', '--apply-filters', @script_flags, '--', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | ($opts{filelist} ? ('-l', $opts{filelist}) : @args), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | if ($opts{server}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | my $cwd = quote_cmdline(getcwd()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | system('ssh', $opts{server}, <<"SCRIPT"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | if [ -f ~/.bash_profile ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | . ~/.bash_profile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | elif [ -f ~/.profile ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | . ~/.profile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | cd $cwd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | $command | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | SCRIPT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | print STDERR "$command\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | system($command); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | unlink $filter_file if -f $filter_file and !$opts{'keep-tmp-files'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $filter_file and not $opts{"keep-tmp-files"}
MC/DC0%0/2
-f $filter_file and not $opts{"keep-tmp-files"}
-f $filter_file
not $opts{"keep-tmp-files"}
Truth table0%0/3
A and not(B)
A= -f $filter_fileB= not $opts{"keep-tmp-files"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | sub round { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | ▶ | my ($value, $precision) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
round: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | my $rounding = ($value >= 0 ? 0.5 : -0.5); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | my $decimalscale = 10**int($precision || 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$precision || 0
MC/DC0%0/1
$precision || 0
$precision
Truth table0%0/2
A
A= $precision
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | my $scaledvalue = int($value * $decimalscale + $rounding); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | return $scaledvalue / $decimalscale; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | sub trunc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | my ($self, $num, $digits) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trunc: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | $digits = int $digits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | my $decimalscale = 10**abs($digits); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | if ($digits >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | return int($num * $decimalscale) / $decimalscale; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | return int($num / $decimalscale) * $decimalscale; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | sub apply_filter { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | my ($input, $filter_file)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_filter: not called CC=15 SCAR=53.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | my $filters; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | my $filter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | my $first = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 1 | ▶ | use POSIX qw(ceil floor); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | if ($opts{'no-filters'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | print while (<$input>); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | my $output_filter = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | ▶ | init => sub { }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | process_row => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | my ($self,$row)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | print(join("\t",@$row)."\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | ▶ | finish => sub { } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | while (<$input>) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | unless ($filter) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | if (-f $filter_file and -s $filter_file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $filter_file and -s $filter_file
MC/DC0%0/2
-f $filter_file and -s $filter_file
-f $filter_file
-s $filter_file
Truth table0%0/3
A and B
A= -f $filter_fileB= -s $filter_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | open my $fh, "<", $filter_file or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | die "Cannot open $filter_file: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | my $filter_code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | $filter_code = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | eval "use utf8;\n".$filter_code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | print STDERR $filter_code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | print STDERR "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | die "Running filter $filter_file failed!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | my @filters = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | my @local_filters = map eval, @{$_->{local_filters_code}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | my $sub = eval($_->{code}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | $sub | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | } @$filters; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | # connect filters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | my $prev; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | for my $filter (@filters) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | $prev->{output}=$filter if $prev; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | $prev = $filter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | if ($prev) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | $prev->{output} = $output_filter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | $filter = $filters[0] || die "First filter is empty!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$filters[0] || die('First filter is empty!')
MC/DC0%0/1
$filters[0] || die('First filter is empty!')
$filters[0]
Truth table0%0/2
A
A= $filters[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | $filter->{init}->($filter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | $filter = $output_filter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | $filter->{process_row}->($filter,[split /\t/,$_]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | ▶ | $filter->{finish}->($filter) if $filter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||