File Coverage

blib/lib/Log/Report/Lexicon/Table.pm
Criterion Covered Total %
statement 27 32 84.3
branch 9 14 64.2
condition n/a
subroutine 8 13 61.5
pod 9 10 90.0
total 53 69 76.8


line stmt bran cond sub pod time code
1             # This code is part of Perl distribution Log-Report-Lexicon version 1.15.
2             # The POD got stripped from this file by OODoc version 3.05.
3             # For contributors see file ChangeLog.
4              
5             # This software is copyright (c) 2007-2025 by Mark Overmeer.
6              
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10              
11             #oodist: *** DO NOT USE THIS VERSION FOR PRODUCTION ***
12             #oodist: This file contains OODoc-style documentation which will get stripped
13             #oodist: during its release in the distribution. You can use this file for
14             #oodist: testing, however the code of this development version may be broken!
15              
16             package Log::Report::Lexicon::Table;{
17             our $VERSION = '1.15';
18             }
19              
20              
21 6     6   51 use warnings;
  6         12  
  6         409  
22 6     6   33 use strict;
  6         16  
  6         246  
23              
24 6     6   674 use Log::Report 'log-report-lexicon';
  6         114835  
  6         49  
25              
26             #--------------------
27              
28 2     2 1 542 sub new(@) { my $class = shift; (bless {}, $class)->init({@_}) }
  2         23  
29 0     0 0 0 sub init($) { $_[0] }
30              
31             #--------------------
32              
33             #--------------------
34              
35 0     0 1 0 sub msgid($;$) {panic "not implemented"}
36 0     0 1 0 sub msgstr($;$$) {panic "not implemented"}
37              
38             #--------------------
39              
40 0     0 1 0 sub add($) {panic "not implemented"}
41              
42              
43 0     0 1 0 sub translations(;$) {panic "not implemented"}
44              
45              
46             sub pluralIndex($)
47 23     23 1 58 { my ($self, $count) = @_;
48             my $algo = $self->{algo}
49 23 50       73 or error __x"there is no Plural-Forms field in the header, but needed";
50              
51 23         1361 $algo->($count);
52             }
53              
54              
55             sub setupPluralAlgorithm()
56 18     18 1 24 { my $self = shift;
57 18 100       68 my $forms = $self->header('Plural-Forms') or return;
58              
59 7 50       76 my $alg = $forms =~ m/plural\=([n%!=><\s\d|&?:()]+)/ ? $1 : "n!=1";
60 7         65 $alg =~ s/\bn\b/(\$_[0])/g;
61 7         736 my $code = eval "sub(\$) {$alg}";
62 7 50       32 $@ and error __x"invalid plural-form algorithm '{alg}'", alg => $alg;
63 7         37 $self->{algo} = $code;
64              
65 7 50       271 $self->{nplurals} = $forms =~ m/\bnplurals\=(\d+)/ ? $1 : 2;
66 7         28 $self;
67             }
68              
69              
70 8     8 1 56 sub nrPlurals() { $_[0]->{nplurals} }
71              
72              
73             sub header($@)
74 14     14 1 1156 { my ($self, $field) = @_;
75 14 50       32 my $header = $self->msgid('') or return;
76 14 100       434 $header =~ m/^\Q$field\E\:\s*([^\n]*?)\;?\s*$/im ? $1 : undef;
77             }
78              
79             1;