| 1 | package Treex::PML::Backend::CSTS; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | $VERSION='2.29'; # version template | |||||||||||||||||||||||||||
| 6 | } | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Treex::PML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Treex::PML::IO qw(set_encoding); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Treex::PML::Backend::CSTS::Csts2fs; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Treex::PML::Backend::CSTS::Fs2csts; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Fcntl qw(SEEK_SET); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use File::ShareDir; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use vars qw($sgmls $sgmlsopts $doctype $csts_encoding); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | sub default_settings { | ||||||||||||||||||||||||||
|
Subroutine
default_settings: called CC=9 SCAR=26.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | $sgmls = "nsgmls" unless $sgmls; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | $sgmlsopts = "-i preserve.gen.entities" unless $sgmlsopts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | unless ($doctype and -f $doctype) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$doctype and -f $doctype
MC/DC0%0/2
$doctype and -f $doctype
$doctype
-f $doctype
Truth table33%1/3
A and B
A= $doctypeB= -f $doctype
| |||||||||||||||||||||||||||||
| 21 | 2 | $doctype = eval { File::ShareDir::module_file(__PACKAGE__,'csts.doctype') }; | |||||||||||||||||||||||||||
| 22 | 2 | ▶ | unless (defined($doctype) and -f $doctype) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $doctype and -f $doctype
MC/DC0%0/2
defined $doctype and -f $doctype
defined $doctype
-f $doctype
Truth table33%1/3
A and B
A= defined $doctypeB= -f $doctype
| |||||||||||||||||||||||||||||
| 23 | 2 | $doctype = Treex::PML::IO::CallerDir(File::Spec->catfile(qw(CSTS share csts.doctype))); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 2 | ▶ | unless (-f $doctype) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | $doctype = Treex::PML::FindInResources("csts.doctype"); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 2 | ▶ | $sgmls_command='%s %o %d %f' unless $sgmls_command; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 2 | $csts_encoding = 'iso-8859-2'; # this the encoding of CSTS by definition | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2 | my %stderr_pool; | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub open_backend { | ||||||||||||||||||||||||||
|
Subroutine
open_backend: not called CC=12 SCAR=48.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 0 | my ($filename, $mode, $encoding)=@_; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ($mode eq 'w') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 37 | 0 | return Treex::PML::IO::open_backend($filename,$mode,$csts_encoding); | |||||||||||||||||||||||||||
| 38 | } elsif ($mode eq 'r') { | ||||||||||||||||||||||||||||
| 39 | 0 | my $fh = undef; | |||||||||||||||||||||||||||
| 40 | 0 | my $cmd = $sgmls_command; | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | $doctype = Treex::PML::FindInResources($doctype) unless -f $doctype; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | print STDERR "$cmd\n" if $Treex::PML::Debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | $cmd=~s/\%s/$sgmls/g; | |||||||||||||||||||||||||||
| 44 | 0 | $cmd=~s/\%o/$sgmlsopts/g; | |||||||||||||||||||||||||||
| 45 | 0 | $cmd=~s/\%d/$doctype/g; | |||||||||||||||||||||||||||
| 46 | 0 | $cmd=~s/\%f/-/g; | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | warn "[r $cmd]\n" if $Treex::PML::Debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | no integer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||
| 51 | 0 | my $err = File::Temp->new(UNLINK => 1); | |||||||||||||||||||||||||||
| 52 | 0 | $err->autoflush(1); | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | open my $olderr, ">&", \*STDERR or die "Can't dup STDERR: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | open STDERR, ">&", $err or die "Can't dup temporary filehandle as STDERR: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | eval { | |||||||||||||||||||||||||||
| 56 | 0 | $fh = set_encoding(Treex::PML::IO::open_pipe($filename,'r',$cmd),$csts_encoding); | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | binmode $fh,':crlf' if $fh and $^O eq 'MSWin32'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$fh and $^O eq "MSWin32"
MC/DC0%0/2
$fh and $^O eq "MSWin32"
$fh
$^O eq "MSWin32"
Truth table0%0/3
A and B
A= $fhB= $^O eq "MSWin32"
| |||||||||||||||||||||||||||||
| 58 | }; | ||||||||||||||||||||||||||||
| 59 | 0 | close(STDERR); | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | open STDERR, ">&", $olderr or die "Can't dup old STDERR: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | close $err; | |||||||||||||||||||||||||||
| 63 | 0 | die $@; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 0 | $stderr_pool{$fh} = $err; | |||||||||||||||||||||||||||
| 66 | 0 | return $fh; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } else { | ||||||||||||||||||||||||||||
| 69 | 0 | die "unknown mode $mode\n"; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub close_backend { | ||||||||||||||||||||||||||
|
Subroutine
close_backend: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | 0 | my ($fh)=@_; | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | if (exists $stderr_pool{$fh}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | my $err = delete $stderr_pool{$fh}; | |||||||||||||||||||||||||||
| 77 | 0 | seek($err,0,SEEK_SET); | |||||||||||||||||||||||||||
| 78 | 0 | local $/; | |||||||||||||||||||||||||||
| 79 | 0 | my $warnings = <$err>; | |||||||||||||||||||||||||||
| 80 | 0 | close($err); | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | if (defined $warnings and length $warnings) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $warnings and length $warnings
MC/DC0%0/2
defined $warnings and length $warnings
defined $warnings
length $warnings
Truth table0%0/3
A and B
A= defined $warningsB= length $warnings
| |||||||||||||||||||||||||||||
| 82 | 0 | warn $warnings; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | unless (Treex::PML::IO::close_backend($fh)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | die "$sgmls ended with error code $?\n"; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 0 | return 1; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub read { | ||||||||||||||||||||||||||
|
Subroutine
read: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 92 | 0 | Treex::PML::Backend::CSTS::Csts2fs::read(@_); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub write { | ||||||||||||||||||||||||||
|
Subroutine
write: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 96 | 0 | Treex::PML::Backend::CSTS::Fs2csts::write(@_); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 1 | ▶ | sub test_nsgmls { | ||||||||||||||||||||||||||
|
Subroutine
test_nsgmls: called CC=9 SCAR=31.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 100 | 1 | ▶ | return 1 if (-x $sgmls); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 1 | ▶ | foreach (split(($^O eq 'MSWin32' ? ';' : ':'),$ENV{PATH})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 10 | ▶ | if (-x "$_".($^O eq 'MSWin32' ? "\\" : "/")."$sgmls") { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | unless (-f $doctype) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | warn("CSTS doctype not found: $doctype\n") if $Treex::PML::Debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | return 0; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 0 | return 1; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | 1 | ▶ | warn("nsgmls not found at $sgmls\n") if $Treex::PML::Debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 1 | return 0; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub test { | ||||||||||||||||||||||||||
|
Subroutine
test: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | 0 | my ($f,$encoding)=@_; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | return 0 unless test_nsgmls(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if (ref($f)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | my $line=$f->getline(); | |||||||||||||||||||||||||||
| 120 | 0 | return $line=~/^\s*<csts[ >]|^<!DOCTYPE csts/; | |||||||||||||||||||||||||||
| 121 | } else { | ||||||||||||||||||||||||||||
| 122 | 0 | my $fh = Treex::PML::IO::open_backend($f,"r"); | |||||||||||||||||||||||||||
| 123 | 0 | ▶ | my $test = $fh && test($fh); | ||||||||||||||||||||||||||
|
Condition0%0/3
$fh && test($fh)
MC/DC0%0/2
$fh && test($fh)
$fh
test($fh)
Truth table0%0/3
A && B
A= $fhB= test($fh)
| |||||||||||||||||||||||||||||
| 124 | 0 | Treex::PML::IO::close_backend($fh); | |||||||||||||||||||||||||||
| 125 | 0 | return $test; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 130 | 2 | default_settings(); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 2 | 1; | |||||||||||||||||||||||||||
| 134 | __END__ | ||||||||||||||||||||||||||||