| 1 | package Locale::TextDomain::OO::Singleton::Lexicon; ## no critic (TidyCode) | ||||||||||
| 2 | |||||||||||
| 3 | 36 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 36 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 36 | ▶ | use Carp qw(confess); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 36 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 36 | ▶ | use MooX::StrictConstructor; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 36 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 36 | our $VERSION = '1.031'; | |||||||||
| 11 | |||||||||||
| 12 | 36 | with qw( | |||||||||
| 13 | Locale::TextDomain::OO::Role::Logger | ||||||||||
| 14 | MooX::Singleton | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | has data => ( | ||||||||||
| 18 | is => 'ro', | ||||||||||
| 19 | init_arg => undef, | ||||||||||
| 20 | 32 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 32 | my $self = shift; | |||||||||
| 22 | return { | ||||||||||
| 23 | # empty lexicon of developer English | ||||||||||
| 24 | 'i-default::' => { | ||||||||||
| 25 | q{} => { | ||||||||||
| 26 | nplurals => 2, | ||||||||||
| 27 | plural => 'n != 1', | ||||||||||
| 28 | 12 | ▶ | plural_code => sub { return shift != 1 }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 29 | }, | ||||||||||
| 30 | }, | ||||||||||
| 31 | 32 | }; | |||||||||
| 32 | }, | ||||||||||
| 33 | 36 | ); | |||||||||
| 34 | |||||||||||
| 35 | 2 | ▶ | sub merge_lexicon { | ||||||||
|
Subroutine
merge_lexicon: called CC=7 SCAR=20.6
Pod
documented
| |||||||||||
| 36 | 2 | my ( $self, $from1, $from2, $to ) = @_; | |||||||||
| 37 | 2 | ▶ | defined $from1 | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | or confess 'Undef is not a lexicon name to merge from'; | ||||||||||
| 39 | 2 | ▶ | defined $from2 | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | or confess 'Undef is not a lexicon name to merge from'; | ||||||||||
| 41 | 2 | ▶ | exists $self->data->{$from1} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | or confess qq{Missing lexicon "$from1" to merge from}; | ||||||||||
| 43 | 2 | ▶ | exists $self->data->{$from2} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | or confess qq{Missing lexicon "$from2" to merge from}; | ||||||||||
| 45 | 2 | ▶ | defined $to | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | or confess 'Undef is not a lexicon name to merge to'; | ||||||||||
| 47 | |||||||||||
| 48 | $self->data->{$to} = { | ||||||||||
| 49 | 2 | %{ $self->data->{$from1} }, | |||||||||
| 50 | 2 | %{ $self->data->{$from2} }, | |||||||||
| 51 | }; | ||||||||||
| 52 | 2 | ▶ | $self->logger and $self->logger->( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | qq{Lexicon "$from1", "$from2" merged to "$to".}, | ||||||||||
| 54 | { | ||||||||||
| 55 | object => $self, | ||||||||||
| 56 | type => 'debug', | ||||||||||
| 57 | event => 'lexicon,merge', | ||||||||||
| 58 | }, | ||||||||||
| 59 | ); | ||||||||||
| 60 | |||||||||||
| 61 | 2 | return $self; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 1 | ▶ | sub copy_lexicon { | ||||||||
|
Subroutine
copy_lexicon: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||
| 65 | 1 | my ( $self, $from, $to ) = @_; | |||||||||
| 66 | |||||||||||
| 67 | 1 | ▶ | defined $from | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | or confess 'Undef is not a lexicon name to copy from'; | ||||||||||
| 69 | 1 | ▶ | exists $self->data->{$from} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | or confess qq{Missing lexicon "$from" to copy from}; | ||||||||||
| 71 | 1 | ▶ | defined $to | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | or confess 'Undef is not a lexicon name to copy to'; | ||||||||||
| 73 | |||||||||||
| 74 | $self->data->{$to} = { | ||||||||||
| 75 | 1 | %{ $self->data->{$from} }, | |||||||||
| 76 | }; | ||||||||||
| 77 | 1 | ▶ | $self->logger and $self->logger->( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | qq{Lexicon "$from" copied to "$to".}, | ||||||||||
| 79 | { | ||||||||||
| 80 | object => $self, | ||||||||||
| 81 | type => 'debug', | ||||||||||
| 82 | event => 'lexicon,copy', | ||||||||||
| 83 | }, | ||||||||||
| 84 | ); | ||||||||||
| 85 | |||||||||||
| 86 | 1 | return $self; | |||||||||
| 87 | |||||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 2 | ▶ | sub move_lexicon { | ||||||||
|
Subroutine
move_lexicon: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||
| 91 | 2 | my ( $self, $from, $to ) = @_; | |||||||||
| 92 | |||||||||||
| 93 | 2 | ▶ | defined $from | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | or confess 'Undef is not a lexicon name to move from'; | ||||||||||
| 95 | 2 | ▶ | exists $self->data->{$from} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | or confess qq{Missing lexicon "$from" to move from}; | ||||||||||
| 97 | 2 | ▶ | defined $to | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | or confess 'Undef is not a lexicon name to move to'; | ||||||||||
| 99 | 2 | $self->data->{$to} = delete $self->data->{$from}; | |||||||||
| 100 | 2 | ▶ | $self->logger and $self->logger->( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | qq{Lexicon "$from" moved to "$to".}, | ||||||||||
| 102 | { | ||||||||||
| 103 | object => $self, | ||||||||||
| 104 | type => 'debug', | ||||||||||
| 105 | event => 'lexicon,move', | ||||||||||
| 106 | }, | ||||||||||
| 107 | ); | ||||||||||
| 108 | |||||||||||
| 109 | 2 | return $self; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 2 | ▶ | sub delete_lexicon { | ||||||||
|
Subroutine
delete_lexicon: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||
| 113 | 2 | my ( $self, $name ) = @_; | |||||||||
| 114 | |||||||||||
| 115 | 2 | ▶ | defined $name | ||||||||
|
Branch: 1 branch
| |||||||||||
| 116 | or confess 'Undef is not a lexicon name to delete'; | ||||||||||
| 117 | 2 | my $deleted = delete $self->data->{$name}; | |||||||||
| 118 | 2 | ▶ | $self->logger and $self->logger->( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | qq{Lexicon "$name" deleted.}, | ||||||||||
| 120 | { | ||||||||||
| 121 | object => $self, | ||||||||||
| 122 | type => 'debug', | ||||||||||
| 123 | event => 'lexicon,delete', | ||||||||||
| 124 | }, | ||||||||||
| 125 | ); | ||||||||||
| 126 | |||||||||||
| 127 | 2 | return $deleted; | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | 36 | __PACKAGE__->meta->make_immutable; | |||||||||
| 131 | |||||||||||
| 132 | 36 | 1; | |||||||||
| 133 | |||||||||||
| 134 | __END__ | ||||||||||