Skip to content

Perl module to read the "YAML front matter" format

Notifications You must be signed in to change notification settings

notameadow/Text-FrontMatter-YAML

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Text::FrontMatter::YAML - read the "YAML front matter" format

DESCRIPTION

Text::FrontMatter::YAML opens files with so-called "YAML front matter",
such as are found on GitHub (and used in Jekyll, and various other
programs). It's a way of associating metadata with a file by marking off
the metadata into a YAML section at the top of the file.

The YAML front matter can be retrieved as a hash or as a string, and the
file data below can be retrieved as a string, or via a filehandle.
Access is read-only.


SYNOPSIS

    use File::Slurp;
    use Text::FrontMatter::YAML;

    # READING
    my $text_with_frontmatter = read_file("filename.md");
    my $tfm = Text::FrontMatter::YAML->new(
        document_string => $text_with_frontmatter
    );

    my $hashref  = $tfm->frontmatter_hashref;
    my $mumble   = $hashref->{'mumble'};
    my $data     = $tfm->data_text;

    # or also

    my $fh = $tfm->data_fh();
    while (defined(my $line = <$fh>)) {
        # do something with the file data
    }

    # WRITING
    my $tfm = Text::FrontMatter::YAML->new(
        frontmatter_hashref => {
            title => 'The first sentence of the "Gettysburg Address"',
            author => 'Abraham Lincoln',
            date => 18631119
        },
        data_text => "Four score and seven years ago...",
    );

    write_file("gettysburg.md", $tfm->document_string);


INSTALLATION

To install this module, run the following commands:

    perl Makefile.PL
    make
    make test
    make install


FUTURE DIRECTIONS

Text::FrontMatter::YAML uses YAML::Tiny. Perhaps it would be useful to
support more than one YAML module. Perhaps that would be more trouble
that it's worth. Thoughts?


SUPPORT AND DOCUMENTATION

After installing, you can find documentation for this module with the
perldoc command.

    perldoc Text::FrontMatter::YAML

Send questions, feature requests, and bug reports to me at
C<ahall@vitaphone.net>. Please include C<Text::FrontMatter::YAML> in the
subject line of the e-mail. Thanks!


LICENSE AND COPYRIGHT

Copyright 2013-2019 Aaron Hall.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl 5.10.1.

See http://dev.perl.org/licenses/ for more information.

About

Perl module to read the "YAML front matter" format

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Perl 100.0%