/usr/share/perl5/Log/Report/Lexicon/POTcompact.pm is in liblog-report-perl 0.998-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | # Copyrights 2007-2013 by [Mark Overmeer].
# For other contributors see ChangeLog.
# See the manual pages for details on the licensing terms.
# Pod stripped from pm file by OODoc 2.01.
package Log::Report::Lexicon::POTcompact;
use vars '$VERSION';
$VERSION = '0.998';
use base 'Log::Report::Lexicon::Table';
use warnings;
use strict;
use Log::Report 'log-report';
use Log::Report::Util qw/escape_chars unescape_chars/;
sub _unescape($$);
sub _escape($$);
sub read($@)
{ my ($class, $fn, %args) = @_;
my $self = bless {}, $class;
my $charset = $args{charset}
or error __x"charset parameter required for {fn}", fn => $fn;
open my $fh, "<:encoding($charset)", $fn
or fault __x"cannot read in {cs} from file {fn}"
, cs => $charset, fn => $fn;
# Speed!
my ($last, $msgctxt, $msgid, @msgstr);
LINE:
while(my $line = $fh->getline)
{ next if substr($line, 0, 1) eq '#';
if($line =~ m/^\s*$/) # blank line starts new
{ if(@msgstr)
{ $self->{index}{$msgid} = @msgstr > 1 ? [@msgstr] : $msgstr[0];
($msgid, @msgstr) = ();
}
next LINE;
}
if($line =~ s/^msgctxt\s+//)
{ undef $last; # ignore context records
}
elsif($line =~ s/^msgid\s+//)
{ $msgid = _unescape $line, $fn;
$last = \$msgid;
}
elsif($line =~ s/^msgstr\[(\d+)\]\s*//)
{ $last = \($msgstr[$1] = _unescape $line, $fn);
}
elsif($line =~ s/^msgstr\s+//)
{ $msgstr[0] = _unescape $line, $fn;
$last = \$msgstr[0];
}
elsif($last && $line =~ m/^\s*\"/)
{ $$last .= _unescape $line, $fn;
}
}
$self->{index}{$msgid} = (@msgstr > 1 ? \@msgstr : $msgstr[0])
if @msgstr; # don't forget the last
close $fh
or failure __x"failed reading from file {fn}", fn => $fn;
$self->{filename} = $fn;
$self->setupPluralAlgorithm;
$self;
}
sub index() {shift->{index}}
sub filename() {shift->{filename}}
sub msgid($) { $_[0]->{index}{$_[1]} }
# speed!!!
sub msgstr($;$)
{ my $po = $_[0]->{index}{$_[1]}
or return undef;
ref $po # no plurals defined
or return $po;
$po->[$_[0]->{algo}->(defined $_[2] ? $_[2] : 1)]
|| $po->[$_[0]->{algo}->(1)];
}
#
### internal helper routines, shared with ::PO.pm and ::POT.pm
#
sub _unescape($$)
{ unless( $_[0] =~ m/^\s*\"(.*)\"\s*$/ )
{ warning __x"string '{text}' not between quotes at {location}"
, text => $_[0], location => $_[1];
return $_[0];
}
unescape_chars $1;
}
sub _escape($$)
{ my @escaped = map { '"' . escape_chars($_) . '"' }
defined $_[0] && length $_[0] ? split(/(?<=\n)/, $_[0]) : '';
unshift @escaped, '""' if @escaped > 1;
join $_[1], @escaped;
}
1;
|