| 1 | package Treex::PML::Backend::PML; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use Treex::PML; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use Treex::PML::IO qw(close_backend); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use File::ShareDir; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | $VERSION='2.29'; # version template | |||||||||||||||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | use Treex::PML::Instance qw( :all :diagnostics $DEBUG ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 9 | ▶ | use constant EMPTY => q{}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 9 | ▶ | use vars qw($config $config_file $allow_no_trees $config_inc_file $TRANSFORM @EXPORT_OK); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 9 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 9 | $TRANSFORM=0; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 9 | @EXPORT_OK = qw(open_backend close_backend test read write); | |||||||||||||||||||||||||||||||||||||||||
| 28 | 9 | $config = undef; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 9 | $config_file = 'pmlbackend_conf.xml'; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 9 | $config_inc_file = 'pmlbackend_conf.inc'; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 9 | $allow_no_trees = 0; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | ▶ | sub configure { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
configure: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 9 | my @resource_path = Treex::PML::ResourcePaths(); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 9 | my $ret = eval { _configure() }; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 9 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 9 | Treex::PML::SetResourcePaths(@resource_path); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 9 | ▶ | die $err if ($err); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 9 | $config = $ret; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 9 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 9 | ▶ | sub _configure { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_configure: called CC=16 SCAR=42.7
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 9 | my $cfg; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 9 | my $schema_dir = eval { File::ShareDir::module_dir('Treex::PML') }; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | ▶ | unless (defined($schema_dir) and length($schema_dir) and -f File::Spec->catfile($schema_dir,'pmlbackend_conf_schema.xml')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $schema_dir and length $schema_dir and -f "File::Spec"->catfile($schema_dir, "pmlbackend_conf_schema.xml")
defined $schema_dir and length $schema_dir
MC/DC0%0/3
defined $schema_dir and length $schema_dir and -f "File::Spec"->catfile($schema_dir, "pmlbackend_conf_schema.xml")
defined $schema_dir
length $schema_dir
-f "File::Spec"->catfile($schema_dir, "pmlbackend_conf_schema.xml")
Truth table25%1/4
A and B and C
A= defined $schema_dirB= length $schema_dirC= -f "File::Spec"->catfile($schema_dir, "pmlbackend_conf_schema.xml")
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | $schema_dir = Treex::PML::IO::CallerDir(File::Spec->catfile(qw(.. share))); | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 9 | ▶ | Treex::PML::AddResourcePath($schema_dir) if defined($schema_dir) and length($schema_dir); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $schema_dir and length $schema_dir
MC/DC0%0/2
defined $schema_dir and length $schema_dir
defined $schema_dir
length $schema_dir
Truth table33%1/3
A and B
A= defined $schema_dirB= length $schema_dir
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 9 | my $file = Treex::PML::FindInResources($config_file,{strict=>1}); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 9 | ▶ | if ($file and -f $file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$file and -f $file
MC/DC0%0/2
$file and -f $file
$file
-f $file
Truth table33%1/3
A and B
A= $fileB= -f $file
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | _debug("config file: $file"); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $cfg = Treex::PML::Instance->load({filename => $file}); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 9 | _debug("using empty pmlbackend_conf.xml file"); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 9 | $cfg = Treex::PML::Instance->load({string=><<'_CONFIG_',filename => $file}); | |||||||||||||||||||||||||||||||||||||||||
| 58 | <?xml version="1.0" encoding="UTF-8"?> | ||||||||||||||||||||||||||||||||||||||||||
| 59 | <pmlbackend xmlns="http://ufal.mff.cuni.cz/pdt/pml/"> | ||||||||||||||||||||||||||||||||||||||||||
| 60 | <head><schema href="pmlbackend_conf_schema.xml"/></head> | ||||||||||||||||||||||||||||||||||||||||||
| 61 | <transform_map/> | ||||||||||||||||||||||||||||||||||||||||||
| 62 | </pmlbackend> | ||||||||||||||||||||||||||||||||||||||||||
| 63 | _CONFIG_ | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 9 | ▶ | if ($cfg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 9 | my @config_files = Treex::PML::FindInResources($config_inc_file,{all=>1}); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 9 | ▶ | my $T = $cfg->get_root->{transform_map} ||= Treex::PML::Factory->createSeq(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$cfg->get_root->{"transform_map"} ||= "Treex::PML::Factory"->createSeq
MC/DC0%0/2
$cfg->get_root->{"transform_map"} ||= "Treex::PML::Factory"->createSeq
$cfg->get_root->{"transform_map"}
"Treex::PML::Factory"->createSeq
Truth table33%1/3
A ||= B
A= $cfg->get_root->{"transform_map"}B= "Treex::PML::Factory"->createSeq
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 9 | for my $file (reverse @config_files) { | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | _debug("config include file: $file"); | |||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $c = Treex::PML::Instance->load({filename => $file}); | |||||||||||||||||||||||||||||||||||||||||
| 72 | # merge | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $t = $c->get_root->{transform_map}; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($t) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | for my $transform (reverse $t->elements) { | |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $copy = Treex::PML::CloneValue($transform); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $T->unshift_element_obj($copy); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if (ref($copy->value) and $copy->value->{id}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $copy->value and $copy->value->{"id"}
MC/DC0%0/2
ref $copy->value and $copy->value->{"id"}
ref $copy->value
$copy->value->{"id"}
Truth table0%0/3
A and B
A= ref $copy->valueB= $copy->value->{"id"}
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $cfg->hash_id($copy->value->{id}, $copy->value, 1); | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | warn $@ if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 9 | return $cfg; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | ################### | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 32 | ▶ | sub open_backend { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open_backend: called CC=3 SCAR=13.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 32 | my ($filename, $mode, $encoding)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 32 | ▶ | my $fh = Treex::PML::IO::open_backend($filename,$mode) # discard encoding | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
Treex::PML::IO::open_backend($filename, $mode) || die("Cannot open $filename for " . ($mode eq 'w' ? 'writing' : 'reading') . ": $!")
MC/DC0%0/1
Treex::PML::IO::open_backend($filename, $mode) || die("Cannot open $filename for " . ($mode eq 'w' ? 'writing' : 'reading') . ": $!")
Treex::PML::IO::open_backend($filename, $mode)
Truth table50%1/2
A
A= Treex::PML::IO::open_backend($filename, $mode)
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | || die "Cannot open $filename for ".($mode eq 'w' ? 'writing' : 'reading').": $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 32 | return $fh; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 22 | ▶ | sub read ($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=5 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 22 | my ($input, $fsfile)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 22 | ▶ | return unless ref($fsfile); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 22 | my $ctxt = Treex::PML::Instance->load({fh => $input, filename => $fsfile->filename, config => $config }); | |||||||||||||||||||||||||||||||||||||||||
| 105 | 22 | $ctxt->convert_to_fsfile( $fsfile ); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 22 | my $status = $ctxt->get_status; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 22 | ▶ | if ($status and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$status and not $Treex::PML::Backend::PML::allow_no_trees || defined $ctxt->get_trees
$Treex::PML::Backend::PML::allow_no_trees || defined $ctxt->get_trees
MC/DC0%0/3
$status and not $Treex::PML::Backend::PML::allow_no_trees || defined $ctxt->get_trees
$status
$Treex::PML::Backend::PML::allow_no_trees
defined $ctxt->get_trees
Truth table25%1/4
A and not(B || C)
A= $statusB= $Treex::PML::Backend::PML::allow_no_treesC= defined $ctxt->get_trees
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | !($allow_no_trees or defined($ctxt->get_trees))) { | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | _die("No trees found in the Treex::PML::Instance!"); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 22 | return $status | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 10 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 10 | my ($fh,$fsfile)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 10 | my $ctxt = Treex::PML::Instance->convert_from_fsfile( $fsfile ); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 10 | $ctxt->save({ fh => $fh, config => $config }); | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 44 | ▶ | sub test { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test: called CC=30 SCAR=52.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 44 | my ($f,$encoding)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 44 | ▶ | if (ref($f)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 22 | local $_; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 22 | ▶ | if ($TRANSFORM and $config) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Treex::PML::Backend::PML::TRANSFORM and $Treex::PML::Backend::PML::config
MC/DC0%0/2
$Treex::PML::Backend::PML::TRANSFORM and $Treex::PML::Backend::PML::config
$Treex::PML::Backend::PML::TRANSFORM
$Treex::PML::Backend::PML::config
Truth table33%1/3
A and B
A= $Treex::PML::Backend::PML::TRANSFORMB= $Treex::PML::Backend::PML::config
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | 1 while ($_=$f->getline() and !/\S/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_ = $f->getline and not /\S/
MC/DC0%0/2
$_ = $f->getline and not /\S/
$_ = $f->getline
not /\S/
Truth table0%0/3
A and not(B)
A= $_ = $f->getlineB= not /\S/
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | # see <, assume XML | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | return 1 if (defined and /^\s*</); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_ and /^\s*</
MC/DC0%0/2
defined $_ and /^\s*</
defined $_
/^\s*</
Truth table0%0/3
A and B
A= defined $_B= /^\s*</
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # only accept PML instances | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # xmlns:...="..pml-namespace.." must occur in the first tag (on one line) | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | # FIXME: the following code will fail for UTF-16 and UTF-32; | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # proper fix would be to use XML::LibXML::Reader to read the | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # first tag (performance impact on processing many files past | ||||||||||||||||||||||||||||||||||||||||||
| 137 | # PML backend to be measured). Another way to fix for UTF-16 is | ||||||||||||||||||||||||||||||||||||||||||
| 138 | # to check for UTF-16 BOM (both BE and LE) and decode | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # accordingly if present; UTF-32 is rarely used and probably not | ||||||||||||||||||||||||||||||||||||||||||
| 140 | # worth fixing. | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 22 | my ($in_first_tag,$in_pi,$in_comment, $past_BOM); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 22 | ▶ | while ($_=$f->getline()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 49 | ▶ | unless ($past_BOM) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | # ignore UTF-8 BOM | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 22 | s{^\x{ef}\x{bb}\x{bf}}{}; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 22 | $past_BOM = 1; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 49 | ▶ | next if !/\S/; # whitespace | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 44 | ▶ | if ($in_first_tag) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | last if />/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | return 1 if m{\bxmlns(?::[[:alnum:]]+)?=([\'\"])http://ufal.mff.cuni.cz/pdt/pml/\1}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } elsif ($in_pi) { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | next unless s/^.*?\?>//; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $in_pi=0; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } elsif ($in_comment) { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | next unless s/^.*?\-->//; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $in_comment=0; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 44 | s/^(?:\s*<\?.*?\?>|\s*<!--.*?-->)*\s*//; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 44 | ▶ | if (/<\?/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $in_pi=1; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } elsif (/<!--/) { | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $in_comment=1; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } elsif (/^</) { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 22 | ▶ | last if />/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $in_first_tag=1; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | return 1 if m{^[^>]*xmlns(?::[[:alnum:]]+)?=([\'\"])http://ufal.mff.cuni.cz/pdt/pml/\1}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | } elsif (length) { | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | return 0; # nothing else allowed before the first tag | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 22 | ▶ | return 0 if !$in_first_tag && !(defined($_) and s/^\s*<//); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$in_first_tag or defined $_ and s/^\s*<//
defined $_ and s/^\s*<//
MC/DC0%0/3
$in_first_tag or defined $_ and s/^\s*<//
$in_first_tag
defined $_
s/^\s*<//
Truth table25%1/4
A or B and C
A= $in_first_tagB= defined $_C= s/^\s*<//
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 22 | ▶ | return 1 if defined($_) and m{^[^>]*xmlns(?::[[:alnum:]]+)?=([\'\"])http://ufal.mff.cuni.cz/pdt/pml/\1}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_ and m[^[^>]*xmlns(?::[[:alnum:]]+)?=([\'\"])http://ufal.mff.cuni.cz/pdt/pml/\1]
MC/DC0%0/2
defined $_ and m[^[^>]*xmlns(?::[[:alnum:]]+)?=([\'\"])http://ufal.mff.cuni.cz/pdt/pml/\1]
defined $_
m[^[^>]*xmlns(?::[[:alnum:]]+)?=([\'\"])http://ufal.mff.cuni.cz/pdt/pml/\1]
Truth table33%1/3
A and B
A= defined $_B= m[^[^>]*xmlns(?::[[:alnum:]]+)?=([\'\"])http://ufal.mff.cuni.cz/pdt/pml/\1]
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 22 | my $fh = Treex::PML::IO::open_backend($f,"r"); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 22 | ▶ | my $test = $fh && test($fh,$encoding); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$fh && test($fh, $encoding)
MC/DC0%0/2
$fh && test($fh, $encoding)
$fh
test($fh, $encoding)
Truth table33%1/3
A && B
A= $fhB= test($fh, $encoding)
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 22 | Treex::PML::IO::close_backend($fh); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 22 | return $test; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | ###################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | ################### | ||||||||||||||||||||||||||||||||||||||||||
| 190 | # INIT | ||||||||||||||||||||||||||||||||||||||||||
| 191 | ################### | ||||||||||||||||||||||||||||||||||||||||||
| 192 | package Treex::PML::Backend::PML; | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 9 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 194 | 9 | configure(); | |||||||||||||||||||||||||||||||||||||||||
| 195 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 9 | ▶ | Carp::cluck( $@ ) if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | Treex::PML::Backend::PML - I/O backend for PML documents | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | use Treex::PML; | ||||||||||||||||||||||||||||||||||||||||||
| 209 | Treex::PML::AddBackends(qw(PML)) | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | my $document = Treex::PML::Factory->createDocumentFromFile('input.pml'); | ||||||||||||||||||||||||||||||||||||||||||
| 212 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 213 | $document->save(); | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | This module implements a Treex::PML input/output backend which accepts | ||||||||||||||||||||||||||||||||||||||||||
| 218 | reads/writes PML files. See L<Treex::PML::Instance> for details. | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | NOTE: L<Treex::PML> enables this backend by default. | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | Copyright (C) 2006-2010 by Petr Pajas, 2010-2024 Jan Stepanek | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 227 | it under the same terms as Perl itself, either Perl version 5.8.2 or, | ||||||||||||||||||||||||||||||||||||||||||
| 228 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | =cut | ||||||||||||||||||||||||||||||||||||||||||