578
|
5 |
26 |
0 |
$$self{'merged_snippets'} ||= do {
my @snippets;
foreach my $snip (@{$$self{'unmerged_snippets'};}) {
if (not defined $snip) {
push @snippets, undef if defined $snippets[-1];
}
elsif (not @snippets) {
push @snippets, $snip;
}
elsif (not defined $snippets[-1]) {
$snippets[-1] = $snip;
}
else {
my $prevstartline = $snippets[-1]->line;
my $newlines_to_add = $snip->line - $prevstartline - _number_of_newlines_in($snippets[-1]);
if ($newlines_to_add < 0) {
my $filename = $self->filename;
warn "Pod::Snippets: problem counting newlines at $filename\nnear line $prevstartline (trying to skip $newlines_to_add lines)\nOutput will be desynchronized.\n";
$newlines_to_add = 0;
};
$snippets[-1] = $snippets[-1] . $/ x $newlines_to_add . $snip;
};
};
pop @snippets unless defined $snippets[-1];
foreach my $i (0 .. $#snippets) {
my $text = "$snippets[$i]";
my $line = $snippets[$i]->line;
my $nl = $/;
while ($text =~ s/^\s*$nl//) {
++$line;
};
$text =~ s/(^\s*$nl)*\Z//m;
$snippets[$i] = 'Pod::Snippets::_Snippet'->new($line, $text, $snippets[$i]->names_set);
};
\@snippets
} |