| 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
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||