File Coverage

lib/Perlmazing/Perlmazing/Precompile/truncate_text.pm
Criterion Covered Total %
statement 15 15 100.0
branch 8 10 80.0
condition 1 3 33.3
subroutine 2 2 100.0
pod n/a
total 26 30 86.6


line stmt bran cond sub pod time code
1 50     50   440 use Perlmazing;
  50         143  
  50         294  
2            
3             sub main ($$) {
4 39     39   109 my ($str, $size) = @_;
5 39 50 33     191 return '' unless defined $str and length $str;
6 39 50       165 return unless is_number $size;
7 39         75 my $length = length $str;
8 39 100       87 return $str if $length <= $size;
9 38         79 my $next = substr $str, $size, 1;
10 38         73 $str = substr $str, 0, $size;
11 38 100       108 if ((my $index = rindex($str, ' ')) != -1) {
12 33 100       78 unless ($next eq ' ') {
13 28         57 $str = substr $str, 0, $index;
14             }
15             }
16 38         121 $str =~ s/\s+$//;
17 38         203 $str;
18             }
19            
20             1;