File Coverage

blib/lib/String/Nudge.pm
Criterion Covered Total %
statement 26 26 100.0
branch 4 4 100.0
condition 3 3 100.0
subroutine 5 5 100.0
pod 1 1 100.0
total 39 39 100.0


line stmt bran cond sub pod time code
1 1     1   78766 use 5.10.0;
  1         15  
2 1     1   5 use strict;
  1         1  
  1         26  
3 1     1   5 use warnings;
  1         2  
  1         83  
4              
5             package String::Nudge;
6              
7             # ABSTRACT: Indents all lines in a multi-line string
8             our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9             our $VERSION = '1.0002';
10              
11 1     1   8 use Exporter 'import';
  1         1  
  1         247  
12             our @EXPORT = qw/nudge/;
13              
14             sub nudge ($;$) {
15 11     11 1 718 my $first = shift;
16 11         19 my $second = shift;
17              
18 11         15 my $indent = 4;
19 11         18 my $string;
20              
21 11 100       26 if(defined $second) {
22 8 100 100     49 if(int $first eq $first && int $first >= 0) {
23 6         11 $indent = int $first;
24 6         9 $string = $second;
25             }
26             else {
27 2         373 warnings::warn(numeric => q{first argument to nudge not an integer >= 0.});
28 2         13 $string = $second;
29             }
30             }
31             else {
32 3         6 $string = $first;
33              
34             }
35 11         27 my $nudgement = ' ' x $indent;
36              
37 11         61 $string =~ s{^(?=\V)}{$nudgement}gms;
38 11         45 $string =~ s{^\h*$}{}gms;
39 11         48 return $string;
40             }
41              
42              
43             1;
44              
45             __END__