Indent/Data.pm

filter: Statementstmt 100% 49 / 49 Branchbran 100% 14 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 78 / 78 CC 9 SCAR 15.3
CC
9
Cov
100%
indent
8.0
new
2.0
BEGIN
1.0
CRAP 4.6
« Indent/Word.pm ↑ Summary Indent.pm »
1 package Indent::Data;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Class::Utils qw(set_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Indent::Utils qw(line_size_check string_len);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # Constants.
12 4 Readonly::Scalar my $EMPTY_STR => q{};
13 4 Readonly::Scalar my $LINE_SIZE => 79;
14  
15 4 our $VERSION = 0.10;
16  
17 # Constructor.
18 sub new {
19 11 ▶ my ($class, @params) = @_;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
20 11 my $self = bless {}, $class;
21  
22 # Options.
23 11 $self->{'line_size'} = $LINE_SIZE;
24 11 $self->{'next_indent'} = "\t";
25  
26 # Output.
27 11 $self->{'output_separator'} = "\n";
28  
29 # Process params.
30 11 set_params($self, @params);
31  
32 # 'line_size' check.
33 9 line_size_check($self);
34  
35 # Error with 'next_indent' length greater than 'line_size'.
36 9 ▶ if ($self->{'line_size'} <= length $self->{'next_indent'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"line_size"} <= length $self->{"next_indent"}) 1 8 9
37 1 err "Bad line_size = '$self->{'line_size'}' ".
38 "or length of string '$self->{'next_indent'}'.";
39 }
40  
41 # Object.
42 8 return $self;
43 }
44  
45 # Parses tag to indented data.
46 sub indent {
47 10 ▶ my ($self, $data, $act_indent, $non_indent) = @_;
Subroutine indent: called CC=8 SCAR=20.8
Pod documented
48  
49 # Undef indent.
50 10 ▶ if (! $act_indent) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($act_indent) 4 6 10
51 4 $act_indent = $EMPTY_STR;
52 }
53  
54 # If non_indent data, than return.
55 10 ▶ if ($non_indent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($non_indent) 1 9 10
56 1 return $act_indent.$data;
57 }
58  
59 # Check to actual indent maximal length.
60 9 ▶ if (string_len($act_indent) > ($self->{'line_size'}
Branch: 1 branch
BranchTrueFalseTotal
if (string_len($act_indent) > $self->{"line_size"} - string_len($self->{"next_indent"}) - 1) 2 7 9
61 - string_len($self->{'next_indent'}) - 1)) {
62  
63 2 err 'Bad actual indent value. Length is greater then '.
64 '(\'line_size\' - \'size of next_indent\' - 1).';
65 }
66  
67 # Splits data.
68 7 my $first = undef;
69 7 my $second = $act_indent.$data;
70 7 my @data;
71 7 ▶ while (string_len($second) >= $self->{'line_size'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (string_len($second) >= $self->{"line_size"}) 30 7 37
72 30 $first = substr($second, 0, $self->{'line_size'});
73 $second = $act_indent.$self->{'next_indent'}.substr($second,
74 30 $self->{'line_size'});
75  
76 # Parsed part of data to @data array.
77 30 push @data, $first;
78 }
79  
80 # Add other data to @data array.
81 7 ▶ if ($second && $second ne $act_indent.$self->{'next_indent'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($second and $second ne $act_indent . $self->{"next_indent"}) 3 4 7
Condition100%3/3
$second and $second ne $act_indent . $self->{"next_indent"}
!ll&&!rl&&r
133
MC/DC100%2/2
$second and $second ne $act_indent . $self->{"next_indent"}
$second $second ne $act_indent . $self->{"next_indent"}
Truth table100%3/3
A and B
A= $secondB= $second ne $act_indent . $self->{"next_indent"}
ABresult
0X0
100
111
82 3 push @data, $second;
83 }
84  
85 # Return as array or one line with output separator between its.
86 7 ▶ return wantarray ? @data : join($self->{'output_separator'}, @data);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 2 7
87 }
88  
89 4 1;
90  
91 __END__
« Indent/Word.pm ↑ Summary Indent.pm »