line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Serialize::Serializer::Markdown; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
3
|
|
|
|
|
|
|
#ABSTRACT: Markdown (with frontmatter) serializer for File::Serialize |
4
|
|
|
|
|
|
|
$File::Serialize::Serializer::Markdown::VERSION = '1.4.0'; |
5
|
6
|
|
|
6
|
|
194257
|
use strict; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
183
|
|
6
|
6
|
|
|
6
|
|
30
|
use warnings; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
212
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
414
|
use File::Serialize qw/ deserialize_file serialize_file /; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
67
|
|
9
|
6
|
|
|
6
|
|
876
|
use Moo; |
|
6
|
|
|
|
|
7128
|
|
|
6
|
|
|
|
|
37
|
|
10
|
|
|
|
|
|
|
with 'File::Serialize::Serializer'; |
11
|
|
|
|
|
|
|
|
12
|
66
|
|
|
66
|
0
|
361
|
sub required_modules { return qw//; } |
13
|
|
|
|
|
|
|
|
14
|
22
|
|
|
22
|
1
|
155
|
sub extensions { qw/ md markdown / }; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub serialize { |
17
|
|
|
|
|
|
|
my( $self, $data, $options ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $content = delete $data->{_content}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $yaml = ''; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
return $content unless keys %$data; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
serialize_file \$yaml, $data, { format => 'yaml' }; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return join "---\n", $yaml, $content//''; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub deserialize { |
32
|
|
|
|
|
|
|
my( $self, $data, $options ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# remote the potential leading `---` |
35
|
|
|
|
|
|
|
$data =~ s/^---\n//; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return { _content => $data } if $data !~ /^---\n?$/m; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my( $frontmatter, $content ) = split /^---\n?$/m, $data, 2; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $struct = deserialize_file( \$frontmatter, { format => 'yml' } ); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$struct->{_content} = $content if $content =~ /\S/; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return $struct; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |