File Coverage

blib/lib/String/Indent.pm
Criterion Covered Total %
statement 22 22 100.0
branch 4 4 100.0
condition 11 13 84.6
subroutine 5 5 100.0
pod 1 1 100.0
total 43 45 95.5


line stmt bran cond sub pod time code
1             package String::Indent;
2              
3             our $DATE = '2015-03-06'; # DATE
4             our $VERSION = '0.03'; # VERSION
5              
6 1     1   16841 use 5.010001;
  1         3  
  1         33  
7 1     1   4 use strict;
  1         1  
  1         42  
8 1     1   4 use warnings;
  1         2  
  1         37  
9              
10 1     1   5 use Exporter;
  1         1  
  1         194  
11             our @ISA = qw(Exporter);
12             our @EXPORT_OK = qw(
13             indent
14             );
15              
16             sub indent {
17 5     5 1 17 my ($indent, $str, $opts) = @_;
18 5   100     15 $opts //= {};
19              
20 5   100     17 my $ibl = $opts->{indent_blank_lines} // 1;
21 5   66     18 my $fli = $opts->{first_line_indent} // $indent;
22 5   66     15 my $sli = $opts->{subsequent_lines_indent} // $indent;
23             #say "D:ibl=<$ibl>, fli=<$fli>, sli=<$sli>";
24              
25 5         4 my $i = 0;
26 5 100 100     28 $str =~ s/^([^\r\n]?)/$i++; !$ibl && !$1 ? "$1" : $i==1 ? "$fli$1" : "$sli$1"/egm;
  16 100       13  
  16         78  
27 5         47 $str;
28             }
29              
30             1;
31             # ABSTRACT: String indenting routines
32              
33             __END__