| 1 | package Serge::Engine::Plugin::Transform::tags; | ||||||||||
| 2 | 1 | ▶ | use parent Serge::Engine::Plugin::Base::Transform; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | sub name { | ||||||||||
| 7 | 0 | ▶ | return 'Tag replacement plugin'; | ||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 8 | } | ||||||||||
| 9 | |||||||||||
| 10 | sub filter_key { | ||||||||||
| 11 | 0 | ▶ | my ($self, $s) = @_; | ||||||||
|
Subroutine
filter_key: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 12 | |||||||||||
| 13 | 0 | my $n = 0; | |||||||||
| 14 | |||||||||||
| 15 | # support simple cases like "aaa <div><strong>bbb</strong></div> ccc" | ||||||||||
| 16 | # and tags with processing instructions in them: | ||||||||||
| 17 | # "aaa <div<? if ($foo): ?> class="foo"<? endif ?>>bbb</div> ccc" | ||||||||||
| 18 | |||||||||||
| 19 | # test if the string consists of just tags and whitespace, | ||||||||||
| 20 | # and if this is the case, just return an empty string | ||||||||||
| 21 | # (which means that the translation can simply be copied from the source) | ||||||||||
| 22 | 0 | my $test = $s; | |||||||||
| 23 | 0 | $test =~ s/<[^<>]*?((<\?.*?\?>)*[^<>]*?)*>//sg; # remove all tags | |||||||||
| 24 | 0 | ▶ | if ($test !~ m/\S/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | return ''; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 0 | $s =~ s/<[^<>]*?((<\?.*?\?>)*[^<>]*?)*>/'[tag:'.($n++).']'/ge; | |||||||||
| 29 | |||||||||||
| 30 | 0 | return $s; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | sub transform { | ||||||||||
| 34 | 0 | ▶ | my ($self, $s, $target) = @_; | ||||||||
|
Subroutine
transform: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 35 | |||||||||||
| 36 | 0 | my ($s_start_tag, $s_content, $s_end_tag, $target_start_tag, $target_content, $target_end_tag); | |||||||||
| 37 | |||||||||||
| 38 | 0 | my @tags = (); | |||||||||
| 39 | 0 | my $n = 0; | |||||||||
| 40 | 0 | ▶ | while ($target =~ m/(<.*?((<\?.*?\?>)*.*?)*>)/g) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 0 | push @tags, $1; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 0 | my $n = 0; | |||||||||
| 45 | 0 | $s =~ s/<.*?((<\?.*?\?>)*.*?)*>/$tags[$n++]/ge; | |||||||||
| 46 | |||||||||||
| 47 | 0 | return $s; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 1 | 1; | |||||||||