| 1 | package Indent::String; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Class::Utils qw(set_params); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Indent::Utils qw(line_size_check); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | # Constants. | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | Readonly::Scalar my $EMPTY_STR => q{}; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | Readonly::Scalar my $LINE_SIZE => 79; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | our $VERSION = 0.08; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | # Constructor. | ||||||||||||||||||||||||||||||||||||||||||
| 17 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my ($class, @params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | # Options. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | $self->{'line_size'} = $LINE_SIZE; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | $self->{'next_indent'} = "\t"; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # Output. | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | $self->{'output_separator'} = "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # Process params. | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | set_params($self, @params); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # 'line_size' check. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | line_size_check($self); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # Object. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | # Indent text by words to line_size block size. | ||||||||||||||||||||||||||||||||||||||||||
| 39 | sub indent { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my ($self, $data, $act_indent, $non_indent) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
indent: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # 'indent' initialization. | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if (! defined $act_indent) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $act_indent = $EMPTY_STR; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # If non_indent data, than return. | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($non_indent) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return $act_indent.$data; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my ($first, $second) = (undef, $act_indent.$data); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $last_second_length = 0; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my @data; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $one = 1; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | while (length $second >= $self->{'line_size'} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
length $second >= $self->{"line_size"} and $second =~ /^\s*\S+\s+/ms and $last_second_length != length $second
length $second >= $self->{"line_size"} and $second =~ /^\s*\S+\s+/ms
MC/DC0%0/3
length $second >= $self->{"line_size"} and $second =~ /^\s*\S+\s+/ms and $last_second_length != length $second
length $second >= $self->{"line_size"}
$second =~ /^\s*\S+\s+/ms
$last_second_length != length $second
Truth table0%0/4
A and B and C
A= length $second >= $self->{"line_size"}B= $second =~ /^\s*\S+\s+/msC= $last_second_length != length $second
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | && $second =~ /^\s*\S+\s+/ms | ||||||||||||||||||||||||||||||||||||||||||
| 58 | && $last_second_length != length $second) { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | # Last length of non-parsed part of data. | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $last_second_length = length $second; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # Parse to indent length. | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ($first, my $tmp) = $second | |||||||||||||||||||||||||||||||||||||||||
| 65 | =~ /^(.{0,$self->{'line_size'}})\s+(.*)$/msx; | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | # If string is non-breakable in indent length, than parse to | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # blank char. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if (! $first || length $first < length $act_indent | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $first or length $first < length $act_indent or $first =~ /^$act_indent\s*$/ms
not $first or length $first < length $act_indent
MC/DC0%0/3
not $first or length $first < length $act_indent or $first =~ /^$act_indent\s*$/ms
not $first
length $first < length $act_indent
$first =~ /^$act_indent\s*$/ms
Truth table0%0/4
not(A) or B or C
A= not $firstB= length $first < length $act_indentC= $first =~ /^$act_indent\s*$/ms
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | || $first =~ /^$act_indent\s*$/ms) { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ($first, $tmp) = $second | |||||||||||||||||||||||||||||||||||||||||
| 73 | =~ /^($act_indent\s*[^\s]+?)\s(.*)$/msx; | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # If parsing is right. | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ($tmp) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # Non-parsed part of data. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $second = $tmp; | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # Add next_indent to string. | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($one == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $act_indent .= $self->{'next_indent'}; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $one = 0; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $second = $act_indent.$second; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | # Parsed part of data to @data array. | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | push @data, $first; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | # Add other data to @data array. | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($second || $second !~ /^\s*$/ms) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$second or not $second =~ /^\s*$/ms
MC/DC0%0/2
$second or not $second =~ /^\s*$/ms
$second
not $second =~ /^\s*$/ms
Truth table0%0/3
A or not(B)
A= $secondB= not $second =~ /^\s*$/ms
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | push @data, $second; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | # Return as array or one line with output separator between its. | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | return wantarray ? @data : join($self->{'output_separator'}, @data); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||||||||||||||||||||||||