Serialize/Serializer/Markdown.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 6 / 6 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 8 / 8 Podpod 25.0% 1 / 4 totaltotal 94.2% 49 / 52 CC 5 SCAR 6.9
CC
5
Cov
100%
serialize
3.0
deserialize
3.0
BEGIN
1.0
CRAP 2.0
« Serialize.pm ↑ Summary Serialize/Serializer/JSON/MaybeXS.pm »
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
BranchTrueFalseTotal
unless keys %$data 1 2 3
24  
25 2 serialize_file \$yaml, $data, { format => 'yaml' };
26  
27 2 ▶ return join "---\n", $yaml, $content//'';
Condition100%2/2
$content // ""
l!l
11
MC/DC100%1/1
$content // ""
$content
Truth table100%2/2
A
A= $content
Aresult
11
00
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
BranchTrueFalseTotal
unless $data =~ /^---\n?$/m 1 5 6
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
BranchTrueFalseTotal
if $content =~ /\S/ 3 2 5
45  
46 5 return $struct;
47 }
48  
49 5 1;
50  
51 __END__
« Serialize.pm ↑ Summary Serialize/Serializer/JSON/MaybeXS.pm »