| 1 | package Treex::PML::Backend::NTRED; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Treex::PML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Storable qw(nfreeze thaw); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Treex::PML::IO; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | $VERSION='2.29'; # version template | |||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use vars qw($ntred); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | $ntred='ntred'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub test { | ||||||||||||||||||||||||||
|
Subroutine
test: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 0 | my ($filename,$encoding)=@_; | |||||||||||||||||||||||||||
| 20 | 0 | return $filename=~m(^ntred://); | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub open_backend { | ||||||||||||||||||||||||||
|
Subroutine
open_backend: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 0 | my ($filename, $mode, $encoding)=@_; | |||||||||||||||||||||||||||
| 25 | 0 | my $fh = undef; | |||||||||||||||||||||||||||
| 26 | 0 | my $cmd = ""; | |||||||||||||||||||||||||||
| 27 | 0 | ▶ | return unless $filename=~m(^ntred://(.*)$); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | $filename=$1; | |||||||||||||||||||||||||||
| 29 | 0 | $filename=~s/@/##/; | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ($filename) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ($mode eq 'w') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | open($fh,'|-',$ntred, '-Q', '--upload-file', $filename) || die "Failed to start NTrEd Client '$ntred': $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | } else { | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | open($fh,'-|',$ntred, '-Q', '--dump-files', $filename) || die "Failed NTrEd Client '$ntred': $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 0 | return Treex::PML::IO::set_encoding($fh,$encoding); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub close_backend { | ||||||||||||||||||||||||||
|
Subroutine
close_backend: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 0 | my ($fh)=@_; | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | return $fh && $fh->close(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$fh && $fh->close
MC/DC0%0/2
$fh && $fh->close
$fh
$fh->close
Truth table0%0/3
A && B
A= $fhB= $fh->close
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub read { | ||||||||||||||||||||||||||
|
Subroutine
read: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 0 | my ($fd,$fs)=@_; | |||||||||||||||||||||||||||
| 47 | 0 | my $data = do{{ local $/; <$fd>}}; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | unless (defined $data and length $data) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $data and length $data
MC/DC0%0/2
defined $data and length $data
defined $data
length $data
Truth table0%0/3
A and B
A= defined $dataB= length $data
| |||||||||||||||||||||||||||||
| 49 | 0 | die "NTrEd Client returned no data\n"; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 0 | my $fs_files = Storable::thaw(decode_base64($data)); | |||||||||||||||||||||||||||
| 52 | 0 | undef $data; | |||||||||||||||||||||||||||
| 53 | 0 | my $restore = $fs_files->[0]; | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | if (ref($restore)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | my $api_version = $restore->[6]; | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ($api_version ne $Treex::PML::API_VERSION) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | warn "Warning: the binary content obtained via Treex::PML::Backend::NTRED from ".$fs->filename." is a dump of structures created by possibly incompatible Treex::PML API version $api_version (the current Treex::PML API version is $Treex::PML::API_VERSION)\n"; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 0 | $fs->changeFS($restore->[0]); | |||||||||||||||||||||||||||
| 60 | 0 | $fs->changeTrees(@{$restore->[1]}); | |||||||||||||||||||||||||||
| 61 | 0 | $fs->changeTail(@{$restore->[2]}); | |||||||||||||||||||||||||||
| 62 | 0 | $fs->[13]=$restore->[3]; # metaData | |||||||||||||||||||||||||||
| 63 | 0 | $fs->changePatterns(@{$restore->[4]}); | |||||||||||||||||||||||||||
| 64 | 0 | $fs->changeHint($restore->[5]); | |||||||||||||||||||||||||||
| 65 | 0 | $fs->FS->renew_specials(); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub write { | ||||||||||||||||||||||||||
|
Subroutine
write: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 72 | 0 | my ($fh,$fsfile)=@_; | |||||||||||||||||||||||||||
| 73 | 0 | my $dump= [$fsfile->FS, | |||||||||||||||||||||||||||
| 74 | $fsfile->treeList, | ||||||||||||||||||||||||||||
| 75 | [$fsfile->tail], | ||||||||||||||||||||||||||||
| 76 | $fsfile->[13], # metaData | ||||||||||||||||||||||||||||
| 77 | [$fsfile->patterns], | ||||||||||||||||||||||||||||
| 78 | $fsfile->hint, | ||||||||||||||||||||||||||||
| 79 | $Treex::PML::API_VERSION | ||||||||||||||||||||||||||||
| 80 | # CAUTION: when adding to this list, don't forget to do the same | ||||||||||||||||||||||||||||
| 81 | # in btred DUMP request handler | ||||||||||||||||||||||||||||
| 82 | ]; | ||||||||||||||||||||||||||||
| 83 | 0 | eval { | |||||||||||||||||||||||||||
| 84 | 0 | print $fh (encode_base64(Storable::nfreeze([$dump]))); | |||||||||||||||||||||||||||
| 85 | 0 | print $fh ("\n"); | |||||||||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | 1; | |||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||