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