Pod.pm

filter: Statementstmt 90.4% 19 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 92.8% 26 / 28 CC 1 SCAR 0.4
CC
1
Cov
90%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Pod/Handler.pm ↑ Summary
1 package Markdown::Pod;
2 {
3 $Markdown::Pod::VERSION = '0.005';
4 }
5 # ABSTRACT: Convert Markdown to POD
6  
7 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 30 ▶use Encode qw( encodings );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 30 ▶use List::Util qw( first );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 30 ▶use Markdent::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 30 ▶use Markdent::Types qw( Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 30 ▶use Markdown::Pod::Handler;
Subroutine BEGIN: called CC=1 SCAR=2.6
15 use Moose;
16 use MooseX::Params::Validate qw( validated_list );
17 use MooseX::StrictConstructor;
18 use namespace::autoclean;
19  
20 sub markdown_to_pod {
21 my $self = shift;
22 my ( $dialect, $markdown, $encoding ) = validated_list(
23 \@_,
24 dialect => { isa => Str, default => 'Standard' },
25 markdown => { isa => Str },
26 encoding => { isa => Str, default => q{}, optional => 1 },
27 );
28  
29 my $capture = q{};
30 open my $fh, '>', \$capture
31 or die $!;
32  
33 if ($encoding) {
34 my $found = first { $_ eq $encoding } Encode->encodings;
35 if ($found) {
36 binmode $fh, ":encoding($encoding)";
37 }
38 else {
39 warn "cannot find such '$encoding' encoding\n";
40 }
41 }
42  
43 my $handler = Markdown::Pod::Handler->new(
44 encoding => $encoding,
45 output => $fh,
46 );
47  
48 my $parser = Markdent::Parser->new(
49 dialect => $dialect,
50 handler => $handler,
51 );
52  
53 $parser->parse( markdown => $markdown );
54  
55 close $fh;
56  
57 $capture =~ s/\n+$/\n/;
58  
59 #
60 # FIXME
61 # dirty code to support blockquote
62 #
63 $capture =~ s{
64 ^ =begin \s+ blockquote
65 \s+
66 (.*?)
67 \s+
68 ^ =end \s+ blockquote
69 }{
70 my $quoted = $1;
71 $quoted =~ s/^/ /gsm;
72 $quoted;
73 }xgsme;
74  
75 return $capture;
76 }
77  
78 __PACKAGE__->meta->make_immutable;
79 1;
80  
81 __END__
82  
83 =pod
84  
85 =encoding UTF-8
86  
87 =head1 NAME
88  
89 Markdown::Pod - Convert Markdown to POD
90  
91 =head1 VERSION
92  
93 version 0.005
94  
95 =head1 SYNOPSIS
96  
97 use Markdown::Pod;
98
99 my $m2p = Markdown::Pod->new;
100 my $pod = $m2p->markdown_to_pod(
101 markdown => $markdown,
102 );
103  
104 =head1 DESCRIPTION
105  
106 This module parses Markdown text and return POD text.
107 It uses L<Markdent> module to parse Markdown.
108 Due to POD doesn't support blockquoted HTML tag,
109 so quoted text of Markdown will not be handled properly.
110 Quoted text will be converted to POD verbatim section.
111  
112 =head1 ATTRIBUTES
113  
114 =head2 markdown
115  
116 markdown text
117  
118 =head2 encoding
119  
120 encoding to use. Available type of encoding is same as L<Encode> module.
121  
122 =head1 METHODS
123  
124 =head2 new
125  
126 create Markdown::Pod object
127  
128 =head2 markdown_to_pod
129  
130 convert markdown text to POD text
131  
132 =head1 SEE ALSO
133  
134 =over
135  
136 =item *
137  
138 L<Markdent>
139  
140 =item *
141  
142 L<Pod::Markdown>
143  
144 =item *
145  
146 L<Text::MultiMarkdown>, L<Text::Markdown>
147  
148 =back
149  
150 =head1 AUTHOR
151  
152 Keedi Kim - 김도형 <keedi@cpan.org>
153  
154 =head1 CONTRIBUTORS
155  
156 =over 4
157  
158 =item *
159  
160 Abigail (ABIGAIL)
161  
162 =item *
163  
164 Jason McIntosh (JMAC)
165  
166 =back
167  
168 =head1 COPYRIGHT AND LICENSE
169  
170 This software is copyright (c) 2013 by Keedi Kim.
171  
172 This is free software; you can redistribute it and/or modify it under
173 the same terms as the Perl 5 programming language system itself.
174  
175 =cut
« Pod/Handler.pm ↑ Summary