| 1 | =head1 NAME | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | MKDoc::Text::Structured - Another Text to HTML module | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | =head1 SYNOPSIS | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | my $text = some_structured_text(); | ||||||||||||||||||||
| 9 | my $html = MKDoc::Text::Structured::process ($text); | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 SUMMARY | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | L<MKDoc::Text::Structured> is a library which allows simple syntaxic | ||||||||||||||||||||
| 15 | text construct to be turned into HTML. These constructs are the ones | ||||||||||||||||||||
| 16 | you would be using when writing a text email or newsgroup message. | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | L<MKDoc::Text::Structured> follows the KISS philosophy. Comparing with | ||||||||||||||||||||
| 19 | similar modules which try to implement as many HTML constructs as possible, | ||||||||||||||||||||
| 20 | this module is incredibly conservative. | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =cut | ||||||||||||||||||||
| 23 | package MKDoc::Text::Structured; | ||||||||||||||||||||
| 24 | 20 | ▶ | use MKDoc::Text::Structured::Factory; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | 20 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | 20 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 20 | our $Text = ''; | |||||||||||||||||||
| 29 | 20 | our $VERSION = 0.83; | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | sub process | ||||||||||||||||||||
| 33 | 85 | ▶ | { | ||||||||||||||||||
|
Subroutine
process: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||
| 34 | 85 | my $text = shift; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | # Mac + DOS carriage returns -> bang! | ||||||||||||||||||||
| 37 | 85 | $text =~ s/\r\n/\n/gs; | |||||||||||||||||||
| 38 | 85 | $text =~ s/\r/\n/gs; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | # Trailing spaces -> fizzle! | ||||||||||||||||||||
| 41 | # (except when the line is made only of trailing spaces...) | ||||||||||||||||||||
| 42 | $text = join "\n", map { | ||||||||||||||||||||
| 43 | 85 | chomp(); | |||||||||||||||||||
| 44 | 239 | ▶ | s/\s+$// unless (/^\s*$/); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 239 | $_; | |||||||||||||||||||
| 46 | } split /\n/, $text; | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 85 | my @lines = split /\n/, $text; | |||||||||||||||||||
| 49 | 85 | my @result = (); | |||||||||||||||||||
| 50 | 85 | my $current = undef; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 85 | ▶ | while (scalar @lines) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | { | ||||||||||||||||||||
| 54 | 272 | my $line = shift (@lines); | |||||||||||||||||||
| 55 | 272 | ▶ | $current ||= MKDoc::Text::Structured::Factory->new ($line); | ||||||||||||||||||
|
Condition100%3/3
$current ||= "MKDoc::Text::Structured::Factory"->new($line)
MC/DC100%2/2
$current ||= "MKDoc::Text::Structured::Factory"->new($line)
$current
"MKDoc::Text::Structured::Factory"->new($line)
Truth table100%3/3
A ||= B
A= $currentB= "MKDoc::Text::Structured::Factory"->new($line)
| |||||||||||||||||||||
| 56 | 272 | ▶ | $current || next; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 248 | ▶ | if ($current->is_ok ($line)) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | { | ||||||||||||||||||||
| 60 | 215 | $current->add_line ($line); | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | else | ||||||||||||||||||||
| 63 | { | ||||||||||||||||||||
| 64 | 33 | push @result, $current->process(); | |||||||||||||||||||
| 65 | 33 | unshift (@lines, $line); | |||||||||||||||||||
| 66 | 33 | $current = undef; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 85 | ▶ | push @result, $current->process() if ($current); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | 85 | return join "\n", @result; | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 20 | 1; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||