| 1 | package File::Gettext::Storage; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use File::Basename qw( basename ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use File::DataClass::Constants qw( EXCEPTION_CLASS FALSE NUL TRUE ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use File::DataClass::Functions qw( is_stale merge_file_data throw ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use File::DataClass::Types qw( Object ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use File::Gettext; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Unexpected::Functions qw( NothingUpdated Unspecified ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | has 'gettext' => is => 'lazy', isa => Object, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | builder => sub { File::Gettext->new( builder => $_[ 0 ]->schema ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_gettext: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | has 'schema' => is => 'ro', isa => Object, required => TRUE, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | handles => [ qw( cache language ) ], weak_ref => TRUE; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | has 'storage' => is => 'ro', isa => Object, required => TRUE, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | handles => [ qw( extn meta_pack meta_unpack | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | read_file txn_do validate_params ) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # Private functions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | ▶ | my $_get_attributes = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=18.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | my ($condition, $source) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 10 | ▶ | return grep { not m{ \A _ }msx | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition44%4/9
!/ \A _ /msx && $_ ne 'id' && $_ ne 'name' && &$condition($_)
not / \A _ /msx and $_ ne "id" and $_ ne "name"
not / \A _ /msx and $_ ne "id"
MC/DC25%1/4
!/ \A _ /msx && $_ ne 'id' && $_ ne 'name' && &$condition($_)
not / \A _ /msx
$_ ne "id"
$_ ne "name"
&$condition($_)
Truth table40%2/5
not(A) and B and C && D
A= not / \A _ /msxB= $_ ne "id"C= $_ ne "name"D= &$condition($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | and $_ ne 'id' and $_ ne 'name' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 5 | ▶ | and $condition->( $_ ) } @{ $source->attributes || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$source->attributes || []
MC/DC0%0/1
$source->attributes || []
$source->attributes
Truth table50%1/2
A
A= $source->attributes
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # Private methods | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 16 | ▶ | my $_extn = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 16 | ▶ | my ($self, $path) = @_; $path //= NUL; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$path //= ""
MC/DC0%0/1
$path //= ""
$path
Truth table50%1/2
A
A= $path
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 16 | ▶ | my $extn = (split m{ \. }mx, ("${path}" // NUL))[ -1 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
"$path" // ""
MC/DC0%0/1
"$path" // ""
"$path"
Truth table50%1/2
A
A= "$path"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 16 | ▶ | return $extn ? ".${extn}" : $self->extn; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 10 | ▶ | my $_gettext = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 10 | ▶ | my ($self, $path) = @_; $path or throw Unspecified, [ 'path name' ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 10 | my $gettext = $self->gettext; my $extn = $self->$_extn( $path ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 10 | $gettext->set_path( $self->language, basename( "${path}", $extn ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 10 | return $gettext; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | ▶ | my $_create_or_update = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | my ($self, $path, $result, $updating) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 4 | ▶ | my $source = $result->can( 'result_source' ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ? $result->result_source : $result->_resultset->source; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 4 | ▶ | my $condition = sub { not $source->language_dependent->{ $_[ 0 ] } }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | my $updated = $self->storage->create_or_update | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ( $path, $result, $updating, $condition ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | my $rs = $self->$_gettext( $path )->resultset; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | my $element = $source->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | ▶ | $condition = sub { $source->language_dependent->{ $_[ 0 ] } }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | for my $attr_name ($_get_attributes->( $condition, $source )) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | ▶ | my $msgstr = $result->$attr_name() or next; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | my $attrs = { msgctxt => "${element}.${attr_name}", | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | msgid => $result->name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | msgstr => [ $msgstr ], }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 3 | $attrs->{name} = $rs->storage->make_key( $attrs ); my $name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 3 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 3 | ▶ | $name = $updating ? $rs->create_or_update( $attrs ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | : $rs->create( $attrs ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | catch { $_->class ne NothingUpdated and throw $_ }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | ▶ | $updated ||= $name ? TRUE : FALSE; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$updated ||= $name ? 1 : 0
MC/DC0%0/2
$updated ||= $name ? 1 : 0
$updated
$name ? 1 : 0
Truth table33%1/3
A ||= B
A= $updatedB= $name ? 1 : 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | ▶ | $updating and not $updated and throw NothingUpdated, level => 4; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$updating and not $updated
MC/DC0%0/2
$updating and not $updated
$updating
not $updated
Truth table66%2/3
A and not(B)
A= $updatingB= not $updated
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | ▶ | $updated and $path->touch; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | return $updated; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 6 | ▶ | my $_get_key_and_newest = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=13 SCAR=26.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 6 | my ($self, $paths) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 6 | my $gettext = $self->gettext; my $key; my $newest = 0; my $valid = TRUE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 6 | for my $path (grep { length } map { "${_}" } @{ $paths }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 6 | ▶ | $key .= $key ? "~${path}" : $path; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 6 | my $mtime = $self->cache->get_mtime( $path ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 6 | ▶ | if ($mtime) { $mtime > $newest and $newest = $mtime } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 4 | else { $valid = FALSE } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 6 | my $file = basename( "${path}", $self->$_extn( $path ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 6 | my $lang_file = $gettext->object_file( $self->language, $file ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 6 | ▶ | if (defined ($mtime = $self->cache->get_mtime( "${lang_file}" ))) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | ▶ | if ($mtime) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | ▶ | $key .= $key ? "~${lang_file}" : "${lang_file}"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | ▶ | $mtime > $newest and $newest = $mtime; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 4 | ▶ | if ($lang_file->exists and $lang_file->is_file) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$lang_file->exists and $lang_file->is_file
MC/DC0%0/2
$lang_file->exists and $lang_file->is_file
$lang_file->exists
$lang_file->is_file
Truth table33%1/3
A and B
A= $lang_file->existsB= $lang_file->is_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | ▶ | $key .= $key ? "~${lang_file}" : "${lang_file}"; $valid = FALSE; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | else { $self->cache->set_mtime( "${lang_file}", 0 ) } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 6 | ▶ | return ($key, $valid ? $newest : undef); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | ▶ | my $_load_gettext = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 4 | my ($self, $data, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | ▶ | my $gettext = $self->$_gettext( $path ); $gettext->path->is_file or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 4 | my $gettext_data = $gettext->load->{ $gettext->source_name }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 4 | for my $key (keys %{ $gettext_data }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | my ($msgctxt, $msgid) = $gettext->storage->decompose_key( $key ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 3 | my ($element, $attr_name) = split m{ [\.] }msx, $msgctxt, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 3 | ▶ | ($element and $attr_name and $msgid) or next; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$element and $attr_name and $msgid
$element and $attr_name
MC/DC0%0/3
$element and $attr_name and $msgid
$element
$attr_name
$msgid
Truth table25%1/4
A and B and C
A= $elementB= $attr_nameC= $msgid
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | $data->{ $element }->{ $msgid }->{ $attr_name } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 3 | = $gettext_data->{ $key }->{msgstr}->[ 0 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | return $gettext->path->stat->{mtime}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # Public methods | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | my ($self, $path, $result) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | ▶ | my $source = $result->can( 'result_source' ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | ? $result->result_source : $result->_resultset->source; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | ▶ | my $condition = sub { $source->language_dependent->{ $_[ 0 ] } }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | my $deleted = $self->storage->delete( $path, $result ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | my $rs = $self->$_gettext( $path )->resultset; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | my $element = $source->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 2 | for my $attr_name ($_get_attributes->( $condition, $source )) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | my $attrs = { msgctxt => "${element}.${attr_name}", | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | msgid => $result->name, }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | my $name = $rs->storage->make_key( $attrs ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | $name = $rs->delete( { name => $name, optional => TRUE } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | ▶ | $deleted ||= $name ? TRUE : FALSE; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$deleted ||= $name ? 1 : 0
MC/DC0%0/2
$deleted ||= $name ? 1 : 0
$deleted
$name ? 1 : 0
Truth table33%1/3
A ||= B
A= $deletedB= $name ? 1 : 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | return $deleted; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | ▶ | sub dump { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | my ($self, $path, $data) = @_; $self->validate_params( $path, TRUE ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | my $gettext = $self->$_gettext( $path ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | my $gettext_data = $gettext->path->exists ? $gettext->load : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | for my $source (values %{ $self->schema->source_registrations }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | my $element = $source->name; my $element_ref = $data->{ $element }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | for my $msgid (keys %{ $element_ref }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 8 | ▶ | for my $attr_name (keys %{ $source->language_dependent || {} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$source->language_dependent || {}
MC/DC0%0/1
$source->language_dependent || {}
$source->language_dependent
Truth table50%1/2
A
A= $source->language_dependent
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 8 | ▶ | my $msgstr = delete $element_ref->{ $msgid }->{ $attr_name } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | my $attrs = { msgctxt => "${element}.${attr_name}", | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | msgid => $msgid, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | msgstr => [ $msgstr ] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | my $key = $gettext->storage->make_key( $attrs ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | $gettext_data->{ $gettext->source_name }->{ $key } = $attrs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | $gettext->dump( { data => $gettext_data } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | return $self->storage->dump( $path, $data ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 3 | ▶ | sub insert { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 3 | return $_[ 0 ]->$_create_or_update( $_[ 1 ], $_[ 2 ], FALSE ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 6 | ▶ | sub load { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 6 | ▶ | my ($self, @paths) = @_; $paths[ 0 ] or return {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 6 | my ($key, $newest) = $self->$_get_key_and_newest( \@paths ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 6 | my ($data, $meta) = $self->cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 6 | my $cache_mtime = $self->meta_unpack( $meta ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 6 | ▶ | not is_stale $data, $cache_mtime, $newest and return $data; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 4 | $data = {}; $newest = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 4 | for my $path (@paths) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 4 | my ($red, $path_mtime) = $self->read_file( $path, FALSE ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 4 | merge_file_data $data, $red; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 4 | ▶ | $path_mtime > $newest and $newest = $path_mtime; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 4 | $path_mtime = $self->$_load_gettext( $data, $path ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 4 | ▶ | $path_mtime and $path_mtime > $newest and $newest = $path_mtime; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$path_mtime and $path_mtime > $newest
MC/DC0%0/2
$path_mtime and $path_mtime > $newest
$path_mtime
$path_mtime > $newest
Truth table33%1/3
A and B
A= $path_mtimeB= $path_mtime > $newest
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 4 | $self->cache->set( $key, $data, $self->meta_pack( $newest ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 4 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 5 | ▶ | sub select { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 5 | my ($self, $path, $element) = @_; $self->validate_params( $path, $element ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 5 | my $data = $self->load( $path ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 5 | ▶ | return exists $data->{ $element } ? $data->{ $element } : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | return $_[ 0 ]->$_create_or_update( $_[ 1 ], $_[ 2 ], TRUE ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||