blib/lib/String/Substrings.pm

filter: Statementstmt 100% 35 / 35 Branchbran 100% 10 / 10 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 98.3% 59 / 60 CC 9 SCAR 18.8
CC
9
Cov
100%
substrings
9.0
BEGIN
1.0
BEGIN
1.0
CRAP 6.5
↑ Summary
1 package String::Substrings;
2  
3 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 require Exporter;
10  
11 3 our @ISA = qw(Exporter);
12  
13 3 our %EXPORT_TAGS = ( 'all' => [ qw(
14 substrings
15 ) ] );
16  
17 3 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
18  
19 3 our @EXPORT = qw(
20 substrings
21 );
22  
23 3 our $VERSION = '0.02';
24  
25 255 ▶sub substrings($;$) {
Subroutine substrings: called CC=9 SCAR=22.0
Pod undocumented
26 255 my ($string, $length) = @_;
27 255 ▶ return undef unless defined $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 1 254 255
28
29 # paramter validation
30 254 ▶ if (my $r = ref($string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = ref $string) 2 252 254
31 2 croak "Please call me `substrings STRING [,LENGTH]`
32 but not with substrings $r, LENGTH";
33 }
34 252 ▶ if (defined($length) and (my $r = ref($length) or $length !~ /^\d+/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $length and (my $r = ref $length) || !($length =~ /^\d+/)) 4 248 252
Condition100%6/6
defined $length and (my $r = ref $length) || !($length =~ /^\d+/)
!ll&&!rl&&r
1271214
my $r = ref $length or not $length =~ /^\d+/
l!l&&r!l&&!r
22121
MC/DC100%3/3
defined $length and (my $r = ref $length) || !($length =~ /^\d+/)
defined $length my $r = ref $length not $length =~ /^\d+/
Truth table100%4/4
A and B or not(C)
A= defined $lengthB= my $r = ref $lengthC= not $length =~ /^\d+/
ABCresult
0XX0
1000
11X1
1011
35 4 croak "Please call me `substrings STRING [,LENGTH]`
36 but not with substrings '$string', $r";
37 }
38
39
40 248 my $strlength = length($string);
41 248 my @s = ();
42 248 ▶ if (defined $length) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $length) { } 121 127 248
43 121 ▶ return @s if $length == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $length == 0 6 115 121
44 115 push @s, map {substr $string, $_, $length} (0 .. $strlength-$length);
45 } else {
46 127 foreach my $length (1 .. $strlength) {
47 10240 push @s, map {substr $string, $_, $length}
48 (0 .. $strlength - $length);
49 }
50 }
51 242 return @s;
52 }
53  
54 3 1;
55 __END__
↑ Summary