Localizer/Lexicon.pm

filter: Statementstmt 100% 23 / 23 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 86.0% 37 / 43 CC 4 SCAR 6.5
CC
4
Cov
87%
msgstr
3.7
new
2.0
BEGIN
1.0
CRAP 1.9
« Localizer/Resource.pm ↑ Summary Localizer.pm »
1 package Localizer::Lexicon;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use Class::Accessor::Lite 0.05 (
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 rw => [qw(dictionary)],
9 5 );
10  
11 6 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
12 6 my $class = shift;
13 6 ▶ my $dictionary = { @_==1 ? %{$_[0]} : @_ };
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 6 0 6
14 6 bless { dictionary => $dictionary }, $class;
15 }
16  
17 3 ▶sub msgids { keys %{shift->dictionary} }
Subroutine msgids: called CC=1 SCAR=0.0
Pod documented
18  
19 30 ▶sub msgstr {
Subroutine msgstr: called CC=3 SCAR=13.1
Pod documented
20 30 my ( $self, $msgid ) = @_;
21 30 ▶ ( exists $self->dictionary->{$msgid} && $self->dictionary->{$msgid} ) || undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->dictionary->{$msgid} and $self->dictionary->{$msgid} or undef 30 0 30
Condition33%1/3
exists $self->dictionary->{$msgid} and $self->dictionary->{$msgid}
!ll&&!rl&&r
0030
MC/DC0%0/2
exists $self->dictionary->{$msgid} and $self->dictionary->{$msgid}
exists $self->dictionary->{$msgid} $self->dictionary->{$msgid}
Truth table33%1/3
A and B
A= exists $self->dictionary->{$msgid}B= $self->dictionary->{$msgid}
ABresult
0X0
100
111
22 }
23  
24 5 1;
25  
26 =encoding utf-8
27  
28 =head1 NAME
29  
30 Localizer::Lexicon - Default lexicon class
31  
32 =head1 SYNOPSIS
33  
34 use Localizer::Resource;
35 use Localizer::Style::Gettext;
36 use Localizer::Lexicon
37  
38 my $es = Localizer::Resource->new(
39 dictionary => Localizer::Lexicon->new( 'Hi, %1.' => 'Hola %1.' ),
40 format => Localizer::Style::Gettext->new(),
41 );
42  
43 say $es->maketext("Hi, %1.", "John"); # => Hola, John.
44  
45 =head1 DESCRIPTION
46  
47 L<Localizer::Lexicon> is just the default lexicon that is built internally when you provide a hashref as your dictionary.
48  
49 You can implement your own class to replace this one as your L<Localizer> dictionary, for instance, to get your translations from a database or API. Just pass your object which implements msgids() and msgstr() like this one as your dictionary.
50  
51 =head1 METHODS
52  
53 =over 4
54  
55 =item * Localizer::Lexicon->new(%args | \%args)
56  
57 Constructor. It will initialize the lexicon from a list or hashref
58  
59 e.g.
60  
61 my $de = Localizer::Lexicon->new(
62 'Hello, World!' => 'Hello, Welt!'
63 );
64  
65 =over 8
66  
67 =item dictionary: Hash Reference
68  
69 Dictionary data to localize.
70  
71 =back
72  
73 =item * $localizer->msgids();
74  
75 Returns a list of msgeid's which are the keys of the dictionary.
76  
77 =item * $localizer->msgstr($msgid);
78  
79 Return the message to translate given $msgid (dictionary data with key). If you give nonexistent key to this method, it returns undef.
80  
81 =back
82  
83 =head1 SEE ALSO
84  
85 L<Locale::Maketext>, L<Locale::Maketext::Lexicon>
86  
87 =head1 LICENSE
88  
89 Copyright (C) Tokuhiro Matsuno.
90  
91 This library is free software; you can redistribute it and/or modify
92 it under the same terms as Perl itself.
« Localizer/Resource.pm ↑ Summary Localizer.pm »