Indent/Utils.pm

filter: Statementstmt 100% 46 / 46 Branchbran 100% 2 / 2 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 6 / 6 totaltotal 100% 70 / 70 CC 3 SCAR 3.8
CC
3
Cov
100%
line_size_check
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« Indent.pm ↑ Summary
1 package Indent::Utils;
2  
3 22 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 22 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 22 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Constants.
11 22 Readonly::Scalar my $DEFAULT_TAB_LENGTH => 8;
12 22 Readonly::Scalar my $SPACE => q{ };
13  
14 22 our $VERSION = 0.10;
15  
16 # Length of tab.
17 22 our $TAB_LENGTH = $DEFAULT_TAB_LENGTH;
18  
19 # Export.
20 22 our @EXPORT_OK = qw(line_size_check reduce_duplicit_ws remove_first_ws
21 remove_last_ws remove_ws string_len);
22  
23 # Line size check.
24 sub line_size_check {
25 31 ▶ my $self = shift;
Subroutine line_size_check: called CC=3 SCAR=11.0
Pod documented
26 31 ▶ if (! defined $self->{'line_size'}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"line_size"} and $self->{"line_size"} =~ /^\d+$/ms) 4 27 31
Condition100%3/3
defined $self->{"line_size"} and $self->{"line_size"} =~ /^\d+$/ms
!ll&&!rl&&r
1327
MC/DC100%2/2
defined $self->{"line_size"} and $self->{"line_size"} =~ /^\d+$/ms
defined $self->{"line_size"} $self->{"line_size"} =~ /^\d+$/ms
Truth table100%3/3
A and B
A= defined $self->{"line_size"}B= $self->{"line_size"} =~ /^\d+$/ms
ABresult
0X0
100
111
27 || $self->{'line_size'} !~ m/^\d+$/ms) {
28  
29 err '\'line_size\' parameter must be a positive number.',
30 4 'line_size', $self->{'line_size'};
31 }
32 27 return;
33 }
34  
35 # Reduce duplicit blank space in string to one space.
36 # @param $string Reference to data string.
37 sub reduce_duplicit_ws {
38 3 ▶ my $string_sr = shift;
Subroutine reduce_duplicit_ws: called CC=1 SCAR=0.0
Pod documented
39 3 ${$string_sr} =~ s/\s+/\ /gms;
40 3 return;
41 }
42  
43 # Remove blank characters in begin of string.
44 # @param $string Reference to data string.
45 sub remove_first_ws {
46 9 ▶ my $string_sr = shift;
Subroutine remove_first_ws: called CC=1 SCAR=0.0
Pod documented
47 9 ${$string_sr} =~ s/^\s*//ms;
48 9 return;
49 }
50  
51 # Remove blank characters in end of string.
52 # @param $string Reference to data string.
53 sub remove_last_ws {
54 9 ▶ my $string_sr = shift;
Subroutine remove_last_ws: called CC=1 SCAR=0.0
Pod documented
55 9 ${$string_sr} =~ s/\s*$//ms;
56 9 return;
57 }
58  
59 # Remove white characters in begin and end of string.
60 # @param $string reference to data string.
61 sub remove_ws {
62 6 ▶ my $string_sr = shift;
Subroutine remove_ws: called CC=1 SCAR=0.0
Pod documented
63 6 remove_last_ws($string_sr);
64 6 remove_first_ws($string_sr);
65 6 return;
66 }
67  
68 # Gets length of string.
69 # @param $string Data string.
70 # @return $length_of_string Length of data string, when '\t' translate to
71 # $TAB_LENGTH x space.
72 sub string_len {
73 66 ▶ my $string = shift;
Subroutine string_len: called CC=1 SCAR=0.0
Pod documented
74 66 my $tmp = $SPACE x $TAB_LENGTH;
75 66 $string =~ s/\t/$tmp/gms;
76 66 my $length_of_string = length $string;
77 66 return $length_of_string;
78 }
79  
80 22 1;
81  
82 __END__
« Indent.pm ↑ Summary