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   5218 use strict;
  4         8  
  4         399  
4 4     4   24 use warnings;
  4         10  
  4         1921  
5              
6             sub normalize_maketext_string {
7 68     68 0 122 my ($filter) = @_;
8              
9 68         224 my $string_sr = $filter->get_string_sr();
10              
11 68 100       999 if ( ${$string_sr} !~ m/[\!\?\.\:\]…]$/ ) { # ? TODO ? smarter check that is is actual bracket notation and not just a string ?
  68         326  
12 8 100       18 if ( !__is_title_case( ${$string_sr} ) ) {
  8         34  
13              
14             # ${$string_sr} = ${$string_sr} . "[comment,missing puncutation ?]";
15 4         23 $filter->add_warning('Non title/label does not end with some sort of punctuation or bracket notation.');
16             }
17             }
18              
19 68         224 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   1028 my ($string) = @_;
25              
26 20         34 my $word; # buffer
27 20         45 my $possible_ick = 0;
28              
29             # this splits on the whitespace leftover after the Whitespace filter
30 20         190 for $word ( split( /(?:\x20|\xc2\xa0)/, $string ) ) {
31 68 50 33     355 next if !defined $word || $word eq ''; # e.g ' … X Y'
32 68 100       215 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       70 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         37 $possible_ick++;
37             }
38              
39 20 100       100 return if $possible_ick;
40 12         58 return 1;
41             }
42              
43             1;
44              
45             __END__