| 1 | 2 | ▶ | use 5.10.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package String::Nudge; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # ABSTRACT: Indents all lines in a multi-line string | ||||||||||||||||||||||||||||
| 8 | 2 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = '1.0002'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | our @EXPORT = qw/nudge/; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 11 | ▶ | sub nudge ($;$) { | ||||||||||||||||||||||||||
|
Subroutine
nudge: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 11 | my $first = shift; | |||||||||||||||||||||||||||
| 16 | 11 | my $second = shift; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 11 | my $indent = 4; | |||||||||||||||||||||||||||
| 19 | 11 | my $string; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 11 | ▶ | if(defined $second) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 8 | ▶ | if(int $first eq $first && int $first >= 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
int $first eq $first and int $first >= 0
MC/DC100%2/2
int $first eq $first and int $first >= 0
int $first eq $first
int $first >= 0
Truth table100%3/3
A and B
A= int $first eq $firstB= int $first >= 0
| |||||||||||||||||||||||||||||
| 23 | 6 | $indent = int $first; | |||||||||||||||||||||||||||
| 24 | 6 | $string = $second; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | else { | ||||||||||||||||||||||||||||
| 27 | 2 | warnings::warn(numeric => q{first argument to nudge not an integer >= 0.}); | |||||||||||||||||||||||||||
| 28 | 2 | $string = $second; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | else { | ||||||||||||||||||||||||||||
| 32 | 3 | $string = $first; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 11 | my $nudgement = ' ' x $indent; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 11 | $string =~ s{^(?=\V)}{$nudgement}gms; | |||||||||||||||||||||||||||
| 38 | 11 | $string =~ s{^\h*$}{}gms; | |||||||||||||||||||||||||||
| 39 | 11 | return $string; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | 1; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | __END__ | ||||||||||||||||||||||||||||