| 1 | package Serge::Engine::Plugin::parse_master; | ||||||||||
| 2 | 1 | ▶ | use parent Serge::Engine::Plugin::Base::Parser; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | no warnings qw(uninitialized); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | sub name { | ||||||||||
| 9 | 0 | ▶ | return 'Master files parser plugin'; | ||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 10 | } | ||||||||||
| 11 | |||||||||||
| 12 | sub init { | ||||||||||
| 13 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 14 | |||||||||||
| 15 | 0 | $self->SUPER::init(@_); | |||||||||
| 16 | |||||||||||
| 17 | 0 | $self->{errors} = {}; | |||||||||
| 18 | |||||||||||
| 19 | 0 | $self->merge_schema({ | |||||||||
| 20 | opening_marker => 'STRING', | ||||||||||
| 21 | closing_marker => 'STRING', | ||||||||||
| 22 | delimiter => 'STRING', | ||||||||||
| 23 | }); | ||||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | sub validate_data { | ||||||||||
| 27 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
validate_data: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 28 | |||||||||||
| 29 | 0 | $self->SUPER::validate_data; | |||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | $self->{data}->{opening_marker} = '<%' unless $self->{data}->{opening_marker} ne ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | ▶ | $self->{data}->{closing_marker} = '%>' unless $self->{data}->{closing_marker} ne ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | ▶ | $self->{data}->{delimiter} = '%%' unless $self->{data}->{delimiter} ne ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | sub parse { | ||||||||||
| 37 | 0 | ▶ | my ($self, $textref, $callbackref, $lang) = @_; | ||||||||
|
Subroutine
parse: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | die 'callbackref not specified' unless $callbackref; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | # Finding translatable strings in file | ||||||||||
| 42 | |||||||||||
| 43 | # Format is: <%string%> | ||||||||||
| 44 | # or: <%string%%context%> | ||||||||||
| 45 | # or: <%string%%context%%hint%> | ||||||||||
| 46 | # or: <%string%%context%%hint%%flags%> | ||||||||||
| 47 | # context, hint and flags are optional and can be empty: | ||||||||||
| 48 | # <%string%%%%hint%> | ||||||||||
| 49 | # <%string%%%%%%flags%> | ||||||||||
| 50 | |||||||||||
| 51 | 0 | my $o = $self->{data}->{opening_marker}; | |||||||||
| 52 | 0 | my $c = $self->{data}->{closing_marker}; | |||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | if ($lang) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | # do a substitution (on a copy of the string) | ||||||||||
| 56 | 0 | my $translated_text = $$textref; | |||||||||
| 57 | 0 | $translated_text =~ s|$o(.*?)$c|&$callbackref($self->_split_params($1), $lang)|sge; | |||||||||
| 58 | 0 | return $translated_text; | |||||||||
| 59 | } else { | ||||||||||
| 60 | # just match strings (faster) | ||||||||||
| 61 | 0 | ▶ | while ($$textref =~ m/$o(.*?)$c/sg) { &$callbackref($self->_split_params($1), undef); } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | return undef; | |||||||||
| 63 | } | ||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | sub _split_params { | ||||||||||
| 67 | 0 | ▶ | my ($self, $text) = @_; | ||||||||
|
Subroutine
_split_params: not called CC=1 SCAR=6.9
| |||||||||||
| 68 | 0 | my $d = $self->{data}->{delimiter}; | |||||||||
| 69 | 0 | my ($str, $context, $hint, $flags) = split(/$d/, $text); | |||||||||
| 70 | 0 | my @flags_array = split(/,/, $flags); | |||||||||
| 71 | 0 | return ($str, $context, $hint, \@flags_array); # this will ensure we return exactly 4 values | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 1 | 1; | |||||||||