| 1 | package Markdown::Pod; | ||||||||||
| 2 | # ABSTRACT: Convert Markdown to POD | ||||||||||
| 3 | |||||||||||
| 4 | 32 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 32 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 32 | our $VERSION = '0.007'; | |||||||||
| 8 | |||||||||||
| 9 | 32 | ▶ | use Encode qw( encodings ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 32 | ▶ | use List::Util qw( first ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 32 | ▶ | use Markdent::Parser; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 32 | ▶ | use Markdent::Types qw( Str ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 32 | ▶ | use Markdown::Pod::Handler; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 32 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 32 | ▶ | use MooseX::Params::Validate qw( validated_list ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 32 | ▶ | use MooseX::StrictConstructor; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 32 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | sub markdown_to_pod { | ||||||||||
| 20 | 31 | ▶ | my $self = shift; | ||||||||
|
Subroutine
markdown_to_pod: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||
| 21 | 31 | my ( $dialect, $markdown, $encoding ) = validated_list( | |||||||||
| 22 | \@_, | ||||||||||
| 23 | dialect => { type => 'Str', default => 'Standard', optional => 1 }, | ||||||||||
| 24 | markdown => { type => 'Str' }, | ||||||||||
| 25 | encoding => { type => 'Str', default => q{}, optional => 1 }, | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | 31 | my $capture = q{}; | |||||||||
| 29 | 31 | ▶ | open my $fh, '>', \$capture | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | or die $!; | ||||||||||
| 31 | |||||||||||
| 32 | 31 | ▶ | if ($encoding) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 31 | ▶ | my $found = first { $_ eq $encoding } Encode->encodings; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 31 | ▶ | if ($found) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 31 | ▶ | binmode $fh, ":encoding($encoding)"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | } | ||||||||||
| 37 | else { | ||||||||||
| 38 | 0 | warn "cannot find such '$encoding' encoding\n"; | |||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 31 | my $handler = Markdown::Pod::Handler->new( | |||||||||
| 43 | encoding => $encoding, | ||||||||||
| 44 | output => $fh, | ||||||||||
| 45 | ); | ||||||||||
| 46 | |||||||||||
| 47 | 31 | my $parser = Markdent::Parser->new( | |||||||||
| 48 | dialect => $dialect, | ||||||||||
| 49 | handler => $handler, | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | 31 | $parser->parse( markdown => $markdown ); | |||||||||
| 53 | |||||||||||
| 54 | 31 | close $fh; | |||||||||
| 55 | |||||||||||
| 56 | 31 | $capture =~ s/\n+$/\n/; | |||||||||
| 57 | |||||||||||
| 58 | # | ||||||||||
| 59 | # FIXME | ||||||||||
| 60 | # dirty code to support blockquote | ||||||||||
| 61 | # | ||||||||||
| 62 | # UPDATE A.Speer - not needed, blockquote converted to use =over 2, =back | ||||||||||
| 63 | # | ||||||||||
| 64 | #$capture =~ s{ | ||||||||||
| 65 | # ^ =begin \s+ blockquote | ||||||||||
| 66 | # \s+ | ||||||||||
| 67 | # (.*?) | ||||||||||
| 68 | # \s+ | ||||||||||
| 69 | # ^ =end \s+ blockquote | ||||||||||
| 70 | #}{ | ||||||||||
| 71 | # my $quoted = $1; | ||||||||||
| 72 | # $quoted =~ s/^/ /gsm; | ||||||||||
| 73 | # $quoted; | ||||||||||
| 74 | #}xgsme; | ||||||||||
| 75 | |||||||||||
| 76 | 31 | return $capture; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 32 | __PACKAGE__->meta->make_immutable; | |||||||||
| 80 | 32 | 1; | |||||||||
| 81 | |||||||||||
| 82 | __END__ | ||||||||||
| 83 | |||||||||||
| 84 | =pod | ||||||||||
| 85 | |||||||||||
| 86 | =encoding UTF-8 | ||||||||||
| 87 | |||||||||||
| 88 | =head1 NAME | ||||||||||
| 89 | |||||||||||
| 90 | Markdown::Pod - Convert Markdown to POD | ||||||||||
| 91 | |||||||||||
| 92 | =head1 VERSION | ||||||||||
| 93 | |||||||||||
| 94 | version 0.007 | ||||||||||
| 95 | |||||||||||
| 96 | =head1 SYNOPSIS | ||||||||||
| 97 | |||||||||||
| 98 | use Markdown::Pod; | ||||||||||
| 99 | |||||||||||
| 100 | my $m2p = Markdown::Pod->new; | ||||||||||
| 101 | my $pod = $m2p->markdown_to_pod( | ||||||||||
| 102 | markdown => $markdown, | ||||||||||
| 103 | ); | ||||||||||
| 104 | |||||||||||
| 105 | =head1 DESCRIPTION | ||||||||||
| 106 | |||||||||||
| 107 | This module parses Markdown text and return POD text. | ||||||||||
| 108 | It uses L<Markdent> module to parse Markdown. | ||||||||||
| 109 | Due to POD doesn't support blockquoted HTML tag, | ||||||||||
| 110 | so quoted text of Markdown will not be handled properly. | ||||||||||
| 111 | Quoted text will be converted to POD verbatim section. | ||||||||||
| 112 | |||||||||||
| 113 | =head1 ATTRIBUTES | ||||||||||
| 114 | |||||||||||
| 115 | =head2 markdown | ||||||||||
| 116 | |||||||||||
| 117 | markdown text | ||||||||||
| 118 | |||||||||||
| 119 | =head2 encoding | ||||||||||
| 120 | |||||||||||
| 121 | encoding to use. Available type of encoding is same as L<Encode> module. | ||||||||||
| 122 | |||||||||||
| 123 | =head1 METHODS | ||||||||||
| 124 | |||||||||||
| 125 | =head2 new | ||||||||||
| 126 | |||||||||||
| 127 | create Markdown::Pod object | ||||||||||
| 128 | |||||||||||
| 129 | =head2 markdown_to_pod | ||||||||||
| 130 | |||||||||||
| 131 | convert markdown text to POD text | ||||||||||
| 132 | |||||||||||
| 133 | =head1 SEE ALSO | ||||||||||
| 134 | |||||||||||
| 135 | =over | ||||||||||
| 136 | |||||||||||
| 137 | =item * | ||||||||||
| 138 | |||||||||||
| 139 | L<Markdent> | ||||||||||
| 140 | |||||||||||
| 141 | =item * | ||||||||||
| 142 | |||||||||||
| 143 | L<Pod::Markdown> | ||||||||||
| 144 | |||||||||||
| 145 | =item * | ||||||||||
| 146 | |||||||||||
| 147 | L<Text::MultiMarkdown>, L<Text::Markdown> | ||||||||||
| 148 | |||||||||||
| 149 | =back | ||||||||||
| 150 | |||||||||||
| 151 | =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan | ||||||||||
| 152 | |||||||||||
| 153 | =head1 SUPPORT | ||||||||||
| 154 | |||||||||||
| 155 | =head2 Bugs / Feature Requests | ||||||||||
| 156 | |||||||||||
| 157 | Please report any bugs or feature requests through the issue tracker | ||||||||||
| 158 | at L<https://github.com/keedi/Markdown-Pod/issues>. | ||||||||||
| 159 | You will be notified automatically of any progress on your issue. | ||||||||||
| 160 | |||||||||||
| 161 | =head2 Source Code | ||||||||||
| 162 | |||||||||||
| 163 | This is open source software. The code repository is available for | ||||||||||
| 164 | public review and contribution under the terms of the license. | ||||||||||
| 165 | |||||||||||
| 166 | L<https://github.com/keedi/Markdown-Pod> | ||||||||||
| 167 | |||||||||||
| 168 | git clone https://github.com/keedi/Markdown-Pod.git | ||||||||||
| 169 | |||||||||||
| 170 | =head1 AUTHOR | ||||||||||
| 171 | |||||||||||
| 172 | 김도형 - Keedi Kim <keedi@cpan.org> | ||||||||||
| 173 | |||||||||||
| 174 | =head1 CONTRIBUTORS | ||||||||||
| 175 | |||||||||||
| 176 | =for stopwords Andrew Speer (ASPEER) Jason McIntosh (JMAC) Zakariyya Mughal (ZMUGHAL) | ||||||||||
| 177 | |||||||||||
| 178 | =over 4 | ||||||||||
| 179 | |||||||||||
| 180 | =item * | ||||||||||
| 181 | |||||||||||
| 182 | Andrew Speer (ASPEER) <andrew@webdyne.org> | ||||||||||
| 183 | |||||||||||
| 184 | =item * | ||||||||||
| 185 | |||||||||||
| 186 | Jason McIntosh (JMAC) <jmac@jmac.org> | ||||||||||
| 187 | |||||||||||
| 188 | =item * | ||||||||||
| 189 | |||||||||||
| 190 | Zakariyya Mughal (ZMUGHAL) <zmughal@cpan.org> | ||||||||||
| 191 | |||||||||||
| 192 | =back | ||||||||||
| 193 | |||||||||||
| 194 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 195 | |||||||||||
| 196 | This software is copyright (c) 2018 by Keedi Kim. | ||||||||||
| 197 | |||||||||||
| 198 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 199 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 200 | |||||||||||
| 201 | =cut | ||||||||||