| 1 | package Treex::PML::Backend::Storable; | ||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Treex::PML; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Storable qw(nstore_fd fd_retrieve); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Treex::PML::IO qw( close_backend); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 1 | $VERSION='2.29'; # version template | |||||||||||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use UNIVERSAL::DOES; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Scalar::Util qw(blessed reftype refaddr); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub test { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
test: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 15 | 0 | my ($f,$encoding)=@_; | |||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | if (ref($f)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 17 | 0 | return $f->getline()=~/^pst0/; | |||||||||||||||||||||||||||||||||||||
| 18 | } else { | ||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my $fh = open_backend($f,"r"); | |||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | my $test = $fh && test($fh,$encoding); | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$fh && test($fh, $encoding)
MC/DC0%0/2
$fh && test($fh, $encoding)
$fh
test($fh, $encoding)
Truth table0%0/3
A && B
A= $fhB= test($fh, $encoding)
| |||||||||||||||||||||||||||||||||||||||
| 21 | 0 | close_backend($fh); | |||||||||||||||||||||||||||||||||||||
| 22 | 0 | return $test; | |||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub open_backend { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
open_backend: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 27 | 0 | Treex::PML::IO::open_backend(@_[0,1]); | |||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub read { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
read: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 31 | 0 | my ($fd,$fs)=@_; | |||||||||||||||||||||||||||||||||||||
| 32 | 0 | binmode($fd); | |||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $restore = fd_retrieve($fd); | |||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $api_version = $restore->[6]; | |||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | unless ($Treex::PML::COMPATIBLE_API_VERSION{ $api_version }) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | $api_version='0.001' unless defined $api_version; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 38 | 0 | warn "Warning: the binary file ".$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"; | |||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | # support for old Fslib-based documents: | ||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if (ref($restore->[0]) eq 'FSFormat' and not defined($Fslib::VERSION)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $restore->[0] eq "FSFormat" and not defined $Fslib::VERSION
MC/DC0%0/2
ref $restore->[0] eq "FSFormat" and not defined $Fslib::VERSION
ref $restore->[0] eq "FSFormat"
not defined $Fslib::VERSION
Truth table0%0/3
A and not(B)
A= ref $restore->[0] eq "FSFormat"B= not defined $Fslib::VERSION
| |||||||||||||||||||||||||||||||||||||||
| 43 | # upgrade to Treex::PML | ||||||||||||||||||||||||||||||||||||||
| 44 | # warn "Warning: Detected Fslib-based file and Fslib is not loaded: upgrading to Treex::PML!\n"; | ||||||||||||||||||||||||||||||||||||||
| 45 | 0 | upgrade_from_fslib($restore); | |||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $fs->changeTail(@{$restore->[2]}); | |||||||||||||||||||||||||||||||||||||
| 49 | 0 | $fs->[13]=$restore->[3]; # metaData | |||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $appData = delete $fs->[13]->{'StorableBackend:savedAppData'}; | |||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($appData) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $fs->changeAppData($_,$appData->{$_}) foreach keys(%$appData); | |||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $fs->changePatterns(@{$restore->[4]}); | |||||||||||||||||||||||||||||||||||||
| 55 | 0 | $fs->changeHint($restore->[5]); | |||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||
| 57 | # place to update some internal stuff if necessary | ||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $schema = $fs->metaData('schema'); | |||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if (ref($schema) and !$schema->{-api_version}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $schema and not $schema->{"-api_version"}
MC/DC0%0/2
ref $schema and not $schema->{"-api_version"}
ref $schema
not $schema->{"-api_version"}
Truth table0%0/3
A and not(B)
A= ref $schemaB= not $schema->{"-api_version"}
| |||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $schema->convert_from_hash(); | |||||||||||||||||||||||||||||||||||||
| 61 | 0 | $schema->post_process(); | |||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $fs->changeFS($restore->[0]); | |||||||||||||||||||||||||||||||||||||
| 64 | 0 | $fs->changeTrees(@{$restore->[1]}); | |||||||||||||||||||||||||||||||||||||
| 65 | 0 | $fs->FS->renew_specials(); | |||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | # $fs->_weakenLinks; | ||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
write: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my ($fd,$fs)=@_; | |||||||||||||||||||||||||||||||||||||
| 73 | 0 | binmode($fd); | |||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $metaData = { %{$fs->[13]} }; | |||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $ref = $fs->appData('ref'); | |||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $metaData->{'StorableBackend:savedAppData'}||={}; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$metaData->{"StorableBackend:savedAppData"} ||= {}
MC/DC0%0/1
$metaData->{"StorableBackend:savedAppData"} ||= {}
$metaData->{"StorableBackend:savedAppData"}
Truth table0%0/2
A
A= $metaData->{"StorableBackend:savedAppData"}
| |||||||||||||||||||||||||||||||||||||||
| 77 | 0 | foreach my $savedAppData ($metaData->{'StorableBackend:savedAppData'}) { | |||||||||||||||||||||||||||||||||||||
| 78 | 0 | $savedAppData->{'id-hash'} = $fs->appData('id-hash'); | |||||||||||||||||||||||||||||||||||||
| 79 | $savedAppData->{'ref'} = { | ||||||||||||||||||||||||||||||||||||||
| 80 | map { | ||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my $val = $ref->{$_}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | UNIVERSAL::DOES::does($val,'Treex::PML::Instance') ? ($_ => $val) : () | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 83 | } keys %$ref | ||||||||||||||||||||||||||||||||||||||
| 84 | } if ref $ref; | ||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||
| 86 | 0 | nstore_fd([$fs->FS, | |||||||||||||||||||||||||||||||||||||
| 87 | $fs->treeList, | ||||||||||||||||||||||||||||||||||||||
| 88 | [$fs->tail], | ||||||||||||||||||||||||||||||||||||||
| 89 | $metaData, | ||||||||||||||||||||||||||||||||||||||
| 90 | [$fs->patterns], | ||||||||||||||||||||||||||||||||||||||
| 91 | $fs->hint, | ||||||||||||||||||||||||||||||||||||||
| 92 | $Treex::PML::API_VERSION | ||||||||||||||||||||||||||||||||||||||
| 93 | ],$fd); | ||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub upgrade_from_fslib { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
upgrade_from_fslib: not called CC=19 SCAR=59.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my @next = @_; | |||||||||||||||||||||||||||||||||||||
| 98 | 0 | my %seen; | |||||||||||||||||||||||||||||||||||||
| 99 | 0 | $seen{refaddr($_)}=1 for @next; | |||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | while (@next) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $object = shift @next; | |||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $ref = ref($object); | |||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | next unless $ref; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my $is = blessed($object); | |||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if (defined $is) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ($is =~ /^Treex/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 107 | } elsif ($is eq 'FSNode') { | ||||||||||||||||||||||||||||||||||||||
| 108 | 0 | bless $object, 'Treex::PML::Node'; | |||||||||||||||||||||||||||||||||||||
| 109 | } elsif ($is eq 'Fslib::Type') { | ||||||||||||||||||||||||||||||||||||||
| 110 | 0 | bless $object, 'Treex::PML::Backend::Storable::CopmpatType'; | |||||||||||||||||||||||||||||||||||||
| 111 | } elsif ($is =~ /^Fslib::(.*)$/) { | ||||||||||||||||||||||||||||||||||||||
| 112 | 0 | bless $object, qq{Treex::PML::$1}; | |||||||||||||||||||||||||||||||||||||
| 113 | } elsif ($is =~ /^PMLSchema(::.*)?$/) { | ||||||||||||||||||||||||||||||||||||||
| 114 | 0 | bless $object, qq{Treex::PML::Schema$1}; | |||||||||||||||||||||||||||||||||||||
| 115 | } elsif ($is eq 'FSFile') { | ||||||||||||||||||||||||||||||||||||||
| 116 | 0 | bless $object, 'Treex::PML::Document'; | |||||||||||||||||||||||||||||||||||||
| 117 | } elsif ($is eq 'FSFormat') { | ||||||||||||||||||||||||||||||||||||||
| 118 | 0 | bless $object, 'Treex::PML::FSFormat'; | |||||||||||||||||||||||||||||||||||||
| 119 | } elsif ($is eq 'PMLInstance') { | ||||||||||||||||||||||||||||||||||||||
| 120 | 0 | bless $object, 'Treex::PML::Instance'; | |||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $ref = reftype($object); | |||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | for (($ref eq 'HASH') ? values(%$object) | ||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||
| 125 | : ($ref eq 'ARRAY') ? @$object | ||||||||||||||||||||||||||||||||||||||
| 126 | : ($ref eq 'SCALAR') ? $$object : ()) { | ||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | my $key = refaddr($_) || next; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
builtin::refaddr($_) || (next)
MC/DC0%0/1
builtin::refaddr($_) || (next)
builtin::refaddr($_)
Truth table0%0/2
A
A= builtin::refaddr($_)
| |||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | push @next, $_ unless ($seen{$key}++); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||
| 133 | package Treex::PML::Backend::Storable::CopmpatType; | ||||||||||||||||||||||||||||||||||||||
| 134 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 136 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 137 | 1 | ▶ | use vars qw($AUTOLOAD); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 138 | # This is handler for obsoleted class 'Fslib::Type' | ||||||||||||||||||||||||||||||||||||||
| 139 | # which has no API-compatible counterpart in Treex::PML. | ||||||||||||||||||||||||||||||||||||||
| 140 | # The object is a pair (ARRAYref) containing PML schema and type declaration. | ||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub schema { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
schema: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||||
| 143 | 0 | return $self->[0]; | |||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub type_decl { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
type_decl: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||||
| 147 | 0 | return $self->[1]; | |||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||
| 149 | # delegate every method to the type | ||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | croak "$self is not an object" unless ref($self); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $name = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||
| 154 | 0 | $name =~ s/.*://; # strip fully-qualified portion | |||||||||||||||||||||||||||||||||||||
| 155 | 0 | return $self->[1]->$name(@_); | |||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||
| 158 | 1 | 1; | |||||||||||||||||||||||||||||||||||||
| 159 | __END__ | ||||||||||||||||||||||||||||||||||||||