| 1 | package File::Serialize::Serializer::Markdown; | ||||||||||||
| 2 | 5 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||
| 3 | #ABSTRACT: Markdown (with frontmatter) serializer for File::Serialize | ||||||||||||
| 4 | 5 | $File::Serialize::Serializer::Markdown::VERSION = '1.4.0'; | |||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 7 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 7 | ▶ | use File::Serialize qw/ deserialize_file serialize_file /; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 7 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 5 | with 'File::Serialize::Serializer'; | |||||||||||
| 11 | |||||||||||||
| 12 | 66 | ▶ | sub required_modules { return qw//; } | ||||||||||
|
Subroutine
required_modules: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 13 | |||||||||||||
| 14 | 22 | ▶ | sub extensions { qw/ md markdown / }; | ||||||||||
|
Subroutine
extensions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 15 | |||||||||||||
| 16 | sub serialize { | ||||||||||||
| 17 | 3 | ▶ | my( $self, $data, $options ) = @_; | ||||||||||
|
Subroutine
serialize: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 18 | |||||||||||||
| 19 | 3 | my $content = delete $data->{_content}; | |||||||||||
| 20 | |||||||||||||
| 21 | 3 | my $yaml = ''; | |||||||||||
| 22 | |||||||||||||
| 23 | 3 | ▶ | return $content unless keys %$data; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | |||||||||||||
| 25 | 2 | serialize_file \$yaml, $data, { format => 'yaml' }; | |||||||||||
| 26 | |||||||||||||
| 27 | 2 | ▶ | return join "---\n", $yaml, $content//''; | ||||||||||
|
Condition100%2/2
$content // ""
MC/DC100%1/1
$content // ""
$content
Truth table100%2/2
A
A= $content
| |||||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | |||||||||||||
| 31 | sub deserialize { | ||||||||||||
| 32 | 6 | ▶ | my( $self, $data, $options ) = @_; | ||||||||||
|
Subroutine
deserialize: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 33 | |||||||||||||
| 34 | # remote the potential leading `---` | ||||||||||||
| 35 | 6 | $data =~ s/^---\n//; | |||||||||||
| 36 | |||||||||||||
| 37 | |||||||||||||
| 38 | 6 | ▶ | return { _content => $data } if $data !~ /^---\n?$/m; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | |||||||||||||
| 40 | 5 | my( $frontmatter, $content ) = split /^---\n?$/m, $data, 2; | |||||||||||
| 41 | |||||||||||||
| 42 | 5 | my $struct = deserialize_file( \$frontmatter, { format => 'yml' } ); | |||||||||||
| 43 | |||||||||||||
| 44 | 5 | ▶ | $struct->{_content} = $content if $content =~ /\S/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | |||||||||||||
| 46 | 5 | return $struct; | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 5 | 1; | |||||||||||
| 50 | |||||||||||||
| 51 | __END__ | ||||||||||||