File Coverage

blib/lib/LeftPad.pm
Criterion Covered Total %
statement 17 17 100.0
branch 4 4 100.0
condition 3 3 100.0
subroutine 6 6 100.0
pod 1 1 100.0
total 31 31 100.0


line stmt bran cond sub pod time code
1 1     1   14247 use 5.008001;
  1         3  
2 1     1   6 use strict;
  1         2  
  1         40  
3 1     1   4 use warnings;
  1         2  
  1         44  
4              
5             package LeftPad;
6             # ABSTRACT: Why should Node.js have all the fun?
7              
8             our $VERSION = '0.003';
9              
10 1     1   3 use base 'Exporter';
  1         1  
  1         103  
11             our @EXPORT = qw/leftpad/;
12              
13             #pod =func leftpad
14             #pod
15             #pod $string = leftpad( $string, $min_length );
16             #pod $string = leftpad( $string, $min_length, $pad_char );
17             #pod
18             #pod Returns a copy of the input string with left padding if the input string
19             #pod length is less than the minimum length. It pads with spaces unless given a
20             #pod pad character as a third argument.
21             #pod
22             #pod Zero or negative minimum length returns the input string. Only the first
23             #pod character in the pad-character string is used. Undefined warnings are
24             #pod suppressed so an undefined input string is treated as an empty string.
25             #pod
26             #pod =cut
27              
28             sub leftpad {
29 1     1   3 no warnings 'uninitialized';
  1         1  
  1         94  
30 13 100   13 1 104 return "" . $_[0] if $_[1] < 1;
31 10 100 100     66 return sprintf( "%*s", $_[1], $_[0] ) unless defined $_[2] && length $_[2];
32 4         23 return substr( $_[2], 0, 1 ) x ( $_[1] - length $_[0] ) . $_[0];
33             }
34              
35             1;
36              
37              
38             # vim: ts=4 sts=4 sw=4 et tw=75:
39              
40             __END__