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.5.0'; |
5
|
6
|
|
|
6
|
|
206674
|
use strict; |
|
6
|
|
|
|
|
33
|
|
|
6
|
|
|
|
|
162
|
|
6
|
6
|
|
|
6
|
|
28
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
179
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
441
|
use File::Serialize qw/ deserialize_file serialize_file /; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
70
|
|
9
|
6
|
|
|
6
|
|
1000
|
use Moo; |
|
6
|
|
|
|
|
7576
|
|
|
6
|
|
|
|
|
36
|
|
10
|
|
|
|
|
|
|
with 'File::Serialize::Serializer'; |
11
|
|
|
|
|
|
|
|
12
|
66
|
|
|
66
|
0
|
341
|
sub required_modules { return qw//; } |
13
|
|
|
|
|
|
|
|
14
|
22
|
|
|
22
|
1
|
79
|
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__ |