line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Translate::Fluent::Elements::SelectExpression; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
42
|
use Moo; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
33
|
|
4
|
|
|
|
|
|
|
extends 'Translate::Fluent::Elements::Base'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has [qw(inline_expression default_variant)] => ( |
7
|
|
|
|
|
|
|
is => 'ro', |
8
|
|
|
|
|
|
|
default => sub { undef }, |
9
|
|
|
|
|
|
|
); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has variant_list => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
default => sub { bless {}, 'Translate::Fluent::Elements::_variantlist' }, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
around BUILDARGS => sub { |
17
|
|
|
|
|
|
|
my ($orig, $class, %args) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$args{ inline_expression } = $args{ InlineExpression }; |
20
|
|
|
|
|
|
|
$args{ default_variant} = delete $args{ variant_list }{ DefaultVariant }; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$args{ default_variant}->{Identifier} |
23
|
|
|
|
|
|
|
= $args{ default_variant }->{VariantKey}->{Identifier}; |
24
|
|
|
|
|
|
|
delete $args{default_variant}->{VariantKey}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my %list; |
27
|
|
|
|
|
|
|
if ($args{variant_list}->{variant}) { |
28
|
|
|
|
|
|
|
for my $variant (@{ $args{variant_list}->{variant} }) { |
29
|
|
|
|
|
|
|
$variant = Translate::Fluent::Elements->create( |
30
|
|
|
|
|
|
|
Variant => { |
31
|
|
|
|
|
|
|
Identifier => $variant->{VariantKey}->{Identifier}, |
32
|
|
|
|
|
|
|
Pattern => $variant->{Pattern}, |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
$list{ $variant->identifier } = $variant; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
if (%list) { |
40
|
|
|
|
|
|
|
$args{ variant_list } |
41
|
|
|
|
|
|
|
= bless \%list, 'Translate::Fluent::Elements::_variantlist'; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$class->$orig( %args ); |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub translate { |
48
|
6
|
|
|
6
|
1
|
13
|
my ($self, $variables) = @_; |
49
|
|
|
|
|
|
|
|
50
|
6
|
|
|
|
|
22
|
my $selector = $self->inline_expression->translate( $variables ); |
51
|
|
|
|
|
|
|
|
52
|
6
|
100
|
|
|
|
25
|
if (my $var = $self->variant_list->{ $selector }) { |
53
|
3
|
|
|
|
|
9
|
return $var->translate( $variables ); |
54
|
|
|
|
|
|
|
} else { |
55
|
3
|
|
|
|
|
29
|
return $self->default_variant->translate( $variables ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
package Translate::Fluent::Elements::_variantlist; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |