| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 1 |  |  | 1 |  | 561 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 39 |  | 
| 2 | 1 |  |  | 1 |  | 3 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 46 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | package App::Embra::Plugin::DetectYamlFrontMatter; | 
| 5 |  |  |  |  |  |  | $App::Embra::Plugin::DetectYamlFrontMatter::VERSION = '0.001'; # TRIAL | 
| 6 |  |  |  |  |  |  | # ABSTRACT: detect YAML front matter & save as notes | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 1 |  |  | 1 |  | 3 | use Try::Tiny; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 55 |  | 
| 9 | 1 |  |  | 1 |  | 4 | use Method::Signatures; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 10 | 1 |  |  | 1 |  | 346 | use Moo; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 1 | 50 |  | 1 |  | 865 | method transform_files { | 
|  | 1 |  |  | 1 |  | 9 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 14 | 1 |  |  |  |  | 2 | for my $file ( @{ $self->embra->files } ) { | 
|  | 1 |  |  |  |  | 6 |  | 
| 15 | 2 |  |  |  |  | 23 | 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 | 100 |  |  |  | 421 | next if not $yaml_front_matter; | 
| 23 | 1 |  |  |  |  | 2 | my $notes; | 
| 24 |  |  |  |  |  |  | try { | 
| 25 | 1 |  |  | 1 |  | 530 | require YAML::XS; | 
| 26 | 1 |  |  |  |  | 2173 | $notes = YAML::XS::Load( $yaml_front_matter ); | 
| 27 |  |  |  |  |  |  | } catch { | 
| 28 | 0 |  |  | 0 |  | 0 | die 'cannot read front-matter of '.$file->name.': '.$_; | 
| 29 | 1 |  |  |  |  | 10 | }; | 
| 30 | 1 |  |  |  |  | 25 | $file->update_notes( %$notes ); | 
| 31 | 1 |  |  |  |  | 22 | $file->content( ${^POSTMATCH} ); | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | with 'App::Embra::Role::FileTransformer'; | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | 1; | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | __END__ | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | =pod | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | =encoding UTF-8 | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | =head1 NAME | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | App::Embra::Plugin::DetectYamlFrontMatter - detect YAML front matter & save as notes | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | =head1 VERSION | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | version 0.001 | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | This plugin will check each gathered file for L<YAML front-matter|http://jekyllrb.com/docs/frontmatter/>. Any keys & values found will be added to the file's notes. | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | Files must start with YAML front-matter for it to be detected. The format is: | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | --- | 
| 60 |  |  |  |  |  |  | key: value | 
| 61 |  |  |  |  |  |  | key2: value2 | 
| 62 |  |  |  |  |  |  | --- | 
| 63 |  |  |  |  |  |  | << rest of file ⦠>> | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =head1 AUTHOR | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | Daniel Holz <dgholz@gmail.com> | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | This software is copyright (c) 2015 by Daniel Holz. | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 74 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | =cut |