File Coverage

blib/lib/Locale/Maketext/Utils/Phrase/Norm/EndPunc.pm
Criterion Covered Total %
statement 24 24 100.0
branch 11 12 91.6
condition 1 3 33.3
subroutine 4 4 100.0
pod 0 1 0.0
total 40 44 90.9


line stmt bran cond sub pod time code
1             package Locale::Maketext::Utils::Phrase::Norm::EndPunc;
2              
3 4     4   1911 use strict;
  4         4  
  4         94  
4 4     4   11 use warnings;
  4         4  
  4         763  
5              
6             sub normalize_maketext_string {
7 68     68 0 59 my ($filter) = @_;
8              
9 68         102 my $string_sr = $filter->get_string_sr();
10              
11 68 100       87 if ( ${$string_sr} !~ m/[\!\?\.\:\]…]$/ ) { # ? TODO ? smarter check that is is actual bracket notation and not just a string ?
  68         205  
12 8 100       10 if ( !__is_title_case( ${$string_sr} ) ) {
  8         20  
13              
14             # ${$string_sr} = ${$string_sr} . "[comment,missing puncutation ?]";
15 4         10 $filter->add_warning('Non title/label does not end with some sort of punctuation or bracket notation.');
16             }
17             }
18              
19 68         115 return $filter->return_value;
20             }
21              
22             # this is a really, really, REALLY, *REALLY* dumb check (that is why this filter is a warning)
23             sub __is_title_case {
24 20     20   527 my ($string) = @_;
25              
26 20         22 my $word; # buffer
27 20         12 my $possible_ick = 0;
28              
29             # this splits on the whitespace leftover after the Whitespace filter
30 20         121 for $word ( split( /(?:\x20|\xc2\xa0)/, $string ) ) {
31 68 50 33     207 next if !defined $word || $word eq ''; # e.g ' … X Y'
32 68 100       126 next if $word =~ m/^[A-Z\[]/; # When would a title/label ever start life w/ a beginning ellipsis? i.e. ' … Address' instead of 'Email Address'.
33             # If it is a short conclusion it should have puncutaion, e.g. 'Compiling …' ' … done.'
34 32 100       44 next if length($word) < 3; # There are longer words that should be lowercase (hint: [asis] [comment]), there are shorter words that should be capitol: see “this is a …” above
35              
36 20         18 $possible_ick++;
37             }
38              
39 20 100       51 return if $possible_ick;
40 12         33 return 1;
41             }
42              
43             1;
44              
45             __END__