| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 51 | 4 | $act_indent = $EMPTY_STR; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # If non_indent data, than return. | ||||||||||||||||||||||||||||
| 55 | 10 | ▶ | if ($non_indent) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$second and $second ne $act_indent . $self->{"next_indent"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 4 | 1; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||||||||||