Embra/Plugin/DetectYamlFrontMatter.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 93.4% 43 / 46 CC 4 SCAR 7.4
CC
4
Cov
95%
transform_files
4.0
__ANON__
2.0
BEGIN
1.0
CRAP 2.1
« Embra/Plugin/TemplateToolkit.pm ↑ Summary Embra/Plugin/PruneFiles.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package App::Embra::Plugin::DetectYamlFrontMatter;
5 1 $App::Embra::Plugin::DetectYamlFrontMatter::VERSION = '0.001'; # TRIAL
6 # ABSTRACT: detect YAML front matter & save as notes
7  
8 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Method::Signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 1 ▶method transform_files {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine transform_files: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 1 1
14 1 for my $file ( @{ $self->embra->files } ) {
15 2 my ( $yaml_front_matter ) =
16 $file->content =~ m/
17 \A # beginning of file
18 --- \s* ^ # first line is three dashes
19 ( .*? ) ^ # then the smallest amount of stuff until
20 --- \s* ^ # the next line of three dashes
21 /xmsp;
22 2 ▶ next if not $yaml_front_matter;
Branch: 1 branch
BranchTrueFalseTotal
unless $yaml_front_matter 1 1 2
23 1 my $notes;
24 1 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
25 1 require YAML::XS;
26 1 $notes = YAML::XS::Load( $yaml_front_matter );
27 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 0 die 'cannot read front-matter of '.$file->name.': '.$_;
29 1 };
30 1 $file->update_notes( %$notes );
31 1 $file->content( ${^POSTMATCH} );
32 }
33 }
34  
35 1 with 'App::Embra::Role::FileTransformer';
36  
37 1 1;
38  
39 __END__
« Embra/Plugin/TemplateToolkit.pm ↑ Summary Embra/Plugin/PruneFiles.pm »