File Coverage

blib/lib/LeftPad.pm
Criterion Covered Total %
statement 19 19 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 29 29 100.0


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