File Coverage

blib/lib/Locale/Maketext/Utils/Phrase/Norm/Grapheme.pm
Criterion Covered Total %
statement 12 12 100.0
branch 2 2 100.0
condition n/a
subroutine 3 3 100.0
pod 0 1 0.0
total 17 18 94.4


line stmt bran cond sub pod time code
1             package Locale::Maketext::Utils::Phrase::Norm::Grapheme;
2              
3 4     4   2241 use strict;
  4         38  
  4         128  
4 4     4   16 use warnings;
  4         28  
  4         691  
5              
6             sub normalize_maketext_string {
7 75     75 0 209 my ($filter) = @_;
8              
9 75         230 my $string_sr = $filter->get_string_sr();
10              
11 75 100       167 if ( ${$string_sr} =~ s/((?:\\x[0-9a-fA-F]{2})+)/[comment,grapheme “$1”]/ ) {
  75         420  
12 8         30 $filter->add_violation('Contains grapheme notation');
13             }
14              
15 75         233 return $filter->return_value;
16             }
17              
18             1;
19              
20             __END__
21              
22             =encoding utf-8
23              
24             =head1 Normalization
25              
26             Graphemes are not very human readable and require interpolation, we can avoid both issues by not using them!
27              
28             =head2 Rationale
29              
30             This helps give consistency, clarity, and simplicity.
31              
32             If we parse a string and find 'Commencing compilation \xe2\x80\xa6' then we have to interpolate that string into 'Commencing compilation …' before we can look it up to see if it exists in a hash.
33              
34             Graphemes also add a layer of complexity that hinders translators and thus makes room for lower quality translations.
35              
36             Developers have it slightly better in that they’ll recognize it but it still requires effort to figure out what it is exactly and to determine what sequence they need for a given character.
37              
38             You can simply use the character itself or a bracket notation method for the handful of markup related or visually special characters
39              
40             =head1 possible violations
41              
42             If you get false positives then that only goes to help highlight how ambiguity adds to the reason to avoid non-bytes strings!
43              
44             =over 4
45              
46             =item Contains grapheme notation
47              
48             A sequence of \xe2\x98\xba\xe2\x80\xa6 will be replaced w/ [comment,grapheme “\xe2\x98\xba\xe2\x80\xa6”]
49              
50             =back
51              
52             =head1 possible warnings
53              
54             None
55              
56             =head1 Entire filter only runs under extra filter
57              
58             See L<Locale::Maketext::Utils::Phrase::Norm/extra filters> for more details.